Skip to content

Commit

Permalink
validate: launcher: Separate Reporter from current Test
Browse files Browse the repository at this point in the history
Instead of saving the current Test in Reporter for every test, use
function parameters to achieve the same goal.

Patch 2/5 to move logfile handling out of Reporter and into Test.
  • Loading branch information
Ramiro Polla authored and tsaunier committed Feb 5, 2015
1 parent 39a4092 commit b9357e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion validate/launcher/baseclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def run_tests(self, cur_test_num, total_num_tests):
self.reporter.before_test(test)
res = test.run()
i += 1
self.reporter.after_test()
self.reporter.after_test(test)
if res != Result.PASSED and (self.options.forever or
self.options.fatal_error):
return test.result
Expand Down
22 changes: 9 additions & 13 deletions validate/launcher/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class Reporter(Loggable):
def __init__(self, options):
Loggable.__init__(self)

self._current_test = None
self.out = None
self.options = options
self._start_time = 0
Expand All @@ -82,7 +81,6 @@ def before_test(self, test):
self.out = sys.stderr
else:
self.out = open(path, 'w+')
self._current_test = test

def set_failed(self, test):
self.stats["failure"] += 1
Expand All @@ -100,16 +98,15 @@ def add_results(self, test):
else:
raise UnknownResult("%s" % test.result)

def after_test(self):
if self._current_test not in self.results:
self.results.append(self._current_test)
def after_test(self, test):
if test not in self.results:
self.results.append(test)

self.add_results(self._current_test)
self.add_results(test)
if not self.options.redirect_logs:
self.out.close()

self.out = None
self._current_test = None

def final_report(self):
print "\n"
Expand Down Expand Up @@ -158,19 +155,18 @@ def final_report(self):
self.report()
super(XunitReporter, self).final_report()

def _get_captured(self):
def _get_captured(self, test):
captured = ""
if self.out and not self.options.redirect_logs:
self.out.seek(0)
value = self.out.read()
if value:
captured += '<system-out><![CDATA[%s' % \
escape_cdata(value)

for extralog in self._current_test.extra_logfiles:
for extralog in test.extra_logfiles:
captured += "\n\n===== %s =====\n\n" % escape_cdata(
os.path.basename(extralog))
value = self._current_test.get_extra_log_content(extralog)
value = test.get_extra_log_content(extralog)
captured += escape_cdata(value)

captured += "]]></system-out>"
Expand Down Expand Up @@ -218,7 +214,7 @@ def set_failed(self, test):
'taken': test.time_taken,
'errtype': self._quoteattr(test.result),
'message': self._quoteattr(test.message),
'systemout': self._get_captured(),
'systemout': self._get_captured(test),
})

def set_passed(self, test):
Expand All @@ -231,7 +227,7 @@ def set_passed(self, test):
{'cls': self._quoteattr(test.get_classname()),
'name': self._quoteattr(test.get_name()),
'taken': test.time_taken,
'systemout': self._get_captured(),
'systemout': self._get_captured(test),
})

def _forceUnicode(self, s):
Expand Down

1 comment on commit b9357e3

@thiblahute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Please sign in to comment.