[Python-checkins] bpo-25172: Add test for crypt ImportError on Windows (GH-15252)
Steve Dower
webhook-mailer at python.org
Tue Aug 13 17:27:37 EDT 2019
https://github.com/python/cpython/commit/243a73deee4ac61fe06602b7ed56b6df01e19f27
commit: 243a73deee4ac61fe06602b7ed56b6df01e19f27
branch: master
author: shireenrao <shireenrao at gmail.com>
committer: Steve Dower <steve.dower at python.org>
date: 2019-08-13T14:27:34-07:00
summary:
bpo-25172: Add test for crypt ImportError on Windows (GH-15252)
files:
M Lib/test/test_crypt.py
diff --git a/Lib/test/test_crypt.py b/Lib/test/test_crypt.py
index d9189fc6f28b..d29e005fdad5 100644
--- a/Lib/test/test_crypt.py
+++ b/Lib/test/test_crypt.py
@@ -1,9 +1,25 @@
import sys
-from test import support
import unittest
-crypt = support.import_module('crypt')
+try:
+ import crypt
+ IMPORT_ERROR = None
+except ImportError as ex:
+ crypt = None
+ IMPORT_ERROR = str(ex)
+
+
+ at unittest.skipIf(crypt, 'This should only run on windows')
+class TestWhyCryptDidNotImport(unittest.TestCase):
+ def test_failure_only_for_windows(self):
+ self.assertEqual(sys.platform, 'win32')
+
+ def test_import_failure_message(self):
+ self.assertIn('not supported', IMPORT_ERROR)
+
+
+ at unittest.skipUnless(crypt, 'Not supported on Windows')
class CryptTestCase(unittest.TestCase):
def test_crypt(self):
@@ -39,9 +55,13 @@ def test_methods(self):
else:
self.assertEqual(crypt.methods[-1], crypt.METHOD_CRYPT)
- @unittest.skipUnless(crypt.METHOD_SHA256 in crypt.methods or
- crypt.METHOD_SHA512 in crypt.methods,
- 'requires support of SHA-2')
+ @unittest.skipUnless(
+ crypt
+ and (
+ crypt.METHOD_SHA256 in crypt.methods or crypt.METHOD_SHA512 in crypt.methods
+ ),
+ 'requires support of SHA-2',
+ )
def test_sha2_rounds(self):
for method in (crypt.METHOD_SHA256, crypt.METHOD_SHA512):
for rounds in 1000, 10_000, 100_000:
@@ -54,8 +74,9 @@ def test_sha2_rounds(self):
cr2 = crypt.crypt('mypassword', cr)
self.assertEqual(cr2, cr)
- @unittest.skipUnless(crypt.METHOD_BLOWFISH in crypt.methods,
- 'requires support of Blowfish')
+ @unittest.skipUnless(
+ crypt and crypt.METHOD_BLOWFISH in crypt.methods, 'requires support of Blowfish'
+ )
def test_blowfish_rounds(self):
for log_rounds in range(4, 11):
salt = crypt.mksalt(crypt.METHOD_BLOWFISH, rounds=1 << log_rounds)
More information about the Python-checkins
mailing list