Пример #1
0
 def test_relax(self):
     nd = dict(z=1, y=2, w=3, v=4, x=5)
     with pytest.raises(TypeError):
         r = ordereddict(nd)
     r = ordereddict(nd, relax=True)
     assert nd.keys() == r.keys()
     assert nd.values() == r.values()
Пример #2
0
 def test_ass_non_consequitive_slice(self):
     r = self.z
     r[10:15:2] = ordereddict([(1, 0), (2, 1), (3, 2),])
     #print r[9:16]
     #print ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
     #                               ('n', 13), (3, 2), ('p', 15)])
     assert r[9:16] == ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
                                    ('n', 13), (3, 2), ('p', 15)])
Пример #3
0
 def test_ass_reverse_non_consequitive_slice(self):
     r = self.z
     r[14:9:-2] = ordereddict([(3, 2), (2, 1), (1, 0),])
     assert len(r) == 26
     #print r[9:16]
     #print ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
     #                               ('n', 13), (3, 2), ('p', 15)])
     assert r[9:16] == ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
                                    ('n', 13), (3, 2), ('p', 15)])
Пример #4
0
 def test_ass_non_consequitive_slice(self):
     r = self.z
     r[10:15:2] = ordereddict([
         (1, 0),
         (2, 1),
         (3, 2),
     ])
     #print r[9:16]
     #print ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
     #                               ('n', 13), (3, 2), ('p', 15)])
     assert r[9:16] == ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
                                    ('n', 13), (3, 2), ('p', 15)])
Пример #5
0
 def test_ass_reverse_non_consequitive_slice(self):
     r = self.z
     r[14:9:-2] = ordereddict([
         (3, 2),
         (2, 1),
         (1, 0),
     ])
     assert len(r) == 26
     #print r[9:16]
     #print ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
     #                               ('n', 13), (3, 2), ('p', 15)])
     assert r[9:16] == ordereddict([('j', 9), (1, 0), ('l', 11), (2, 1),
                                    ('n', 13), (3, 2), ('p', 15)])
Пример #6
0
 def setup_method(self, method):
     self.x = ordereddict()
     self.x['a'] = 1
     self.x['b'] = 2
     self.x['c'] = 3
     self.x['d'] = 4
     self.z = ordereddict()
     for index, ch in enumerate(string.lowercase):
         self.z[ch] = index
     self.e = ordereddict()
     self.part = ordereddict((('f', 5),('g', 6),('h', 7),('i', 8), ('j', 9)))
     #self.revpart = ordereddict((('j', 9),('g', 6),('i', 8),('h', 7), ('f', 5)))
     self.upperlower = ordereddict([('A', 1), ('a', 2), ('B', 4), ('b', 4)])
Пример #7
0
 def setup_method(self, method):
     self.x = ordereddict()
     self.x['a'] = 1
     self.x['b'] = 2
     self.x['c'] = 3
     self.x['d'] = 4
     self.z = ordereddict()
     for index, ch in enumerate(all_lowercase):
         self.z[ch] = index
     self.e = ordereddict()
     self.part = ordereddict(
         (('f', 5), ('g', 6), ('h', 7), ('i', 8), ('j', 9)))
     self.upperlower = ordereddict([('A', 1), ('a', 2), ('B', 4), ('b', 4)])
Пример #8
0
 def test_kvio2(self):
     r = ordereddict(kvio=True)
     r.update(self.x)
     r['b'] = 2
     assert r != self.x
     r.update([('c', 3), ('d', 4)])
     assert r == self.x
Пример #9
0
 def test_repr(self):
     d = ordereddict()
     assert repr(d) == 'ordereddict([])'
     d['a'] = 1
     assert repr(d) == "ordereddict([('a', 1)])"
     d[2] = 'b'
     assert repr(d) == "ordereddict([('a', 1), (2, 'b')])"
