예제 #1
0
 def test_tuple_keyerror(self):
     # SF #1576657
     j = judy.JudyIntObjectMap()
     try:
         j[(1, )]
     except KeyError, e:
         self.assertEqual(e.args, ((1, ), ))
예제 #2
0
def mem_measure(kv_sequence_func, sequence_name):
	# our x-values
	x = [int((1.2)**i) for i in xrange(50, 60, 1)]

	# and our measured values
	m_j_io = [ ]
	m_p_io = [ ]

	# m_j_ii = [ ]
	# m_p_ii = [ ]

	m_j_i = [ ]
	m_p_i = [ ]

	# for each race
	for N, n in enumerate(x):
		print 'N', N, n
		# our candidates
		j_io = judy.JudyIntObjectMap()
		p_io = dict()

		# j_ii = judy.JudyIntIntMap()
		# p_ii = dict()

		j_i = judy.JudyIntSet()
		p_i = set()

		# some value to put in io mappings
		io_v = 'foobar'

		for k, v in kv_sequence_func(n):
			j_io[k] = io_v
			p_io[k] = io_v

			# j_ii[k] = v
			# p_ii[k] = v

			j_i.add(k)
			p_i.add(k)

		m_j_io.append(judy_io_map_mem(j_io))
		m_p_io.append(python_io_map_mem(p_io))

		# m_j_ii.append(judy_ii_map_mem(j_ii))
		# m_p_ii.append(python_ii_map_mem(p_ii))

		m_j_i.append(judy_i_set_mem(j_i))
		m_p_i.append(python_i_set_mem(p_i))

	if sys.maxint == 2**63-1:
		bits = 64
	elif sys.maxint == 2**31-1:
		bits = 32
	else:
		raise ValueError('I miss my bits')

	print format_graph(x, m_j_io, m_p_io, 'int/object map',    sequence_name, bits)
	# emit_graph(x, m_j_ii, m_p_ii, 'int/int maps',    sequence_name, bits)
	print format_graph(x, m_j_i,  m_p_i,  'int set',           sequence_name, bits)
예제 #3
0
 def test_clear(self):
     j = judy.JudyIntObjectMap()
     j[1] = 'a'
     j[2] = 'b'
     j[3] = 'c'
     j.clear()
     self.assertEqual(dict(j.iteritems()), {})
     self.assertRaises(TypeError, j.clear, None)
예제 #4
0
 def test_values(self):
     j = judy.JudyIntObjectMap()
     self.assertEqual(list(j.itervalues()), [])
     j[1] = 2
     self.assertEqual(list(j.itervalues()), [2])
     self.assertRaises(TypeError, j.itervalues, None)
     self.assertRaises(TypeError, j.itervalues, 1, None)
     self.assertRaises(TypeError, j.itervalues, None, 1)
예제 #5
0
    def test_repr(self):
        j = judy.JudyIntObjectMap()
        self.assertEqual(repr(j), '{}')
        j[1] = 2
        self.assertEqual(repr(j), '{1: 2}')
        j = judy.JudyIntObjectMap()
        j[1] = j
        self.assertEqual(repr(j), '{1: {...}}')

        class Exc(Exception):
            pass

        class BadRepr(object):
            def __repr__(self):
                raise Exc()

        d = {1: BadRepr()}
        self.assertRaises(Exc, repr, d)
예제 #6
0
    def test_items(self):
        j = judy.JudyIntObjectMap()
        self.assertEqual(list(j.iteritems()), [])

        j[1] = 'foo'
        self.assertEqual(list(j.iteritems()), [(1, 'foo')])

        self.assertRaises(TypeError, j.iteritems, None)
        self.assertRaises(TypeError, j.iteritems, 1, None)
        self.assertRaises(TypeError, j.iteritems, None, 1)
예제 #7
0
 def test_keys(self):
     j = judy.JudyIntObjectMap()
     self.assertEqual(list(j.iterkeys()), [])
     j = {2: 'foo', 4: 'bar'}
     k = list(j.iterkeys())
     self.assert_(2 in j)
     self.assert_(4 in j)
     self.assert_(2 in k)
     self.assert_(4 in k)
     self.assertRaises(TypeError, j.iterkeys, None)
예제 #8
0
    def test_by_index(self):
        j = judy.JudyIntObjectMap()

        j[1000] = 1
        j[500] = 2
        j[1500] = 3

        self.assertEquals(j.by_index(0), 2)
        self.assertEquals(j.by_index(1), 1)
        self.assertEquals(j.by_index(2), 3)
        self.assertRaises(IndexError, j.by_index, 3)
예제 #9
0
 def test_get(self):
     j = judy.JudyIntObjectMap()
     self.assert_(j.get('c') is None)
     self.assertEqual(j.get('c', 3), 3)
     j[1] = 'a'
     j[2] = 'b'
     self.assert_(j.get(3) is None)
     self.assertEqual(j.get(3, 3), 3)
     self.assertEqual(j.get(2), 'b')
     self.assertEqual(j.get(1, 3), 'a')
     self.assertRaises(TypeError, j.get)
     self.assertRaises(TypeError, j.get, None, None, None)
예제 #10
0
    def test_contains(self):
        j = judy.JudyIntObjectMap()
        self.assert_(not ('a' in j))
        self.assert_('a' not in j)
        j[1] = 'a'
        j[2] = 'b'
        self.assert_(not ('a' in j))
        self.assert_('a' not in j)
        self.assert_(1 in j)
        self.assert_(2 in j)
        self.assert_(0 not in j)

        self.assertRaises(TypeError, j.__contains__)
예제 #11
0
    def test_container_iterator(self):
        # Bug #3680: tp_traverse was not implemented for dictiter objects
        class C(object):
            pass

        iterators = (judy.JudyIntObjectMap.iteritems,
                     judy.JudyIntObjectMap.itervalues,
                     judy.JudyIntObjectMap.iterkeys)

        for i in iterators:
            obj = C()
            ref = weakref.ref(obj)
            container = judy.JudyIntObjectMap()
            container[1] = obj
            obj.x = i(container)
            del obj, container
            gc.collect()
            self.assert_(ref() is None, 'Cycle was not collected')
예제 #12
0
    def test_container_refs(self):
        # Bug #3680: tp_traverse was not implemented for dictiter objects
        class C(object):
            pass

        obj = C()

        j = judy.JudyIntObjectMap()
        j[1] = obj
        j[2] = j

        ref = weakref.ref(obj)

        obj.x = j

        del obj, j
        gc.collect()

        self.assert_(ref() is None, 'Cycle was not collected')
예제 #13
0
 def test_len(self):
     j = judy.JudyIntObjectMap()
     self.assertEqual(len(j), 0)
     j[1] = 'a'
     j[2] = 'b'
     self.assertEqual(len(j), 2)
예제 #14
0
 def test_empty_constructor(self):
     self.assertEqual(list(judy.JudyIntObjectMap().iteritems()),
                      list({}.iteritems()))