Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7e8fdba0
Commit
7e8fdba0
authored
Aug 22, 2002
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standardize behavior: no docstrings in test functions; create a single
suite merging all test cases.
parent
cb682584
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
Lib/test/test_hmac.py
Lib/test/test_hmac.py
+19
-13
No files found.
Lib/test/test_hmac.py
View file @
7e8fdba0
...
...
@@ -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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment