-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_bmi.py
55 lines (38 loc) · 1.39 KB
/
test_bmi.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
import pytest
from bmi import create_parser, handle_args
@pytest.fixture
def parser():
return create_parser()
def test_no_args_exits(parser):
# parser.parse_args should raise the exception but in case
# you raised it explicitly further down the stack let's check
# if handle_args raises it (same applies to next test)
with pytest.raises(SystemExit):
handle_args()
def test_help_flag_exits(parser):
with pytest.raises(SystemExit):
args = parser.parse_args(['-h'])
handle_args(args)
def test_only_width_exits(parser):
with pytest.raises(SystemExit):
args = parser.parse_args(['-w', '80'])
handle_args(args)
def test_only_length_exits(parser):
with pytest.raises(SystemExit):
args = parser.parse_args(['-l', '187'])
handle_args(args)
def test_two_arg(parser, capfd):
args = parser.parse_args(['-w', '80', '-l', '187'])
handle_args(args)
output = capfd.readouterr()[0]
assert "Your BMI is: 22.88" in output
def test_two_arg_reversed_order(parser, capfd):
args = parser.parse_args(['-l', '187', '-w', '80'])
handle_args(args)
output = capfd.readouterr()[0]
assert "Your BMI is: 22.88" in output
def test_different_args(parser, capfd):
args = parser.parse_args(['-l', '200', '-w', '100'])
handle_args(args)
output = capfd.readouterr()[0]
assert "Your BMI is: 25.0" in output