forked from ACC-HelloWorld/python-refresher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_refresher_test.py
More file actions
70 lines (48 loc) · 1.89 KB
/
python_refresher_test.py
File metadata and controls
70 lines (48 loc) · 1.89 KB
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
import math
import datetime
import os
def test_import_example(capsys):
exec(open("import_example.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == str(math.pi)
def test_control_flow(capsys):
exec(open("control_flow.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "10 or less"
def test_variables_data_types(capsys):
exec(open("variables_data_types.py").read())
captured = capsys.readouterr()
assert "25" in captured.out and "John" in captured.out
def test_comments(capsys):
exec(open("comments.py").read())
captured = capsys.readouterr()
assert "This is a comment" in captured.out
def test_functions_methods(capsys):
exec(open("functions_methods.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "Hello, Alice!"
def test_lists_dictionaries(capsys):
exec(open("lists_dictionaries.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "red\nAlice"
def test_modules_packages(capsys):
exec(open("modules_packages.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == str(datetime.date.today())
def test_classes_objects(capsys):
exec(open("classes_objects.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "Beep!"
def test_file_handling(capsys):
exec(open("file_handling.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "Hello, World!"
os.remove("hello.txt") # Clean up the file after the test
def test_error_handling(capsys):
exec(open("error_handling.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "File not found."
def test_string_formatting(capsys):
exec(open("string_formatting.py").read())
captured = capsys.readouterr()
assert captured.out.strip() == "There are 5 apples."