Standardize behavior: no docstrings in test functions; create a single

suite merging all test cases.
This commit is contained in:
Guido van Rossum 2002-08-22 19:38:14 +00:00
parent cb682584a3
commit 7e8fdba01c
1 changed files with 19 additions and 13 deletions

View File

@ -3,8 +3,9 @@ import unittest
from test import test_support from test import test_support
class TestVectorsTestCase(unittest.TestCase): class TestVectorsTestCase(unittest.TestCase):
def test_vectors(self): def test_vectors(self):
"""Test the HMAC module against test vectors from the RFC.""" # Test the HMAC module against test vectors from the RFC.
def md5test(key, data, digest): def md5test(key, data, digest):
h = hmac.HMAC(key, data) h = hmac.HMAC(key, data)
@ -23,8 +24,9 @@ class TestVectorsTestCase(unittest.TestCase):
"56be34521d144c88dbb8c733f0e8b3f6") "56be34521d144c88dbb8c733f0e8b3f6")
class ConstructorTestCase(unittest.TestCase): class ConstructorTestCase(unittest.TestCase):
def test_normal(self): def test_normal(self):
"""Standard constructor call.""" # Standard constructor call.
failed = 0 failed = 0
try: try:
h = hmac.HMAC("key") h = hmac.HMAC("key")
@ -32,14 +34,14 @@ class ConstructorTestCase(unittest.TestCase):
self.fail("Standard constructor call raised exception.") self.fail("Standard constructor call raised exception.")
def test_withtext(self): def test_withtext(self):
"""Constructor call with text.""" # Constructor call with text.
try: try:
h = hmac.HMAC("key", "hash this!") h = hmac.HMAC("key", "hash this!")
except: except:
self.fail("Constructor call with text argument raised exception.") self.fail("Constructor call with text argument raised exception.")
def test_withmodule(self): def test_withmodule(self):
"""Constructor call with text and digest module.""" # Constructor call with text and digest module.
import sha import sha
try: try:
h = hmac.HMAC("key", "", sha) h = hmac.HMAC("key", "", sha)
@ -47,14 +49,15 @@ class ConstructorTestCase(unittest.TestCase):
self.fail("Constructor call with sha module raised exception.") self.fail("Constructor call with sha module raised exception.")
class SanityTestCase(unittest.TestCase): class SanityTestCase(unittest.TestCase):
def test_default_is_md5(self): def test_default_is_md5(self):
"""Testing if HMAC defaults to MD5 algorithm.""" # Testing if HMAC defaults to MD5 algorithm.
import md5 import md5
h = hmac.HMAC("key") h = hmac.HMAC("key")
self.failUnless(h.digestmod == md5) self.failUnless(h.digestmod == md5)
def test_exercise_all_methods(self): def test_exercise_all_methods(self):
"""Exercising all methods once.""" # Exercising all methods once.
# This must not raise any exceptions # This must not raise any exceptions
try: try:
h = hmac.HMAC("my secret key") h = hmac.HMAC("my secret key")
@ -66,8 +69,9 @@ class SanityTestCase(unittest.TestCase):
self.fail("Exception raised during normal usage of HMAC class.") self.fail("Exception raised during normal usage of HMAC class.")
class CopyTestCase(unittest.TestCase): class CopyTestCase(unittest.TestCase):
def test_attributes(self): def test_attributes(self):
"""Testing if attributes are of same type.""" # Testing if attributes are of same type.
h1 = hmac.HMAC("key") h1 = hmac.HMAC("key")
h2 = h1.copy() h2 = h1.copy()
self.failUnless(h1.digestmod == h2.digestmod, self.failUnless(h1.digestmod == h2.digestmod,
@ -78,7 +82,7 @@ class CopyTestCase(unittest.TestCase):
"Types of outer don't match.") "Types of outer don't match.")
def test_realcopy(self): def test_realcopy(self):
"""Testing if the copy method created a real copy.""" # Testing if the copy method created a real copy.
h1 = hmac.HMAC("key") h1 = hmac.HMAC("key")
h2 = h1.copy() h2 = h1.copy()
# Using id() in case somebody has overridden __cmp__. # Using id() in case somebody has overridden __cmp__.
@ -89,7 +93,7 @@ class CopyTestCase(unittest.TestCase):
"No real copy of the attribute 'outer'.") "No real copy of the attribute 'outer'.")
def test_equality(self): def test_equality(self):
"""Testing if the copy has the same digests.""" # Testing if the copy has the same digests.
h1 = hmac.HMAC("key") h1 = hmac.HMAC("key")
h1.update("some random text") h1.update("some random text")
h2 = h1.copy() h2 = h1.copy()
@ -99,10 +103,12 @@ class CopyTestCase(unittest.TestCase):
"Hexdigest of copy doesn't match original hexdigest.") "Hexdigest of copy doesn't match original hexdigest.")
def test_main(): def test_main():
test_support.run_unittest(TestVectorsTestCase) suite = unittest.TestSuite()
test_support.run_unittest(ConstructorTestCase) suite.addTest(unittest.makeSuite(TestVectorsTestCase))
test_support.run_unittest(SanityTestCase) suite.addTest(unittest.makeSuite(ConstructorTestCase))
test_support.run_unittest(CopyTestCase) suite.addTest(unittest.makeSuite(SanityTestCase))
suite.addTest(unittest.makeSuite(CopyTestCase))
test_support.run_suite(suite)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()