-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsufilter.py
More file actions
71 lines (51 loc) · 2.09 KB
/
Copy pathsufilter.py
File metadata and controls
71 lines (51 loc) · 2.09 KB
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
69
70
import sys
import subunit
import argparse
class FilterStreamer(subunit.StreamResultToBytes):
def __init__(self, output_stream, excluded_ids, logfile):
super(FilterStreamer, self).__init__(output_stream)
self.excluded_ids = excluded_ids
self.logfile = logfile
def should_exclude(self, test_id):
return test_id in self.excluded_ids
def status(self, test_id=None, test_status=None, test_tags=None,
runnable=True, file_name=None, file_bytes=None, eof=False,
mime_type=None, route_code=None, timestamp=None):
if self.should_exclude(test_id):
self.log_exclusion(test_id)
else:
self.log_inclusion(test_id)
return super(FilterStreamer, self).status(
test_id=test_id, test_status=test_status, test_tags=test_tags,
runnable=runnable, file_name=file_name, file_bytes=file_bytes,
eof=eof, mime_type=mime_type, route_code=route_code,
timestamp=timestamp)
def _log(self, status, test_id):
self.logfile.write(status + test_id + '\n')
def log_exclusion(self, test_id):
self._log('EXCLUDED ', test_id)
def log_inclusion(self, test_id):
self._log('INCLUDED ', test_id)
def load_id_list(path):
test_ids = []
with open(path, 'rb') as list_file:
for line in list_file.readlines():
stripped_line = line.strip()
if stripped_line:
test_ids.append(stripped_line)
list_file.close()
return test_ids
def main():
parser = argparse.ArgumentParser(description="Subunit filter")
parser.add_argument("exclude")
parser.add_argument("logfile")
args = parser.parse_args()
excluded_ids = load_id_list(args.exclude)
with open(args.logfile, 'wb') as logfile:
stream_reader = subunit.ByteStreamToStreamResult(sys.stdin)
stream_writer = FilterStreamer(sys.stdout, excluded_ids, logfile)
stream_writer.startTestRun()
stream_reader.run(stream_writer)
stream_writer.stopTestRun()
if __name__ == "__main__":
main()