40 TESTSCRIPT_NAME = 'testscript.sh' |
40 TESTSCRIPT_NAME = 'testscript.sh' |
41 SCRIPT_PROLOGUE = """#!/bin/sh |
41 SCRIPT_PROLOGUE = """#!/bin/sh |
42 set -e |
42 set -e |
43 """ |
43 """ |
44 |
44 |
|
45 input_buffer = tempfile.TemporaryFile() |
45 output_buffer = tempfile.TemporaryFile() |
46 output_buffer = tempfile.TemporaryFile() |
46 |
47 |
47 class ExtractorTestError(Exception): |
48 class ExtractorTestError(Exception): |
48 pass |
49 pass |
49 |
50 |
50 |
51 |
51 class ExtractorTest(object): |
52 class ExtractorTest(object): |
52 def __init__(self, **kwargs): |
53 def __init__(self, **kwargs): |
53 for key in ('name',): |
54 setattr(self, 'name', kwargs['name']) |
54 setattr(self, key, kwargs[key]) |
55 setattr(self, 'options', kwargs.get('options', '-n').split()) |
|
56 setattr(self, 'filenames', kwargs.get('filenames', '').split()) |
55 for key in ('directory', 'prerun', 'posttest', 'baseline', 'error', |
57 for key in ('directory', 'prerun', 'posttest', 'baseline', 'error', |
56 'grep', 'antigrep', 'output'): |
58 'grep', 'antigrep', 'input', 'output'): |
57 setattr(self, key, kwargs.get(key, None)) |
59 setattr(self, key, kwargs.get(key, None)) |
58 for key in ('options', 'filenames'): |
|
59 setattr(self, key, kwargs.get(key, '').split()) |
|
60 |
60 |
61 def get_results(self, commands): |
61 def get_results(self, commands, stdin=None): |
62 print >>output_buffer, "Output from %s:" % (' '.join(commands),) |
62 print >>output_buffer, "Output from %s:" % (' '.join(commands),) |
63 output_buffer.flush() |
63 output_buffer.flush() |
64 status = subprocess.call(commands, stdout=output_buffer, |
64 status = subprocess.call(commands, stdout=output_buffer, |
65 stderr=output_buffer) |
65 stderr=output_buffer, stdin=stdin) |
66 process = subprocess.Popen(['find', '!', '-name', TESTSCRIPT_NAME], |
66 process = subprocess.Popen(['find', '!', '-name', TESTSCRIPT_NAME], |
67 stdout=subprocess.PIPE) |
67 stdout=subprocess.PIPE) |
68 process.wait() |
68 process.wait() |
69 output = process.stdout.read(-1) |
69 output = process.stdout.read(-1) |
70 process.stdout.close() |
70 process.stdout.close() |
82 |
82 |
83 def get_extractor_results(self): |
83 def get_extractor_results(self): |
84 if self.prerun: |
84 if self.prerun: |
85 self.write_script(self.prerun) |
85 self.write_script(self.prerun) |
86 subprocess.call(['sh', TESTSCRIPT_NAME]) |
86 subprocess.call(['sh', TESTSCRIPT_NAME]) |
87 return self.get_results([X_SCRIPT] + self.options + self.filenames) |
87 input_buffer.seek(0, 0) |
|
88 input_buffer.truncate() |
|
89 if self.input: |
|
90 input_buffer.write(self.input) |
|
91 if not self.input.endswith('\n'): |
|
92 input_buffer.write('\n') |
|
93 input_buffer.seek(0, 0) |
|
94 input_buffer.flush() |
|
95 return self.get_results([X_SCRIPT] + self.options + self.filenames, |
|
96 input_buffer) |
88 |
97 |
89 def get_posttest_result(self): |
98 def get_posttest_result(self): |
90 if not self.posttest: |
99 if not self.posttest: |
91 return 0 |
100 return 0 |
92 self.write_script(self.posttest) |
101 self.write_script(self.posttest) |
137 return self.show_status('FAILED') |
146 return self.show_status('FAILED') |
138 return self.show_status('Passed') |
147 return self.show_status('Passed') |
139 |
148 |
140 def have_error_mismatch(self, status): |
149 def have_error_mismatch(self, status): |
141 if self.error and (status == 0): |
150 if self.error and (status == 0): |
142 return "x did not return expected error" |
151 return "dtrx did not return expected error" |
143 elif (not self.error) and (status != 0): |
152 elif (not self.error) and (status != 0): |
144 return "x returned error code %s" % (status,) |
153 return "dtrx returned error code %s" % (status,) |
145 return None |
154 return None |
146 |
155 |
147 def grep_output(self, output): |
156 def grep_output(self, output): |
148 if self.grep and (not re.search(self.grep, output)): |
157 if self.grep and (not re.search(self.grep, output)): |
149 return "output did not match %s" % (self.grep) |
158 return "output did not match %s" % (self.grep) |