示例#1
0
 def test_hash_dict_update(self):
     d1 = HashDict()
     d1[1] = 1
     d2 = HashDict()
     d2[2] = 2
     d1.update(d2)
     self.assertEquals(d1, {1: 1, 2: 2})
示例#2
0
def test_hashdict_str_ignorecase():
    test_dict = HashDict(StringComparers.IgnoreCaseComparer)
    test_dict['a'] = 1
    assert len(test_dict) == 1
    assert list(test_dict) == ['a']

    assert test_dict['a'] == 1
    assert test_dict['A'] == 1
示例#3
0
def test_hashdict_default():
    test_dict = HashDict()
    test_dict['a'] = 1
    assert len(test_dict) == 1
    assert list(test_dict) == ['a']

    assert test_dict['a'] == 1
    with raises(KeyError):
        test_dict['A']
示例#4
0
def test_any_comparer():
    d = {}
    with raises(TypeError, match='unhashable type'):
        d[{}] = 1
    assert len(d) == 0

    hd = HashDict(AnyComparer.instance)
    hd[d] = 15
    assert hd[d] == 15
    d['k'] = 'v'
    assert hd[d] == 15
    with raises(KeyError):
        hd[{}]

    hd[None] = 10
    assert hd[None] == 10
示例#5
0
 def test_hash_dict_clear(self):
     d = HashDict()
     d[1] = 1
     d[2] = 1
     d.clear()
     self.assertEquals(d, HashDict())
示例#6
0
 def test_hash_dict_repr(self):
     d = HashDict()
     d[1] = 1
     self.assertEquals(d.__repr__(), "{1: 1}")
示例#7
0
 def test_hash_dict_setdefault2(self):
     d = HashDict()
     d.setdefault(1, 231)
     self.assertEquals(d[1], 231)
示例#8
0
 def test_hash_dict_popitem(self):
     d = HashDict()
     d[1] = 2
     self.assertEquals(d.popitem(1), (1, 2))
示例#9
0
 def test_hash_dict_keys(self):
     d = HashDict()
     d[1] = 2
     d[2] = 3
     self.assertEquals(d.keys(), [1, 2])
示例#10
0
 def test_hash_dict_get(self):
     d = HashDict()
     d[1] = 2
     self.assertEquals(d.get(1), 2)
示例#11
0
 def test_hash_dict_setitem2(self):
     d = HashDict()
     d[1] = 1
     d[1] = 2
     self.assertEquals(d[1], 2)
示例#12
0
 def test_hash_dict_setitem1(self):
     d = HashDict()
     d[1] = 1
     self.assertEquals(d[1], 1)
示例#13
0
def test_obj_comparer():
    s = HashDict(ObjectComparer())
    s[0] = 15
    assert s[0] == 15
示例#14
0
def test_hashdict_fromkeys():
    test_dict = HashDict.fromkeys(range(10))
    assert list(test_dict.values()) == list(itertools.repeat(None, 10))
示例#15
0
 def test_hash_dict_copy(self):
     d = HashDict()
     d[1] = 2
     self.assertEquals(d.copy(), {1: 2})
示例#16
0
 def test_hash_dict_fromkeys(self):
     d = HashDict()
     self.assertEquals(d.fromkeys([1, 2, 3]), {1: None, 2: None, 3: None})
示例#17
0
 def test_hash_dict_delitem(self):
     d = HashDict()
     d[1] = 1
     del d[1]
     self.assertEquals(len(d), 0)
示例#18
0
 def test_hash_dict_items(self):
     d = HashDict()
     d[1] = 2
     self.assertEquals(d.items(), [(1, 2)])
示例#19
0
 def test_hash_dict_contains(self):
     d = HashDict()
     d[1] = 1
     self.assertEquals(1 in d, True)
示例#20
0
 def test_hash_dict_pop(self):
     d = HashDict()
     d[1] = 2
     d.pop(1)
     self.assertEquals(len(d), 0)
示例#21
0
 def test_hash_dict_eq1(self):
     d1 = HashDict()
     d1[1] = 1
     d2 = HashDict()
     d2[1] = 1
     self.assertEquals(d1 == d2, True)
示例#22
0
 def test_hash_dict_values(self):
     d = HashDict()
     d[1] = 2
     self.assertEquals(d.values(), [2])
示例#23
0
 def test_hash_dict_eq2(self):
     d1 = HashDict()
     d1[1] = 1
     d2 = HashDict()
     d2[1] = 2
     self.assertEquals(d1 == d2, False)
示例#24
0
 def test_hash_dict_ne(self):
     d1 = HashDict()
     d1[1] = 1
     d2 = HashDict()
     d2[1] = 2
     self.assertEquals(d1 != d2, True)
示例#25
0
def test_hashdict_empty():
    test_dict = HashDict()
    assert len(test_dict) == 0
    assert list(test_dict) == []