-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_issue28.py
60 lines (45 loc) · 1.45 KB
/
test_issue28.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
import unittest
import sandbox
import os.path
import os
from io import StringIO
import sys
from assignment import Assignment
from command import Command
OUTFILE = sandbox.dir('issue28.txt')
class test_issue28(unittest.TestCase):
def tearDown(self):
if os.path.isfile(OUTFILE):
os.remove(OUTFILE)
def test_missingFile_keepGoing(self):
out = self._get_stdout_as_StringIO()
try:
collector = Collector(OUTFILE)
Assignment(sandbox.dir('issue28.json')).accept(collector.visit)
self.assertTrue(len(collector.get_lines()) == 5)
output = out.getvalue().strip()
self.assertRegex(output, 'Not found: .*student2/file1.txt',
msg=output)
finally:
self._restore_stdout()
def _get_stdout_as_StringIO(self):
self._saved_stdout = sys.stdout
out = StringIO()
sys.stdout = out
return out
def _restore_stdout(self):
sys.stdout = self._saved_stdout
class Collector(object):
def __init__(self, file_):
self._file = file_
self.ls = Command('ls "{ins}" >> ' + file_)
def visit(self, submission_directory, files_to_collect):
for file in files_to_collect:
self.ls(file)
def get_lines(self):
lines = []
with open(self._file) as outfile:
lines = outfile.readlines()
return lines
if __name__ == '__main__':
unittest.main()