diff options
author | Saif Hakim <saif@benchling.com> | 2021-02-17 00:08:18 -0800 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2021-02-24 13:35:18 +0100 |
commit | 214c0f90e2dab0bc3d5a052cdf726c762cb4b74c (patch) | |
tree | 7d15b1fdc72bd4e21d19e73c4d433860507ad3ec | |
parent | 4c3cd57ae2717856e09b9fed587e4d1afa3b44f2 (diff) | |
download | rsa-git-214c0f90e2dab0bc3d5a052cdf726c762cb4b74c.tar.gz |
Clean up stdout when using unittest test runner
While pytest is the preferred test runner via tox, it looks like some folks are
still running tests via `python3 setup.py test` which uses unittest and does
not have good support for capturing stdout. To make using unittest slightly
more friendly, we further swallow stdout / stderr for cli tests, and ensure
print statements start on a newline.
-rw-r--r-- | tests/test_cli.py | 10 | ||||
-rw-r--r-- | tests/test_integers.py | 4 | ||||
-rw-r--r-- | tests/test_pkcs1.py | 2 | ||||
-rw-r--r-- | tests/test_strings.py | 2 |
4 files changed, 9 insertions, 9 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py index 1cd92c2..00f77ac 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -113,7 +113,7 @@ class AbstractCliTest(unittest.TestCase): class KeygenTest(AbstractCliTest): def test_keygen_no_args(self): - with cli_args(): + with captured_output(), cli_args(): self.assertExits(1, rsa.cli.keygen) def test_keygen_priv_stdout(self): @@ -182,11 +182,11 @@ class KeygenTest(AbstractCliTest): class EncryptDecryptTest(AbstractCliTest): def test_empty_decrypt(self): - with cli_args(): + with captured_output(), cli_args(): self.assertExits(1, rsa.cli.decrypt) def test_empty_encrypt(self): - with cli_args(): + with captured_output(), cli_args(): self.assertExits(1, rsa.cli.encrypt) @cleanup_files('encrypted.txt', 'cleartext.txt') @@ -227,11 +227,11 @@ class EncryptDecryptTest(AbstractCliTest): class SignVerifyTest(AbstractCliTest): def test_empty_verify(self): - with cli_args(): + with captured_output(), cli_args(): self.assertExits(1, rsa.cli.verify) def test_empty_sign(self): - with cli_args(): + with captured_output(), cli_args(): self.assertExits(1, rsa.cli.sign) @cleanup_files('signature.txt', 'cleartext.txt') diff --git a/tests/test_integers.py b/tests/test_integers.py index 2ca0a9a..659e85a 100644 --- a/tests/test_integers.py +++ b/tests/test_integers.py @@ -26,7 +26,7 @@ class IntegerTest(unittest.TestCase): def test_enc_dec(self): message = 42 - print("\tMessage: %d" % message) + print("\n\tMessage: %d" % message) encrypted = rsa.core.encrypt_int(message, self.pub.e, self.pub.n) print("\tEncrypted: %d" % encrypted) @@ -40,7 +40,7 @@ class IntegerTest(unittest.TestCase): message = 42 signed = rsa.core.encrypt_int(message, self.priv.d, self.pub.n) - print("\tSigned: %d" % signed) + print("\n\tSigned: %d" % signed) verified = rsa.core.decrypt_int(signed, self.pub.e, self.pub.n) print("\tVerified: %d" % verified) diff --git a/tests/test_pkcs1.py b/tests/test_pkcs1.py index 64fb0c5..272e2bc 100644 --- a/tests/test_pkcs1.py +++ b/tests/test_pkcs1.py @@ -29,7 +29,7 @@ class BinaryTest(unittest.TestCase): def test_enc_dec(self): message = struct.pack('>IIII', 0, 0, 0, 1) - print("\tMessage: %r" % message) + print("\n\tMessage: %r" % message) encrypted = pkcs1.encrypt(message, self.pub) print("\tEncrypted: %r" % encrypted) diff --git a/tests/test_strings.py b/tests/test_strings.py index 1090a8e..e392627 100644 --- a/tests/test_strings.py +++ b/tests/test_strings.py @@ -29,7 +29,7 @@ class StringTest(unittest.TestCase): def test_enc_dec(self): message = unicode_string.encode('utf-8') - print("\tMessage: %r" % message) + print("\n\tMessage: %r" % message) encrypted = rsa.encrypt(message, self.pub) print("\tEncrypted: %r" % encrypted) |