OLD | NEW |
(Empty) | |
| 1 # -*- coding: utf-8 -*- |
| 2 # |
| 3 # SelfTest/st_common.py: Common functions for SelfTest modules |
| 4 # |
| 5 # Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net> |
| 6 # |
| 7 # =================================================================== |
| 8 # The contents of this file are dedicated to the public domain. To |
| 9 # the extent that dedication to the public domain is not available, |
| 10 # everyone is granted a worldwide, perpetual, royalty-free, |
| 11 # non-exclusive license to exercise all rights associated with the |
| 12 # contents of this file for any purpose whatsoever. |
| 13 # No rights are reserved. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 # SOFTWARE. |
| 23 # =================================================================== |
| 24 |
| 25 """Common functions for SelfTest modules""" |
| 26 |
| 27 __revision__ = "$Id$" |
| 28 |
| 29 import unittest |
| 30 import binascii |
| 31 import sys |
| 32 if sys.version_info[0] == 2 and sys.version_info[1] == 1: |
| 33 from Crypto.Util.py21compat import * |
| 34 from Crypto.Util.py3compat import * |
| 35 |
| 36 class _list_testloader(unittest.TestLoader): |
| 37 suiteClass = list |
| 38 |
| 39 def list_test_cases(class_): |
| 40 """Return a list of TestCase instances given a TestCase class |
| 41 |
| 42 This is useful when you have defined test* methods on your TestCase class. |
| 43 """ |
| 44 return _list_testloader().loadTestsFromTestCase(class_) |
| 45 |
| 46 def strip_whitespace(s): |
| 47 """Remove whitespace from a text or byte string""" |
| 48 if isinstance(s,str): |
| 49 return b("".join(s.split())) |
| 50 else: |
| 51 return b("").join(s.split()) |
| 52 |
| 53 def a2b_hex(s): |
| 54 """Convert hexadecimal to binary, ignoring whitespace""" |
| 55 return binascii.a2b_hex(strip_whitespace(s)) |
| 56 |
| 57 def b2a_hex(s): |
| 58 """Convert binary to hexadecimal""" |
| 59 # For completeness |
| 60 return binascii.b2a_hex(s) |
| 61 |
| 62 # vim:set ts=4 sw=4 sts=4 expandtab: |
OLD | NEW |