示例#1
0
 def test_indexeddict_create(self):
     d = dict(a=1, b=2, c=3)
     i = IndexedDict(a=1, b=2, c=3)
     assert_is_instance(i, dict)
     assert_equal(len(d), len(i))
     # Python 3.6 and above ensure items order
     assert_equal(list(d.keys()), list(i.keys()))
     assert_equal(list(d.values()), list(i.values()))
     assert_equal(i, d)
示例#2
0
def test_indexeddict_create():
    d = dict(a=1, b=2, c=3)
    i = IndexedDict(a=1, b=2, c=3)
    check.is_instance(i, dict)
    check.equal(len(d), len(i))
    # Python 3.6 and above ensure items order
    check.equal(list(d.keys()), list(i.keys()))
    check.equal(list(d.values()), list(i.values()))
    check.equal(i, d)
示例#3
0
def test_indexeddict_invalid_key():
    a = IndexedDict(a=1, b=2, c=3, d=4)
    with pytest.raises(KeyError):
        a.index('e')
示例#4
0
def test_indexeddict_index(val, res):
    a = IndexedDict(a=1, b=2, c=3, d=4)
    check.equal(a.index(val), res)
示例#5
0
def test_indexeddict_last():
    a = IndexedDict(a=1, b=2, c=3, d=4)
    a.insert_after('d', 'e', 5)
    check.equal(a, {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5})
示例#6
0
def test_indexeddict_first():
    a = IndexedDict(a=1, b=2, c=3, d=4)
    a.insert_before('a', 'e', 5)
    check.equal(a, {'e': 5, 'a': 1, 'b': 2, 'c': 3, 'd': 4})
示例#7
0
def test_indexeddict_existing_after_after():
    a = IndexedDict(a=1, b=2, c=3, d=4, e=5)
    a.insert_after('e', 'c', 4)
    check.equal(a, {'a': 1, 'b': 2, 'd': 4, 'c': 4, 'e': 5})
示例#8
0
def test_indexeddict_existing_before_after():
    a = IndexedDict(a=1, b=2, c=3, d=4)
    a.insert_after('b', 'c', 3)
    check.equal(a, {'a': 1, 'c': 3, 'b': 2, 'd': 4})
示例#9
0
def test_indexeddict_insert_at_negative():
    a = IndexedDict(a=1, b=2, c=3, d=4)
    a.insert_at(-2, 'e', 5)
    check.equal(a, {'a': 1, 'b': 2, 'c': 3, 'e': 5, 'd': 4})
示例#10
0
 def test_indexeddict_index(self, val, res):
     a = IndexedDict(a=1, b=2, c=3, d=4)
     assert_equal(a.index(val), res)
示例#11
0
 def test_indexeddict_existing_after_before(self):
     a = IndexedDict(a=1, b=2, c=3, d=4, e=5)
     a.insert_before('e', 'c', 4)
     assert_equal(a, {'a': 1, 'b': 2, 'd': 4, 'c': 4, 'e': 5})
示例#12
0
 def test_indexeddict_existing_before_before(self):
     a = IndexedDict(a=1, b=2, c=3, d=4)
     a.insert_before('b', 'c', 3)
     assert_equal(a, {'a': 1, 'c': 3, 'b': 2, 'd': 4})
示例#13
0
 def test_indexeddict_after(self):
     a = IndexedDict(a=1, b=2, c=3, d=4)
     a.insert_after('b', 'e', 5)
     assert_equal(a, {'a': 1, 'b': 2, 'e': 5, 'c': 3, 'd': 4})
示例#14
0
 def test_indexeddict_insert_at_away(self):
     a = IndexedDict(a=1, b=2, c=3, d=4)
     a.insert_at(42, 'e', 5)
     assert_equal(a, {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5})