Example #1
0
 def testRefCountCreate(self):
     """Tests if reference count is set correctly on creation"""
     # Not sure why, but the following statements need to be run once before
     # mem() is invoked to get a stable initial memory footprint. If these
     # statements are not run, the initial memory footprint is ***always***
     # different from the one after the loop. I can only guess that these
     # statements have side-effects in Python that claim memory when they
     # are run for the first time...
     md5()
     mem()
     # The number of md5 objects to create. Should be high enough so that
     # the cumulative memory leak (if it exists) is greater than a memory
     # page size (see limitations of mem()).
     objectCount = 10000
     # Get memory after all objects that remain in use have been created.
     # After this statement only objects must be created that are expected
     # to be destroyed before the next invocation of mem().
     memory = mem()
     while objectCount > 0:
         objectCount -= 1
         # Store no references. If the C implementation handles reference
         # counts correctly, it can be expected that the object will be
         # destroyed immediately.
         md5()
     self.assertEqual(memory, mem())
Example #2
0
 def testRefCountCreate(self):
     """Tests if reference count is set correctly on creation"""
     # Not sure why, but the following statements need to be run once before
     # mem() is invoked to get a stable initial memory footprint. If these
     # statements are not run, the initial memory footprint is ***always***
     # different from the one after the loop. I can only guess that these
     # statements have side-effects in Python that claim memory when they
     # are run for the first time...
     md5()
     mem()
     # The number of md5 objects to create. Should be high enough so that
     # the cumulative memory leak (if it exists) is greater than a memory
     # page size (see limitations of mem()).
     objectCount = 10000
     # Get memory after all objects that remain in use have been created.
     # After this statement only objects must be created that are expected
     # to be destroyed before the next invocation of mem().
     memory = mem()
     while objectCount > 0:
         objectCount -= 1
         # Store no references. If the C implementation handles reference
         # counts correctly, it can be expected that the object will be
         # destroyed immediately.
         md5()
     self.assertEqual(memory, mem())
Example #3
0
 def testRefCountCopy(self):
     """Tests if reference count is set correctly on md5.copy()"""
     # See comment in the first test method above why these statements are
     # necessary
     md5()
     mem()
     # The actual test starts here
     objectCount = 10000
     memory = mem()
     while objectCount > 0:
         objectCount -= 1
         md5().copy()
     self.assertEqual(memory, mem())
Example #4
0
 def testRefCountCopy(self):
     """Tests if reference count is set correctly on md5.copy()"""
     # See comment in the first test method above why these statements are
     # necessary
     md5()
     mem()
     # The actual test starts here
     objectCount = 10000
     memory = mem()
     while objectCount > 0:
         objectCount -= 1
         md5().copy()
     self.assertEqual(memory, mem())
Example #5
0
 def testRefCountHash(self):
     """Tests if no memory leaks occur when performing a hash operation"""
     # See comment in the first test method above why these statements are
     # necessary
     m = md5(self.inputNormal)
     mem()
     # The actual test starts here
     objectCount = 10000
     memory = mem()
     while objectCount > 0:
         objectCount -= 1
         m = md5(self.inputNormal)
         self.assertEqual(m.hexdigest(), self.expectedHexdigestInputNormal)
     self.assertEqual(memory, mem())
Example #6
0
 def testRefCountHash(self):
     """Tests if no memory leaks occur when performing a hash operation"""
     # See comment in the first test method above why these statements are
     # necessary
     m = md5(self.inputNormal)
     mem()
     # The actual test starts here
     objectCount = 10000
     memory = mem()
     while objectCount > 0:
         objectCount -= 1
         m = md5(self.inputNormal)
         self.assertEqual(m.hexdigest(), self.expectedHexdigestInputNormal)
     self.assertEqual(memory, mem())
Example #7
0
 def testCopyAndDelete(self):
     m1 = md5(self.inputNormal)
     m2 = m1.copy()
     del m1
     m2.update(self.inputNormal)
     hexdigest = m2.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputTwice)
Example #8
0
 def testCopyTwice(self):
     m1 = md5(self.inputNormal)
     m2 = m1.copy()
     m3 = m1.copy()
     self.assertNotEqual(m1, m2)
     self.assertNotEqual(m1, m3)
     self.assertNotEqual(m2, m3)
Example #9
0
 def testHexdigestTwice(self):
     m = md5()
     m.update(self.inputNormal)
     hexdigest1 = m.hexdigest()
     hexdigest2 = m.hexdigest()
     self.assertEqual(hexdigest1, self.expectedHexdigestInputNormal)
     self.assertEqual(hexdigest2, self.expectedHexdigestInputNormal)
Example #10
0
 def testHexdigest(self):
     # This test is somewhat pointless, the hexdigest() method has already
     # been thoroughly tested by other functions. We still perform this
     # test so that hexdigest() has at least one explicit test.
     m = md5()
     m.update(self.inputNormal)
     hexdigest = m.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputNormal)
Example #11
0
 def testCopy(self):
     m1 = md5(self.inputNormal)
     m2 = m1.copy()
     self.assertNotEqual(m1, m2)
     hexdigest1 = m1.hexdigest()
     hexdigest2 = m2.hexdigest()
     self.assertEqual(hexdigest1, self.expectedHexdigestInputNormal)
     self.assertEqual(hexdigest2, self.expectedHexdigestInputNormal)
     m1.update(self.inputNormal)
     hexdigest1 = m1.hexdigest()
     hexdigest2 = m2.hexdigest()
     self.assertEqual(hexdigest1, self.expectedHexdigestInputTwice)
     self.assertEqual(hexdigest2, self.expectedHexdigestInputNormal)
Example #12
0
 def testUpdateInputIsNone(self):
     m = md5()
     input = None
     self.assertRaises(TypeError, m.update, input)
Example #13
0
 def testUpdateInputIsEmpty(self):
     m = md5()
     m.update(self.inputEmpty)
     hexdigest = m.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputEmpty)
Example #14
0
 def testUpdate(self):
     m = md5()
     m.update(self.inputNormal)
     hexdigest = m.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputNormal)
Example #15
0
 def testDelete(self):
     # There's not much that we can test besides the bare fact that an md5
     # object can be deleted without any error
     m = md5()
     del m
Example #16
0
 def testCreateTwice(self):
     m1 = md5()
     m2 = md5()
     self.assertNotEqual(m1, m2)
Example #17
0
 def testCreateInitInputIsEmpty(self):
     m = md5(self.inputEmpty)
     hexdigest = m.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputEmpty)
Example #18
0
 def testCreateKeywordInitInput(self):
     m = md5(input = self.inputNormal)
     hexdigest = m.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputNormal)
Example #19
0
 def testCreate(self):
     m = md5()
     hexdigest = m.hexdigest()
     self.assertEqual(hexdigest, self.expectedHexdigestInputEmpty)
Example #20
0
 def testName(self):
     m = md5()
     self.assertEqual(m.name, "md5")
Example #21
0
 def testBlockSize(self):
     m = md5()
     self.assertEqual(m.block_size, 64)
Example #22
0
 def testDigestSize(self):
     m = md5()
     self.assertEqual(m.digest_size, 16)
Example #23
0
 def testDigest(self):
     m = md5()
     m.update(self.inputNormal)
     digest = m.digest()
     self.assertEqual(digest, self.expectedDigestInputNormal)