Пример #10
0
 def test_relax_update(self):
     d = ordereddict()
     nd = dict(z=1, y=2, w=3, v=4, x=5)
     if not self.nopytest:
         py.test.raises(TypeError, "d.update(nd)")
     d.update(nd, relax=True)
     assert len(d) == 5
Пример #11
0
 def test_repr(self):
     d = ordereddict()
     assert repr(d) == 'ordereddict([])'
     d['a'] = 1
     assert repr(d) == "ordereddict([('a', 1)])"
     d[2] = 'b'
     assert repr(d) == "ordereddict([('a', 1), (2, 'b')])"
Пример #12
0
 def test_relax_update(self):
     d = ordereddict()
     nd = dict(z=1, y=2, w=3, v=4, x=5)
     with pytest.raises(TypeError):
         d.update(nd)
     d.update(nd, relax=True)
     assert len(d) == 5
Пример #13
0
 def test_relax(self):
     nd = dict(z=1,y=2,w=3,v=4,x=5)
     if not self.nopytest:
         py.test.raises(TypeError, "r = ordereddict(nd)")
     r = ordereddict(nd, relax=True)
     assert nd.keys() == r.keys()
     assert nd.values() == r.values()
Пример #14
0
 def test_kvio2(self):
     r = ordereddict(kvio=True)
     r.update(self.x)
     r['b']=2
     assert r != self.x
     r.update([('c', 3), ('d', 4)])
     assert r == self.x
Пример #15
0
 def test_slice(self):
     r = self.z
     rp = self.part.copy()
     rp.reverse()
     assert r[9:4:-1] == rp
     assert r[5:25:5] == ordereddict([('f', 5), ('k', 10), ('p', 15),
                                      ('u', 20)])
Пример #16
0
 def test_relax_update(self):
     d = ordereddict()
     nd = dict(z=1,y=2,w=3,v=4,x=5)
     if not self.nopytest:
         py.test.raises(TypeError, "d.update(nd)")
     d.update(nd, relax=True)
     assert len(d) == 5
Пример #17
0
 def test_kvio_copy(self):
     r = ordereddict(kvio=True)
     r.update(self.x)
     r['b'] = 2
     r1 = r.copy()
     assert r1 != self.x
     r1.update([('c', 3), ('d', 4)])
     assert r1 == self.x
Пример #18
0
			def insert(A,pos,key,value):
				C=value
				if pos>=len(A):A[key]=C;return
				B=ordereddict();B.update(A)
				for E in B:del A[E]
				for (F,D) in enumerate(B):
					if pos==F:A[key]=C
					A[D]=B[D]
Пример #19
0
 def test_sd_ass_non_consequitive_slice(self):
     r = sorteddict(self.z)
     with pytest.raises(TypeError):
         r[10:15:2] = ordereddict([
             (1, 0),
             (2, 1),
             (3, 2),
         ])
Пример #20
0
 def test_sorted_from_ordered(self):
     if py3:
         return
     i = self.z.items(reverse=True)
     random.shuffle(i)
     i = ordereddict(i)
     sd = sorteddict(i)
     assert sd == self.z
Пример #21
0
 def test_ass_consequitive_slice_wrong_size(self):
     r = self.z
     with pytest.raises(ValueError):
         r[10:15] = ordereddict([
             (1, 0),
             (2, 1),
             (3, 2),
         ])
Пример #22
0
 def test_kvio_copy(self):
     r = ordereddict(kvio=True)
     r.update(self.x)
     r['b']=2
     r1 = r.copy()
     assert r1 != self.x
     r1.update([('c', 3), ('d', 4)])
     assert r1 == self.x
Пример #23
0
 def test_relax(self):
     if py3:
         return
     nd = dict(z=1, y=2, w=3, v=4, x=5)
     if not self.nopytest:
         py.test.raises(TypeError, "r = ordereddict(nd)")
     r = ordereddict(nd, relax=True)
     assert nd.keys() == r.keys()
     assert nd.values() == r.values()
