Exemple #1
0
def test_mergeduplicates():

    table = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', '2', None),
             ('D', 'xyz', 9.4), ('B', None, u'7.8', True), ('E', None, 42.),
             ('D', 'xyz', 12.3), ('A', 2, None))

    # value overrides missing
    result = mergeduplicates(table, 'foo', missing=None)
    expectation = (('foo', 'bar', 'baz'), ('A', Conflict([1, 2]),
                                           2), ('B', '2', u'7.8'),
                   ('D', 'xyz', Conflict([9.4, 12.3])), ('E', None, 42.))
    ieq(expectation, result)
Exemple #2
0
def test_mergeduplicates_compoundkey():
    table = [
        ['foo', 'bar', 'baz'],
        ['a', 1, True],
        ['a', 1, True],
        ['a', 2, False],
        ['a', 2, None],
        ['c', 3, True],
        ['c', 3, False],
    ]
    actual = mergeduplicates(table, key=('foo', 'bar'))
    expect = [('foo', 'bar', 'baz'), ('a', 1, True), ('a', 2, False),
              ('c', 3, Conflict([True, False]))]
    ieq(expect, actual)
Exemple #3
0
def test_mergeduplicates_shortrows():
    table = [['foo', 'bar', 'baz'], ['a', 1, True], ['b', 2, True], ['b', 3]]
    actual = mergeduplicates(table, 'foo')
    expect = [('foo', 'bar', 'baz'), ('a', 1, True),
              ('b', Conflict([2, 3]), True)]
    ieq(expect, actual)