-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscripts-tests.py
67 lines (52 loc) · 1.42 KB
/
scripts-tests.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
#!/usr/bin/env python
# file: scripts-tests.py
# vim:fileencoding=utf-8:ft=python
#
# Copyright © 2018 R.F. Smith <[email protected]>.
# SPDX-License-Identifier: MIT
# Created: 2015-04-06T13:08:02+0200
# Last modified: 2019-07-27T15:11:11+0200
"""
Tests for functions in python files in the scripts directory.
To run the tests use: py.test -v scripts-tests.py
"""
from collections import Counter
from genotp import rndcaps, otp
from genpw import roundup, genpw
from nospaces import fixname
from offsetsrt import str2ms, ms2str
def test_rndcaps():
rv = rndcaps(20)
assert len(rv) == 20
assert all(j in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for j in rv)
v = Counter(rndcaps(100000)).values()
mxc = max(v)
mnc = min(v)
assert mxc / mnc < 1.3
def test_otp():
lines = otp(5).splitlines()
assert len(lines) == 5
for ln in lines:
assert len(ln) == 75
def test_roundup():
assert roundup(1) == 3
assert roundup(2) == 3
assert roundup(3) == 3
assert roundup(4) == 3
assert roundup(5) == 6
assert roundup(6) == 6
assert roundup(7) == 6
assert roundup(8) == 6
assert roundup(9) == 9
def test_genpw():
for n in range(12):
assert len(genpw(n)) == n
def test_fixname():
rv = fixname("dit is een\ttest")
assert rv == "dit_is_een_test"
def test_srt():
for j in range(7200):
p = j * 10
ts = ms2str(p)
k = str2ms(ts)
assert p == k