| 1 |
from __future__ import absolute_import, print_function, division |
| 2 |
|
| 3 |
|
| 4 |
from petl.test.helpers import eq_ |
| 5 |
from petl.compat import PY2 |
| 6 |
from petl.util.misc import typeset, diffvalues, diffheaders |
| 7 |
|
| 8 |
|
| 9 |
def test_typeset(): |
| 10 |
|
| 11 |
table = (('foo', 'bar', 'baz'), |
| 12 |
(b'A', 1, u'2'), |
| 13 |
(b'B', '2', u'3.4'), |
| 14 |
(b'B', '3', u'7.8', True), |
| 15 |
(u'D', u'xyz', 9.0), |
| 16 |
(b'E', 42)) |
| 17 |
|
| 18 |
actual = typeset(table, 'foo') |
| 19 |
if PY2: |
| 20 |
expect = {'str', 'unicode'} |
| 21 |
else: |
| 22 |
expect = {'bytes', 'str'} |
| 23 |
eq_(expect, actual) |
| 24 |
|
| 25 |
|
| 26 |
def test_diffheaders(): |
| 27 |
|
| 28 |
table1 = (('foo', 'bar', 'baz'), |
| 29 |
('a', 1, .3)) |
| 30 |
|
| 31 |
table2 = (('baz', 'bar', 'quux'), |
| 32 |
('a', 1, .3)) |
| 33 |
|
| 34 |
add, sub = diffheaders(table1, table2) |
| 35 |
eq_({'quux'}, add) |
| 36 |
eq_({'foo'}, sub) |
| 37 |
|
| 38 |
|
| 39 |
def test_diffvalues(): |
| 40 |
|
| 41 |
table1 = (('foo', 'bar'), |
| 42 |
('a', 1), |
| 43 |
('b', 3)) |
| 44 |
|
| 45 |
table2 = (('bar', 'foo'), |
| 46 |
(1, 'a'), |
| 47 |
(3, 'c')) |
| 48 |
|
| 49 |
add, sub = diffvalues(table1, table2, 'foo') |
| 50 |
eq_({'c'}, add) |
| 51 |
eq_({'b'}, sub) |
| 52 |
|
| 53 |
|