Пример #24
0
 def test_clear(self):
     x = ordereddict()
     x['a'] = 1
     x['b'] = 2
     x['c'] = 3
     x['d'] = 4
     assert len(x) == 4
     x.clear()
     assert len(x) == 0
Пример #25
0
 def test_insert_range(self):
     r = ordereddict()
     r['c'] = 3
     r.insert(0, 'b', 2)
     r.insert(-10, 'a', 1)
     r.insert(3, 'd', 4)
     r.insert(10, 'e', 5)
     self.x['e'] = 5
     assert r == self.x
Пример #26
0
 def test_insert_range(self):
     r = ordereddict()
     r['c'] = 3
     r.insert(0, 'b', 2)
     r.insert(-10, 'a', 1)
     r.insert(3, 'd', 4)
     r.insert(10, 'e', 5)
     self.x['e'] = 5
     assert r == self.x
Пример #27
0
 def test_clear(self):
     x = ordereddict()
     x['a'] = 1
     x['b'] = 2
     x['c'] = 3
     x['d'] = 4
     assert len(x) == 4
     x.clear()
     assert len(x) == 0
Пример #28
0
    def test_multiple_inserts_then_deletes(self):
        d = ordereddict()

        for i in range(1, 6):
            d.insert(i - 1, i, 'a')

        for i in range(1, 6):
            del d[i]

        d.insert(0, 0, 'will this crash?')
Пример #29
0
    def test_multiple_inserts_then_deletes(self):
        d = ordereddict()

        for i in range(1,6):
            d.insert(i-1, i, 'a')

        for i in range(1,6):
            del d[i]

        d.insert(0, 0, 'will this crash?')
Пример #30
0
 def test_deepcopy2(self): # found thanks to Alexandre Andrade
     import copy
     import gc
     d = ordereddict([(1, 2)])
     gc.collect()
     none_refcount = sys.getrefcount(None)
     for i in xrange(10):
         copy.deepcopy(d)
         gc.collect()
     assert none_refcount == sys.getrefcount(None)
Пример #31
0
 def test_del_rev_non_consequitive_slice(self):
     r = self.z
     del r[22:3:-2]
     t = ordereddict()
     for index, ch in enumerate(string.lowercase):
         if ch not in 'abcdfhjlnprtvxyz':
             continue
         t[ch] = index
     #print r
     #print t
     assert r == t
Пример #32
0
 def test_setkeys(self):
     self.x[42] = 'abc'
     r1 = self.x.copy()
     r2 = ordereddict([('d', 4), ('c', 3), ('a', 1), (42, 'abc'), ('b', 2),])
     r1.setkeys(('d', 'c', 'a', 42, 'b',))
     assert r1 == r2
     if not self.nopytest:
         py.test.raises(KeyError, "r1.setkeys(('d', 'e', 'a', 42, 'b',))")
         py.test.raises(KeyError, "r1.setkeys(('d', 42, 'a', 42, 'b',))")
         py.test.raises(ValueError, "r1.setkeys(('d', 'c', 'a', 42, 'b', 'a',))")
         py.test.raises(ValueError, "r1.setkeys(('g', 'c', 'a', 42,))")
Пример #33
0
 def test_update(self):
     y = ordereddict()
     y[1] = 'x'
     y['b'] = 'abc'
     y[3] = 'xx'
     y.update(self.x)
     assert len(y) == 6
     assert y.values()[1] == self.x.values()[1]
     assert y.values()[3] == self.x.values()[0]
     assert y.values()[4] == self.x.values()[2]
     assert y.values()[5] == self.x.values()[3]
Пример #34
0
 def test_del_rev_non_consequitive_slice(self):
     r = self.z
     del r[22:3:-2]
     t = ordereddict()
     for index, ch in enumerate(all_lowercase):
         if ch not in 'abcdfhjlnprtvxyz':
             continue
         t[ch] = index
     #print r
     #print t
     assert r == t
