-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_1-2.py
40 lines (31 loc) · 1.3 KB
/
day_1-2.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
#First *fork* your copy. Then copy-paste your code below this line 👇
#Finally click "Run" to execute the tests
print("Day 1 - String Manipulation")
print('String Concatenation is done with the "+" sign.')
print('e.g. print("Hello " + "world")')
print("New lines can be created with a backslash and n.")
# Write 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 - String Manipulation\nString Concatenation is done with the "+" sign.\ne.g. print("Hello " + "world")\nNew lines can be created with a backslash and n.\n'
self.assertEqual(fake_out.getvalue(), expected_print)
print("\n\n\n.\n.\n.")
print('Checking if what you printed matches the target output *exactly*...')
print('Running some tests on your code:')
print(".\n.\n.")
unittest.main(verbosity=1, exit=False)
os.remove("testing_copy.py")