-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.py
70 lines (50 loc) · 1.41 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# coding: utf-8
import os
import tempfile
import safe
def test_asdf():
s = safe.check('dfghjkl', length=7)
assert not s
assert 'pattern' in str(s)
def test_step():
s = safe.check('abcdefg', length=7)
assert not s
assert 'pattern' in s.message
def test_common():
s = safe.check('password')
assert not s
assert 'common' in s.message
def test_short():
s = safe.check('1')
assert not s
assert 'short' in s.message
def test_simple():
s = safe.check('yhnolku', length=6)
assert not s
assert 'simple' in s.message
def test_medium():
s = safe.check('yhnolkuT', length=7)
assert not s
assert repr(s) == 'medium'
def test_strong():
s = safe.check('yhnolkuT.')
assert bool(s)
assert 'perfect' in s.message
def test_no_cache_on_load_words():
cache_file = _clear_cache_file()
words = safe._load_words(cache_words=False)
assert words
assert not os.path.exists(cache_file)
def test_no_cache_on_safe_check():
cache_file = _clear_cache_file()
s = safe.check('yhnolkuT.', cache_words=False)
assert not os.path.exists(cache_file)
def _clear_cache_file():
filename = 'safe-%s.words.cache' % safe.__version__
_cache_file = os.environ.get(
'PYTHON_SAFE_WORDS_CACHE',
os.path.join(tempfile.gettempdir(), filename),
)
if os.path.exists(_cache_file):
os.remove(_cache_file)
return _cache_file