Пример #35
0
 def test_pickle_kvio(self):
     fname = 'tmpdata.pkl'
     r = ordereddict(self.z, kvio=True)
     fp = open(fname, 'wb')
     cPickle.dump(r, fp)
     fp.close()
     s = cPickle.load(open(fname, 'rb'))
     assert s == r
     r['k'] = 42
     s['k'] = 42
     assert s == r
     os.remove(fname)
Пример #36
0
 def insert(self, pos, key, value):
     if pos >= len(self):
         self[key] = value
         return
     od = ordereddict()
     od.update(self)
     for k in od:
         del self[k]
     for index, old_key in enumerate(od):
         if pos == index:
             self[key] = value
         self[old_key] = od[old_key]
Пример #37
0
 def test_pickle_kvio(self):
     fname = 'tmpdata.pkl'
     r = ordereddict(self.z, kvio=True)
     fp = open(fname, 'wb')
     cPickle.dump(r, fp)
     fp.close()
     s = cPickle.load(open(fname, 'rb'))
     assert s == r
     r['k'] = 42
     s['k'] = 42
     assert s == r
     os.remove(fname)
Пример #38
0
 def test_update(self):
     y = ordereddict()
     y[1] = 'x'
     y['b'] = 'abc'
     y[3] = 'xx'
     y.update(self.x)
     assert len(y) == 6
     yval = [t for t in y.values()]
     xval = [t for t in self.x.values()]
     assert yval[1] == xval[1]
     assert yval[3] == xval[0]
     assert yval[4] == xval[2]
     assert yval[5] == xval[3]
Пример #39
0
 def test_update(self):
     if py3:
         return
     y = ordereddict()
     y[1] = 'x'
     y['b'] = 'abc'
     y[3] = 'xx'
     y.update(self.x)
     assert len(y) == 6
     assert y.values()[1] == self.x.values()[1]
     assert y.values()[3] == self.x.values()[0]
     assert y.values()[4] == self.x.values()[2]
     assert y.values()[5] == self.x.values()[3]
Пример #40
0
 def test_setkeys(self):
     self.x[42] = 'abc'
     r1 = self.x.copy()
     r2 = ordereddict([
         ('d', 4),
         ('c', 3),
         ('a', 1),
         (42, 'abc'),
         ('b', 2),
     ])
     r1.setkeys((
         'd',
         'c',
         'a',
         42,
         'b',
     ))
     assert r1 == r2
     with pytest.raises(KeyError):
         r1.setkeys((
             'd',
             'e',
             'a',
             42,
             'b',
         ))
     with pytest.raises(KeyError):
         r1.setkeys((
             'd',
             42,
             'a',
             42,
             'b',
         ))
     with pytest.raises(ValueError):
         r1.setkeys((
             'd',
             'c',
             'a',
             42,
             'b',
             'a',
         ))
     with pytest.raises(ValueError):
         r1.setkeys((
             'g',
             'c',
             'a',
             42,
         ))
Пример #41
0
 def test_deepcopy2(self):  # found thanks to Alexandre Andrade
     if sys.version_info < (3, ):
         import copy
     else:
         return
         import copy3
     import gc
     d = ordereddict([(1, 2)])
     gc.collect()
     none_refcount = sys.getrefcount(None)
     for i in xrange(10):
         copy.deepcopy(d)
         gc.collect()
     assert none_refcount == sys.getrefcount(None)
Пример #42
0
 def _test_alloc_many(self):
     res = []
     times = 1000
     while times > 0:
         times -= 1
         td = ordereddict()
         count = 100000
         while count > 0:
             td['ab%08d' % count] = dict(abcdef='%09d' % (count))
             count -= 1
         count = 100000
         while count > 0:
             del td['ab%08d' % count]
             count -= 1
         res.append(td)
Пример #43
0
 def _test_alloc_many(self):
     res = []
     times = 1000
     while times > 0:
         times -= 1
         td = ordereddict()
         count = 100000
         while count > 0:
             td['ab%08d' % count] = dict(abcdef = '%09d' % (count))
             count -= 1
         count = 100000
         while count > 0:
             del td['ab%08d' % count]
             count -= 1
         res.append(td)
