diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-07-11 16:36:22 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-07-15 15:01:51 -0700 |
commit | b40e654617ee8bb4a81b07a70198ae48548f2f05 (patch) | |
tree | bf3e7ad43bd1b05348413aecf522c77da9cf78c1 /tests/utilities.py | |
parent | 5977cf3f43715fe0c22b14d861d6912d4b571c26 (diff) |
tests/crypto: Add tests for the crypto module
This covers mosts of the functions in the crypto module, but doesn't
bother with the hash_key function, which is slated for deletion in the
port to python-gpg. It also doesn't cover re-raising errors.
Diffstat (limited to 'tests/utilities.py')
-rw-r--r-- | tests/utilities.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/utilities.py b/tests/utilities.py index aae79552..ed169b59 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -98,3 +98,48 @@ class TestCaseClassCleanup(unittest.TestCase): # TODO: addCleanups success if part of the success of the test, # what should we do here? func(*args, **kwargs) + + +class ModuleCleanup(object): + """Class for managing module level setup and teardown fixtures. + + Because of the way unittest is implemented it's rather difficult to write + elegent fixtures because setUpModule and tearDownModule must exist when the + module is initialized, so you can't do things like assign the methods to + setUpModule and tearDownModule, nor can you just do some globals + manipulation. + """ + + def __init__(self): + self.__stack = [] + + def do_cleanups(self): + while self.__stack: + func, args, kwargs = self.__stack.pop() + func(*args, **kwargs) + + def add_cleanup(self, func, *args, **kwargs): + self.__stack.append((func, args, kwargs)) + + def wrap_teardown(self, teardown): + + @functools.wraps(teardown) + def wrapper(): + try: + teardown() + finally: + self.do_cleanups() + + return wrapper + + def wrap_setup(self, setup): + + @functools.wraps(setup) + def wrapper(): + try: + setup() + except Exception: + self.do_cleanups() + raise + + return wrapper |