1
1
import sys
2
- from test import support
3
2
import unittest
4
3
5
- crypt = support .import_module ('crypt' )
6
4
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' )
7
23
class CryptTestCase (unittest .TestCase ):
8
24
9
25
def test_crypt (self ):
@@ -39,9 +55,13 @@ def test_methods(self):
39
55
else :
40
56
self .assertEqual (crypt .methods [- 1 ], crypt .METHOD_CRYPT )
41
57
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
+ )
45
65
def test_sha2_rounds (self ):
46
66
for method in (crypt .METHOD_SHA256 , crypt .METHOD_SHA512 ):
47
67
for rounds in 1000 , 10_000 , 100_000 :
@@ -54,8 +74,9 @@ def test_sha2_rounds(self):
54
74
cr2 = crypt .crypt ('mypassword' , cr )
55
75
self .assertEqual (cr2 , cr )
56
76
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
+ )
59
80
def test_blowfish_rounds (self ):
60
81
for log_rounds in range (4 , 11 ):
61
82
salt = crypt .mksalt (crypt .METHOD_BLOWFISH , rounds = 1 << log_rounds )
0 commit comments