Exemplo n.º 1
0
 def test_sizeof_dict(self):
     thing = {'A': 1, 'B': 2}
     n = getsizeof(thing)
     for x in thing:
         n += getsizeof(x)
     for x in thing.values():
         n += getsizeof(x)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 2
0
 def test_sizeof_dict(self):
     thing = {'A': 1, 'B': 2}
     n = getsizeof(thing)
     for x in thing:
         n += getsizeof(x)
     for x in thing.values():
         n += getsizeof(x)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 3
0
 def test_sizeof_object(self):
     class A:
         def __init__(self):
             self.name = 'elmer'
             self.age = 10
     thing = A()
     n = getsizeof(thing)
     n += getsizeof(thing.__dict__)
     for x in thing.__dict__:
         n += getsizeof(x)
     for x in thing.__dict__.values():
         n += getsizeof(x)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 4
0
    def test_sizeof_object(self):
        class A:
            def __init__(self):
                self.name = 'elmer'
                self.age = 10

        thing = A()
        n = getsizeof(thing)
        n += getsizeof(thing.__dict__)
        for x in thing.__dict__:
            n += getsizeof(x)
        for x in thing.__dict__.values():
            n += getsizeof(x)
        self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 5
0
 def test_format(self):
     self.assertEqual(Memory.format(20), '20')
     self.assertEqual(Memory.format(2000), '2 kB')
     self.assertEqual(Memory.format(2000000), '2 mB')
     self.assertEqual(Memory.format(2000000000), '2 gB')
Exemplo n.º 6
0
 def test_sizeof_not_formatted(self):
     n = Memory.sizeof(1, False)
     self.assertTrue(isinstance(n, int))
     self.assertEqual(n, getsizeof(1))
Exemplo n.º 7
0
 def test_sizeof(self):
     s = Memory.sizeof(1)
     self.assertTrue(isinstance(s, str))
     self.assertTrue(len(s))
Exemplo n.º 8
0
 def test_sizeof_history(self):
     thing = 1
     history = set()
     history.add(id(thing))
     self.assertEqual(Memory._sizeof(thing, history), 0)
Exemplo n.º 9
0
 def test_sizeof_list(self):
     thing = ['123', '234']
     n = getsizeof(thing)
     for x in thing:
         n += getsizeof(x)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 10
0
 def test_sizeof_string(self):
     thing = '123'
     n = getsizeof(thing)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 11
0
 def test_sizeof_list(self):
     thing = ['123', '234']
     n = getsizeof(thing)
     for x in thing:
         n += getsizeof(x)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 12
0
 def test_sizeof_string(self):
     thing = '123'
     n = getsizeof(thing)
     self.assertEqual(Memory._sizeof(thing, set()), n)
Exemplo n.º 13
0
 def test_format(self):
     self.assertEqual(Memory.format(20), '20')
     self.assertEqual(Memory.format(2000), '2 kB')
     self.assertEqual(Memory.format(2000000), '2 mB')
     self.assertEqual(Memory.format(2000000000), '2 gB')
Exemplo n.º 14
0
 def test_sizeof_not_formatted(self):
     n = Memory.sizeof(1, False)
     self.assertTrue(isinstance(n, int))
     self.assertEqual(n, getsizeof(1))
Exemplo n.º 15
0
 def test_sizeof(self):
     s = Memory.sizeof(1)
     self.assertTrue(isinstance(s, str))
     self.assertTrue(len(s))
Exemplo n.º 16
0
 def test_sizeof_history(self):
     thing = 1
     history = set()
     history.add(id(thing))
     self.assertEqual(Memory._sizeof(thing, history), 0)