-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_parser.py
66 lines (49 loc) · 1.34 KB
/
test_parser.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
import argparse
import sys
import pytest
from parser import parser
def assertValues(
args: argparse.Namespace,
size: int,
fitness_cutoff: int,
mutation_rate: float,
win_percent: float,
max_iter: int,
) -> None:
assert isinstance(args.size, int)
assert isinstance(args.fitness_cutoff, int)
assert isinstance(args.mutation_rate, float)
assert isinstance(args.win_percent, float)
assert isinstance(args.max_iter, int)
assert args.size == size
assert args.fitness_cutoff == fitness_cutoff
assert args.mutation_rate == mutation_rate
assert args.win_percent == win_percent
assert args.max_iter == max_iter
def test_default_arguments():
sys.argv = ["a.py"]
args = parser.parse_args()
assertValues(args, 25, 5, 0.05, 0.75, 1000)
def test_custom_arguments():
sys.argv = [
"a.py",
"-s",
"50",
"-f",
"10",
"-mr",
".1",
"-wp",
"0.8",
"-mi",
"500",
]
args = parser.parse_args()
assertValues(args, 50, 10, 0.1, 0.8, 500)
def test_wrong_argument_type(capsys):
sys.argv = [".py", "--size", "abc"]
with pytest.raises(SystemExit):
parser.parse_args()
captured = capsys.readouterr()
assert "invalid int value: 'abc'" in captured.err
assert "error:" in captured.err