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)
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)
def test_indexeddict_invalid_key(): a = IndexedDict(a=1, b=2, c=3, d=4) with pytest.raises(KeyError): a.index('e')
def test_indexeddict_index(val, res): a = IndexedDict(a=1, b=2, c=3, d=4) check.equal(a.index(val), res)
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})
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})
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})
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})
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})
def test_indexeddict_index(self, val, res): a = IndexedDict(a=1, b=2, c=3, d=4) assert_equal(a.index(val), res)
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})
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})
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})
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})