-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pow2.py
More file actions
41 lines (35 loc) · 741 Bytes
/
test_pow2.py
File metadata and controls
41 lines (35 loc) · 741 Bytes
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
import pytest
from pow2 import *
def test_pow_number():
assert pow(5) == 25
def test_pow_number_str():
assert pow("5") == 25
def test_pow_negative_number_str():
assert pow("-5") == 25
def test_pow_letter():
with pytest.raises(ValueError):
assert pow("a")
def test_main_numbers_txt(capsys: pytest.CaptureFixture):
main("numbers.txt")
stdout = capsys.readouterr()
assert """1
4
9
16
25
36
49
64
81
100
""" == stdout.out
def test_main_numbers_with_letter(capsys: pytest.CaptureFixture):
with pytest.raises(SystemExit) as exit_info:
main("numbers_with_letter.txt")
assert exit_info.value.code == 1
stdout = capsys.readouterr()
assert """1
4
9
Could not parse: a
""" == stdout.out