Ejemplo n.º 1
0
def test_preserves_input_order():
    d = DefaultOrderedDict(list)
    d['a'].append(1)
    d['b'].append(2)
    d['c'].append(3)
    d['a'].append(4)

    assert list(d.keys()) == ['a', 'b', 'c']
    assert list(d.values()) == [[1, 4], [2], [3]]
def test_preserves_input_order():
    d = DefaultOrderedDict(list)
    d['a'].append(1)
    d['b'].append(2)
    d['c'].append(3)
    d['a'].append(4)

    assert list(d.keys()) == ['a', 'b', 'c']
    assert list(d.values()) == [[1, 4], [2], [3]]
Ejemplo n.º 3
0
def test_picklable():
    d = DefaultOrderedDict(list, [('a', 1), ('b', 2)])
    d_copied = pickle.loads(pickle.dumps(d))

    assert d_copied == d
    assert d.default_factory == d_copied.default_factory

    d = DefaultOrderedDict(None, [('a', 1), ('b', 2)])
    d_copied = pickle.loads(pickle.dumps(d))

    assert d_copied == d
    assert d.default_factory == d_copied.default_factory
Ejemplo n.º 4
0
def test_copy():
    d = DefaultOrderedDict(list, [('a', [1, 2]), ('b', [3, 4])])
    d_copied = copy.copy(d)

    assert d_copied == d
    assert d.default_factory == d_copied.default_factory
    assert d_copied['a'] is d['a']
    assert d_copied['b'] is d['b']

    d_copied = d.copy()

    assert d_copied == d
    assert d.default_factory == d_copied.default_factory
    assert d_copied['a'] is d['a']
    assert d_copied['b'] is d['b']
def test_copy():
    d = DefaultOrderedDict(list, [('a', [1, 2]), ('b', [3, 4])])
    d_copied = copy.copy(d)

    assert d_copied == d
    assert d.default_factory == d_copied.default_factory
    assert d_copied['a'] is d['a']
    assert d_copied['b'] is d['b']

    d_copied = d.copy()

    assert d_copied == d
    assert d.default_factory == d_copied.default_factory
    assert d_copied['a'] is d['a']
    assert d_copied['b'] is d['b']
Ejemplo n.º 6
0
def test_will_act_list_default_dict_if_no_factory_defined():
    d = DefaultOrderedDict()

    with raises(KeyError) as excinfo:
        assert d['test']

    assert str(excinfo.value) == "'test'"
Ejemplo n.º 7
0
def test_will_missing_will_set_value_from_factory():
    d = DefaultOrderedDict(list)
    f = d['foo']
    assert isinstance(f, list)
    assert d['foo'] is f
Ejemplo n.º 8
0
def test_requires_callable_default_factory():
    with raises(TypeError) as excinfo:
        DefaultOrderedDict('not callable')

    assert str(excinfo.value) == 'first argument must be callable'
Ejemplo n.º 9
0
def test_will_repr_properly():
    d = DefaultOrderedDict(list, [('a', 1), ('b', 2)])
    assert repr(d) == "DefaultOrderedDict({}, [('a', 1), ('b', 2)])".format(
        list)