-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_run_python_file.py
More file actions
51 lines (39 loc) · 1.72 KB
/
Copy pathtest_run_python_file.py
File metadata and controls
51 lines (39 loc) · 1.72 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
import unittest
import os
from functions.run_python_file import run_python_file
class TestWriteFile(unittest.TestCase):
def test_calculator_usage_instruction(self):
print("Results for current directory")
result = run_python_file("calculator", "main.py")
print(result, "\n")
self.assertIn("Usage: python main.py", result)
def test_run_calculator(self):
print("Results for current directory")
result = run_python_file("calculator", "main.py", ["3 + 5"])
print(result, "\n")
self.assertIn("8", result)
def test_run_calculator_test(self):
print("Results for current directory")
result = run_python_file("calculator", "tests.py")
print(result, "\n")
self.assertIn("Ran 9 tests in", result)
def test_file_in_parent_dir(self):
print("Results for current directory")
with self.assertRaises(Exception) as ctx:
run_python_file("calculator", "../main.py")
print(ctx.exception, "\n")
self.assertIn("outside the permitted working directory", str(ctx.exception))
def test_non_existing_file(self):
print("Results for current directory")
with self.assertRaises(Exception) as ctx:
run_python_file("calculator", "nonexistent.py")
print(ctx.exception, "\n")
self.assertIn("does not exists", str(ctx.exception))
def test_not_a_python_file(self):
print("Results for current directory")
with self.assertRaises(Exception) as ctx:
run_python_file("calculator", "lorem.txt")
print(ctx.exception, "\n")
self.assertIn("is not a Python file", str(ctx.exception))
if __name__ == "__main__":
unittest.main(verbosity=2)