-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
39 lines (29 loc) · 1022 Bytes
/
test.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
import unittest
import os
def custom_function(file_name):
with open(file_name, 'rt') as f:
return sum(1 for _ in f)
class CustomTests(unittest.TestCase):
def setUp(self):
self.file_name = 'test_file.txt'
with open(self.file_name, 'wt') as f:
f.write("""
파이썬에는 단위테스트 모듈이 기본으로 포함되어 있습니다.
매우 멋지군요!
단위테스트를 잘 수행해보고 싶습니다!
""".strip())
def tearDown(self):
try:
os.remove(self.file_name)
except:
pass
def test_run(self):
custom_function(self.file_name)
def test_line_count(self):
self.assertEqual(custom_function(self.file_name), 3)
def test_no_file(self):
with self.assertRaises(IOError):
# custom_function(self.file_name)
custom_function('abc.txt')
if __name__ == '__main__':
unittest.main()