-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main_template.py
68 lines (53 loc) · 1.51 KB
/
test_main_template.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
#!/usr/bin/env python3
"""
Unit Tests for the --Problem Name-- problem
for Google Code Jam --Year--
--Round--
Link to problem description:
--Link--
Author:
Tasos Sangiotis
(tsagi)
Language:
Python 3(.4)
Date:
--Date--
Usage:
python3 test_main.py
"""
import io
import sys
import unittest
# modules I've written:
import runme
class TestRunme(unittest.TestCase):
"""
Simple tests for the --Problem Name-- problem
for Google Code Jam --Year--
--Round--
"""
# define if needed
#def setUp(self):
# pass
# define if needed
#def tearDown(self):
# pass
#def test_something(self):
# # use self.assertEqual(), self.assertTrue() or self.assertRaises()
# pass
def test_main_on_sample_in(self):
# call runme.main and get its output into from_main
with io.StringIO() as target_output_stream:
# redirect stdout to an io.StringIO object to run main
sys.stdout, old_stdout = target_output_stream, sys.stdout
runme.main('sample.in')
from_main = target_output_stream.getvalue()
# get original stdout back
sys.stdout = old_stdout
# get the 'sample.out' file's contents
with open('sample.out', 'r', encoding='utf-8') as sample_out:
from_sample_out = sample_out.read()
# compare runme.main's results with sample.out's contents
self.assertEqual(from_main, from_sample_out)
if __name__ == '__main__':
unittest.main()