forked from fmerg/pymerkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests
executable file
·80 lines (65 loc) · 1.64 KB
/
runtests
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
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
usage_string="usage: ./$(basename "$0") [file_or_dir] [pytest_options] [-e]
Wraps the pytest command by adding an extra option:
-e/--extended: if provided, the tests will be ran against all
combinations of hash algorith, encoding type,
raw-bytes mode and security mode (3240 in total).
Otherwise the code is tested against the encodings
UTF-8, UTF-16 and UTF-32 yielding 108
combinations in total
Positional arguments
file_or_dir The file or directory to be tested.
Defaults to ./tests
Options:
pytest_options Any options to the pytest command
-e, --extended Run tests against all supported encodings
-h, --help Display this help message and exit
Examples:
./$(basename "$0") --cov --extended
./$(basename "$0") tests/hashing --maxfail=3
./$(basename "$0") tests/hashing -vv -e
"
usage() { echo -n "$usage_string" 1>&2; }
declare -A extended_opts=(
[-e]=1 [--extended]=1)
args=""
extended_mode=false
if [[ $# = 1 ]]; then
case $1 in
-e|--extended)
extended_mode=true
;;
tests*)
args+=$1
;;
-h|--help)
usage
exit 0
;;
*)
args+="tests"
;;
esac
else
for arg in $@
do
if [[ -n "${extended_opts[$arg]}" ]]; then
extended_mode=true
else
args+="$arg "
fi
done
fi
config_file="tests/config.py"
EXT="ENCODINGS = EXTENDED"
LIM="ENCODINGS = LIMITED"
if [ $extended_mode = true ];
then
sed -ie "/$EXT/s/^#//#" $config_file # comment line
sed -ie "/$LIM/s/^#*/#/#" $config_file # uncomment line
else
sed -ie "/$EXT/s/^#*/#/" $config_file # uncomment line
sed -ie "/$LIM/s/^#//#" $config_file # comment line
fi
python3 -m pytest $args
exit 0