summaryrefslogtreecommitdiff
path: root/Lib/test/test_hmac.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-22 19:38:14 +0000
committerGuido van Rossum <guido@python.org>2002-08-22 19:38:14 +0000
commitbe86c1850cf615558d543e4d86f22f5ef02f3b93 (patch)
tree009786d597cf66e30e181dec57d1c617cf41c04b /Lib/test/test_hmac.py
parente5648291646e128f9767b83b028d5aa16f117d06 (diff)
downloadcpython-be86c1850cf615558d543e4d86f22f5ef02f3b93.tar.gz
Standardize behavior: no docstrings in test functions; create a single
suite merging all test cases.
Diffstat (limited to 'Lib/test/test_hmac.py')
-rw-r--r--Lib/test/test_hmac.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py
index f9cd73e642..f36db4ea63 100644
--- a/Lib/test/test_hmac.py
+++ b/Lib/test/test_hmac.py
@@ -3,8 +3,9 @@ import unittest
from test import test_support
class TestVectorsTestCase(unittest.TestCase):
+
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):
h = hmac.HMAC(key, data)
@@ -23,8 +24,9 @@ class TestVectorsTestCase(unittest.TestCase):
"56be34521d144c88dbb8c733f0e8b3f6")
class ConstructorTestCase(unittest.TestCase):
+
def test_normal(self):
- """Standard constructor call."""
+ # Standard constructor call.
failed = 0
try:
h = hmac.HMAC("key")
@@ -32,14 +34,14 @@ class ConstructorTestCase(unittest.TestCase):
self.fail("Standard constructor call raised exception.")
def test_withtext(self):
- """Constructor call with text."""
+ # Constructor call with text.
try:
h = hmac.HMAC("key", "hash this!")
except:
self.fail("Constructor call with text argument raised exception.")
def test_withmodule(self):
- """Constructor call with text and digest module."""
+ # Constructor call with text and digest module.
import sha
try:
h = hmac.HMAC("key", "", sha)
@@ -47,14 +49,15 @@ class ConstructorTestCase(unittest.TestCase):
self.fail("Constructor call with sha module raised exception.")
class SanityTestCase(unittest.TestCase):
+
def test_default_is_md5(self):
- """Testing if HMAC defaults to MD5 algorithm."""
+ # Testing if HMAC defaults to MD5 algorithm.
import md5
h = hmac.HMAC("key")
self.failUnless(h.digestmod == md5)
def test_exercise_all_methods(self):
- """Exercising all methods once."""
+ # Exercising all methods once.
# This must not raise any exceptions
try:
h = hmac.HMAC("my secret key")
@@ -66,8 +69,9 @@ class SanityTestCase(unittest.TestCase):
self.fail("Exception raised during normal usage of HMAC class.")
class CopyTestCase(unittest.TestCase):
+
def test_attributes(self):
- """Testing if attributes are of same type."""
+ # Testing if attributes are of same type.
h1 = hmac.HMAC("key")
h2 = h1.copy()
self.failUnless(h1.digestmod == h2.digestmod,
@@ -78,7 +82,7 @@ class CopyTestCase(unittest.TestCase):
"Types of outer don't match.")
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")
h2 = h1.copy()
# Using id() in case somebody has overridden __cmp__.
@@ -89,7 +93,7 @@ class CopyTestCase(unittest.TestCase):
"No real copy of the attribute 'outer'.")
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.update("some random text")
h2 = h1.copy()
@@ -99,10 +103,12 @@ class CopyTestCase(unittest.TestCase):
"Hexdigest of copy doesn't match original hexdigest.")
def test_main():
- test_support.run_unittest(TestVectorsTestCase)
- test_support.run_unittest(ConstructorTestCase)
- test_support.run_unittest(SanityTestCase)
- test_support.run_unittest(CopyTestCase)
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestVectorsTestCase))
+ suite.addTest(unittest.makeSuite(ConstructorTestCase))
+ suite.addTest(unittest.makeSuite(SanityTestCase))
+ suite.addTest(unittest.makeSuite(CopyTestCase))
+ test_support.run_suite(suite)
if __name__ == "__main__":
test_main()