Пример #44
0
 def test_deepcopy2(self):  # found thanks to Alexandre Andrade
     import copy
     import gc
     d = ordereddict([(1, 2)])
     gc.collect()
     none_refcount = sys.getrefcount(None)
     if py3:
         for i in range(10):
             copy.deepcopy(d)
             gc.collect()
     else:
         for i in xrange(10):
             copy.deepcopy(d)
             gc.collect()
     assert none_refcount == sys.getrefcount(None)
Пример #45
0
 def _test_order(self):
     nd = dict(z=1, y=2, w=3, v=4, x=5)
     r = ordereddict(nd, key=True)
     assert nd.keys() == r.keys()
     assert nd.values() == r.values()
Пример #46
0
 def test_init1(self):
     y = ordereddict(self.x)
     y['b'] = 42
     assert self.x['b'] == 2
     assert y['c'] == 3
     assert y['b'] == 42
Пример #47
0
 def test_compare_wrong_value(self):
     y = ordereddict([('a',1), ('b',2), ('c',4), ('d', 3)])
     assert y != self.x
Пример #48
0
 def test_compare(self):
     y = ordereddict([('a',1), ('b',2), ('c',3), ('d', 4)])
     assert y == self.x
Пример #49
0
 def test_consequitive_slice(self):
     r = self.z
     assert r[5:10] == self.part
     assert r[-2:] == ordereddict([('y', 24),('z', 25)])
     assert r[-4:-2] == ordereddict([('w', 22),('x', 23)])
     assert r[:] == self.z
Пример #50
0
 def test_sorted_from_ordered(self):
     i = self.z.items(reverse=True)
     random.shuffle(i)
     i = ordereddict(i)
     sd = sorteddict(i)
     assert sd == self.z
Пример #51
0
 def test_repeated_add_delete(self):
     d = ordereddict()
     for el in range(0, 9):
         d[el] = el
         del d[el]
Пример #52
0
 def test_ass_consequitive_slice(self):
     r = self.z
     r[10:15] = ordereddict([(1, 0), (2, 1), (3, 2), (4, 24), (5, 25)])
     assert r[9:16] == ordereddict([('j', 9), (1, 0), (2, 1), (3, 2),
                                    (4, 24), (5, 25), ('p', 15)])
Пример #53
0
 def test_rename(self):
     self.x.rename('c', 'caaa')
     assert self.x == ordereddict([('a',1), ('b',2), ('caaa',3), ('d', 4)])
Пример #54
0
 def test_repeated_add_delete(self):
     d = ordereddict()
     for el in range(0,9):
         d[el]=el
         del d[el]
Пример #55
0
 def test_kvio1(self):
     r = ordereddict(kvio=True)
     r.update(self.x)
     r['b']=42
     assert r == ordereddict([('a', 1), ('c', 3), ('d', 4), ('b', 42)])
Пример #56
0
 def test_kvio1(self):
     r = ordereddict(kvio=True)
     r.update(self.x)
     r['b'] = 42
     assert r == ordereddict([('a', 1), ('c', 3), ('d', 4), ('b', 42)])
Пример #57
0
 def test_slice(self):
     r = self.z
     rp = self.part.copy()
     rp.reverse()
     assert r[9:4:-1] == rp
     assert r[5:25:5] == ordereddict([('f', 5), ('k', 10), ('p', 15), ('u', 20)])
Пример #58
0
 def test_del_consequitive_slice(self):
     r = self.z
     del r[3:24]
     assert r == ordereddict([('a', 0), ('b', 1), ('c', 2), ('y', 24), ('z', 25)])
Пример #59
0
 def _test_order(self):
     nd = dict(z=1,y=2,w=3,v=4,x=5)
     r = ordereddict(nd, key=True)
     assert nd.keys() == r.keys()
     assert nd.values() == r.values()