11import sys
2- from test import support
32import unittest
43
5- crypt = support .import_module ('crypt' )
64
5+ try :
6+ import crypt
7+ IMPORT_ERROR = None
8+ except ImportError as ex :
9+ crypt = None
10+ IMPORT_ERROR = str (ex )
11+
12+
13+ @unittest .skipIf (crypt , 'This should only run on windows' )
14+ class TestWhyCryptDidNotImport (unittest .TestCase ):
15+ def test_failure_only_for_windows (self ):
16+ self .assertEqual (sys .platform , 'win32' )
17+
18+ def test_import_failure_message (self ):
19+ self .assertIn ('not supported' , IMPORT_ERROR )
20+
21+
22+ @unittest .skipUnless (crypt , 'Not supported on Windows' )
723class CryptTestCase (unittest .TestCase ):
824
925 def test_crypt (self ):
@@ -39,9 +55,13 @@ def test_methods(self):
3955 else :
4056 self .assertEqual (crypt .methods [- 1 ], crypt .METHOD_CRYPT )
4157
42- @unittest .skipUnless (crypt .METHOD_SHA256 in crypt .methods or
43- crypt .METHOD_SHA512 in crypt .methods ,
44- 'requires support of SHA-2' )
58+ @unittest .skipUnless (
59+ crypt
60+ and (
61+ crypt .METHOD_SHA256 in crypt .methods or crypt .METHOD_SHA512 in crypt .methods
62+ ),
63+ 'requires support of SHA-2' ,
64+ )
4565 def test_sha2_rounds (self ):
4666 for method in (crypt .METHOD_SHA256 , crypt .METHOD_SHA512 ):
4767 for rounds in 1000 , 10_000 , 100_000 :
@@ -54,8 +74,9 @@ def test_sha2_rounds(self):
5474 cr2 = crypt .crypt ('mypassword' , cr )
5575 self .assertEqual (cr2 , cr )
5676
57- @unittest .skipUnless (crypt .METHOD_BLOWFISH in crypt .methods ,
58- 'requires support of Blowfish' )
77+ @unittest .skipUnless (
78+ crypt and crypt .METHOD_BLOWFISH in crypt .methods , 'requires support of Blowfish'
79+ )
5980 def test_blowfish_rounds (self ):
6081 for log_rounds in range (4 , 11 ):
6182 salt = crypt .mksalt (crypt .METHOD_BLOWFISH , rounds = 1 << log_rounds )
0 commit comments