-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomizeText-test.py
executable file
·42 lines (35 loc) · 1.06 KB
/
randomizeText-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
40
41
42
#!/usr/bin/python3 -W all
"""
randomizeText-test.py: tests for randomizeText.py
usage: randomizeText-test.py
20171120 erikt(at)xs4all.nl
"""
import io
import re
import sys
import unittest
from contextlib import redirect_stdout
from randomizeText import readData
from randomizeText import printData
DATA = ['a','b','c']
def string2list(inString):
outList = inString.split("\n")
if re.search("\n$",inString): outList.pop()
return(outList)
def list2string(inList):
outString = "\n".join(inList)
if len(outString) > 0: outString+"\n"
return(outString)
class myTest(unittest.TestCase):
def testPrintData(self):
f = io.StringIO()
with redirect_stdout(f): printData(list(DATA))
results = string2list(f.getvalue())
self.assertEqual(len(results),len(DATA))
self.assertEqual(sorted(results),sorted(DATA))
def testReadData(self):
sys.stdin = io.StringIO(list2string(DATA))
results = readData()
self.assertEqual(results,DATA)
if __name__ == '__main__':
unittest.main()