예제 #1
0
파일: test_util.py 프로젝트: obsoleter/petl
def test_recordlookupone():
    """Test the recordlookupone function."""
    
    t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3))
    
    try:
        recordlookupone(t1, 'foo', strict=True)
    except DuplicateKeyError:
        pass # expected
    else:
        assert False, 'expected error'
        
    # relax 
    actual = recordlookupone(t1, 'foo', strict=False)
    expect = {'a': {'foo': 'a', 'bar': 1}, 'b': {'foo': 'b', 'bar': 2}} # first wins
    eq_(expect, actual)

    t2 = (('foo', 'bar', 'baz'),
          ('a', 1, True),
          ('b', 2, False),
          ('b', 3, True),
          ('b', 3, False))
    
    # test compound key
    actual = recordlookupone(t2, ('foo', 'bar'), strict=False)
    expect = {('a', 1): {'foo': 'a', 'bar': 1, 'baz': True}, 
              ('b', 2): {'foo': 'b', 'bar': 2, 'baz': False}, 
              ('b', 3): {'foo': 'b', 'bar': 3, 'baz': True}} # first wins
    eq_(expect, actual)
예제 #2
0
파일: test_util.py 프로젝트: florentx/petl
def test_recordlookupone():
    """Test the recordlookupone function."""

    t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3))

    try:
        recordlookupone(t1, 'foo', strict=True)
    except DuplicateKeyError:
        pass  # expected
    else:
        assert False, 'expected error'

    # relax
    actual = recordlookupone(t1, 'foo', strict=False)
    expect = {
        'a': {
            'foo': 'a',
            'bar': 1
        },
        'b': {
            'foo': 'b',
            'bar': 2
        }
    }  # first wins
    eq_(expect, actual)

    t2 = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 2, False),
          ('b', 3, True), ('b', 3, False))

    # test compound key
    actual = recordlookupone(t2, ('foo', 'bar'), strict=False)
    expect = {
        ('a', 1): {
            'foo': 'a',
            'bar': 1,
            'baz': True
        },
        ('b', 2): {
            'foo': 'b',
            'bar': 2,
            'baz': False
        },
        ('b', 3): {
            'foo': 'b',
            'bar': 3,
            'baz': True
        }
    }  # first wins
    eq_(expect, actual)
예제 #3
0
def test_recordlookupone():
    """Test the recordlookupone function."""

    t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3))

    try:
        recordlookupone(t1, 'foo', strict=True)
    except DuplicateKeyError:
        pass  # expected
    else:
        assert False, 'expected error'

    # relax
    lkp = recordlookupone(t1, 'foo', strict=False)
    eq_(1, lkp['a'].bar)
    eq_(2, lkp['b'].bar)  # first wins
예제 #4
0
파일: test_util.py 프로젝트: brutimus/petl
def test_recordlookupone():
    """Test the recordlookupone function."""

    t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3))

    try:
        recordlookupone(t1, 'foo', strict=True)
    except DuplicateKeyError:
        pass # expected
    else:
        assert False, 'expected error'

    # relax
    lkp = recordlookupone(t1, 'foo', strict=False)
    eq_(1, lkp['a'].bar)
    eq_(2, lkp['b'].bar)  # first wins
예제 #5
0
파일: test_util.py 프로젝트: talwai/petl
def test_recordlookupone():
    """Test the recordlookupone function."""

    t1 = (("foo", "bar"), ("a", 1), ("b", 2), ("b", 3))

    try:
        recordlookupone(t1, "foo", strict=True)
    except DuplicateKeyError:
        pass  # expected
    else:
        assert False, "expected error"

    # relax
    lkp = recordlookupone(t1, "foo", strict=False)
    eq_(1, lkp["a"].bar)
    eq_(2, lkp["b"].bar)  # first wins
예제 #6
0
def test_recordlookupone():

    t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3))

    try:
        recordlookupone(t1, 'foo', strict=True)
    except DuplicateKeyError:
        pass  # expected
    else:
        assert False, 'expected error'

    # relax
    lkp = recordlookupone(t1, 'foo', strict=False)
    eq_('a', lkp['a'].foo)
    eq_('b', lkp['b'].foo)
    eq_(1, lkp['a'].bar)
    eq_(2, lkp['b'].bar)  # first wins

    # key only
    lkp = recordlookupone(cut(t1, 'foo'), 'foo', strict=False)
    eq_('a', lkp['a'].foo)
    eq_('b', lkp['b'].foo)