Ejemplo n.º 1
0
def _compare(expected, actual):
    try:
        ieq(expected, actual)
    except Exception as ex:
        print('Expected:\n', look(expected), file=sys.stderr)
        print('  Actual:\n', look(actual), file=sys.stderr)
        raise ex
Ejemplo n.º 2
0
def test_look_style_minimal():
    table = (('foo', 'bar'), ('a', 1), ('b', 2))
    actual = repr(look(table, style='minimal'))
    expect = """'foo'  'bar'
'a'        1
'b'        2
"""
    eq_(expect, actual)
    look.default_style = 'minimal'
    actual = repr(look(table))
    eq_(expect, actual)
    look.default_style = 'grid'
Ejemplo n.º 3
0
def test_look_style_simple():
    table = (('foo', 'bar'), ('a', 1), ('b', 2))
    actual = repr(look(table, style='simple'))
    expect = """=====  =====
'foo'  'bar'
=====  =====
'a'        1
'b'        2
=====  =====
"""
    eq_(expect, actual)
    look.default_style = 'simple'
    actual = repr(look(table))
    eq_(expect, actual)
    look.default_style = 'grid'
Ejemplo n.º 4
0
def test_fromxml_6():

    data = """<table class='petl'>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td style='text-align: right'>2</td>
</tr>
<tr>
<td>b</td>
<td style='text-align: right'>1</td>
</tr>
<tr>
<td>c</td>
<td style='text-align: right'>3</td>
</tr>
</tbody>
</table>"""
    f = NamedTemporaryFile(delete=False, mode='wt')
    f.write(data)
    f.close()

    actual = fromxml(f.name, './/tr', ('th', 'td'))
    print(look(actual))
    expect = (('foo', 'bar'), ('a', '2'), ('b', '1'), ('c', '3'))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Ejemplo n.º 5
0
def test_look_irregular_rows():
    
    table = (('foo', 'bar'), ('a',), ('b', 2, True))
    actual = repr(look(table))
    expect = """+-------+-------+------+
| 'foo' | 'bar' |      |
+=======+=======+======+
| 'a'   |       |      |
+-------+-------+------+
| 'b'   |     2 | True |
+-------+-------+------+
"""
    eq_(expect, actual)
Ejemplo n.º 6
0
def test_look_bool():

    table = (('foo', 'bar'), ('a', True), ('b', False))
    actual = repr(look(table))
    expect = """+-------+-------+
| 'foo' | 'bar' |
+=======+=======+
| 'a'   | True  |
+-------+-------+
| 'b'   | False |
+-------+-------+
"""
    eq_(expect, actual)
Ejemplo n.º 7
0
def test_look():

    table = (('foo', 'bar'), ('a', 1), ('b', 2))
    actual = repr(look(table))
    expect = """+-------+-------+
| 'foo' | 'bar' |
+=======+=======+
| 'a'   |     1 |
+-------+-------+
| 'b'   |     2 |
+-------+-------+
"""
    eq_(expect, actual)
Ejemplo n.º 8
0
def test_subtract_1():
    
    left = (('begin', 'end', 'label'),
            (1, 6, 'apple'),
            (3, 6, 'orange'),
            (5, 9, 'banana'))
    
    right = (('start', 'stop', 'foo'),
             (3, 4, True))
    
    expect = (('begin', 'end', 'label'),
              (1, 3, 'apple'),
              (4, 6, 'apple'),
              (4, 6, 'orange'),
              (5, 9, 'banana'))
    
    actual = intervalsubtract(left, right, 
                              lstart='begin', lstop='end', 
                              rstart='start', rstop='stop')
    print look(actual)

    ieq(expect, actual)
    ieq(expect, actual)
Ejemplo n.º 9
0
def test_subtract_1():
    
    left = (('begin', 'end', 'label'),
            (1, 6, 'apple'),
            (3, 6, 'orange'),
            (5, 9, 'banana'))
    
    right = (('start', 'stop', 'foo'),
             (3, 4, True))
    
    expect = (('begin', 'end', 'label'),
              (1, 3, 'apple'),
              (4, 6, 'apple'),
              (4, 6, 'orange'),
              (5, 9, 'banana'))
    
    actual = intervalsubtract(left, right, 
                              lstart='begin', lstop='end', 
                              rstart='start', rstop='stop')
    print look(actual)

    ieq(expect, actual)
    ieq(expect, actual)
Ejemplo n.º 10
0
def test_subtract_faceted():
    
    left = (('region', 'begin', 'end', 'label'),
            ('north', 1, 6, 'apple'),
            ('south', 3, 6, 'orange'),
            ('west', 5, 9, 'banana'))
    
    right = (('place', 'start', 'stop', 'foo'),
             ('south', 3, 4, True),
             ('north', 5, 6, True))
    
    expect = (('region', 'begin', 'end', 'label'),
              ('north', 1, 5, 'apple'),
              ('south', 4, 6, 'orange'),
              ('west', 5, 9, 'banana'))
    
    actual = intervalsubtract(left, right,
                              lfacet='region', rfacet='place', 
                              lstart='begin', lstop='end', 
                              rstart='start', rstop='stop')
    print look(actual)

    ieq(expect, actual)
    ieq(expect, actual)
Ejemplo n.º 11
0
def test_subtract_faceted():
    
    left = (('region', 'begin', 'end', 'label'),
            ('north', 1, 6, 'apple'),
            ('south', 3, 6, 'orange'),
            ('west', 5, 9, 'banana'))
    
    right = (('place', 'start', 'stop', 'foo'),
             ('south', 3, 4, True),
             ('north', 5, 6, True))
    
    expect = (('region', 'begin', 'end', 'label'),
              ('north', 1, 5, 'apple'),
              ('south', 4, 6, 'orange'),
              ('west', 5, 9, 'banana'))
    
    actual = intervalsubtract(left, right,
                              lfacet='region', rfacet='place', 
                              lstart='begin', lstop='end', 
                              rstart='start', rstop='stop')
    print look(actual)

    ieq(expect, actual)
    ieq(expect, actual)
Ejemplo n.º 12
0
def test_fromxml_6():

    data = """<table class='petl'>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td style='text-align: right'>2</td>
</tr>
<tr>
<td>b</td>
<td style='text-align: right'>1</td>
</tr>
<tr>
<td>c</td>
<td style='text-align: right'>3</td>
</tr>
</tbody>
</table>"""
    f = NamedTemporaryFile(delete=False)
    f.write(data)
    f.close()

    actual = fromxml(f.name, './/tr', ('th', 'td'))
    print(look(actual))
    expect = (('foo', 'bar'),
              ('a', '2'),
              ('b', '1'),
              ('c', '3'))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice
Ejemplo n.º 13
0
def _dump_both(expected, actual, out=None):
    if out is not None:
        outf = sys.stderr if out else sys.stdout
        print('EXPECTED:\n', look(expected), file=outf)
        print('ACTUAL:\n', look(actual), file=outf)