-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_project.py
99 lines (59 loc) · 3.19 KB
/
test_project.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pytest
import os
import stat
from unittest import mock
from project import openpy, open_read_only, openpyfiles, clear_console
# ---- OPEN PY ----
def test_openpy():
file_path = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\calculator.py"
with mock.patch("subprocess.run") as mock_run:
openpy(file_path)
mock_run.assert_called_once_with(["python", "-m", "idlelib.idle", file_path])
def test_openpy_ERROR():
error_file_path = r"D:\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\Errorcalculator.py"
with pytest.raises(FileNotFoundError):
openpy(error_file_path)
# ---- OPEN READ ONLY ----
def test_open_read_only():
file_path = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\calculator.py"
with mock.patch("subprocess.run") as mock_run, mock.patch("os.chmod") as mock_chmod:
open_read_only(file_path)
mock_run.assert_called_once_with(["python", "-m", "idlelib.idle", file_path])
mock_chmod.assert_called_once_with(file_path, stat.S_IREAD)
def test_open_read_only_ERROR():
error_file_path = r"D:\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\Errorcalculator.py"
with pytest.raises(FileNotFoundError):
open_read_only(error_file_path)
# ---- OPEN PY FILES ----
def test_openpyfiles():
with mock.patch("project.openpy") as mock_openpy:
file_1 = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\calculator.py"
file_2 = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\test_calculator.py"
openpyfiles(file_1, file_2)
mock_openpy.assert_any_call(file_1)
mock_openpy.assert_any_call(file_2)
assert mock_openpy.call_count == 2
def test_openpyfiles_ERROR():
# 2 Error Files
with mock.patch("project.openpy") as mock_openpy:
file_1 = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\Errorcalculator.py"
file_2 = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\Errortest_calculator.py"
with pytest.raises(FileNotFoundError):
openpyfiles(file_1, file_2)
# 1 Error File
with mock.patch("project.openpy") as mock_openpy:
file_1 = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\calculator.py"
file_2 = r"D:\VScode\Projects\CS50\Final Project\Assets\Week 0 Basics of Python and Terminal\Calculator\Errortest_calculator.py"
with pytest.raises(FileNotFoundError):
openpyfiles(file_1, file_2)
mock_openpy.assert_any_call(file_1)
assert mock_openpy.call_count == 1
# ---- CLEAR CONSOLE ----
def test_clear_console():
with mock.patch("os.system") as mock_system:
if os.name == "nt":
clear_console()
mock_system.assert_called_once_with("cls")
else:
clear_console
mock_system.assert_called_once_with("clear")