-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (30 loc) · 1.18 KB
/
main.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
#First *fork* your copy. Then copy-paste your code below this line 👇
#Finally click "Run" to execute the tests
print("Day 1 - Python Print Function")
print("The function is declared like this:")
print("print('what to print')")
#Copy Paste your code above this line 👆
# 🚨 Do NOT modify the code below this line 👇
with open("testing_copy.py", "w") as file:
file.write("def test_func():\n")
with open("main.py", "r") as original:
f2 = original.readlines()[0:30]
for x in f2:
file.write(" " + x)
import testing_copy
import unittest
from unittest.mock import patch
from io import StringIO
import os
class MyTest(unittest.TestCase):
def test_1(self):
with patch('sys.stdout', new = StringIO()) as fake_out:
testing_copy.test_func()
expected_print = "Day 1 - Python Print Function\nThe function is declared like this:\nprint('what to print')\n"
self.assertEqual(fake_out.getvalue(), expected_print)
print("\n\n")
print('Checking if what you printed matches the target output *exactly*...')
print('Running some tests on your code:')
print(".\n.\n.\n.")
unittest.main(verbosity=1, exit=False)
os.remove("testing_copy.py")