diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-12-22 14:52:42 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-12-22 14:52:42 +0000 |
commit | c14fea9f9b3f7ad194b175541c99ee09c7d88d2e (patch) | |
tree | c1c8d136815be3b4a1425a6239f130ff77704336 /tko/parsers | |
parent | 64e766b481c4861b422485a607eefe948a3562a3 (diff) |
Add a helper function for comparing results in the store.
Signed-off-by: Cary Hull <chull@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@2585 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko/parsers')
-rw-r--r-- | tko/parsers/test/execute_parser.py | 2 | ||||
-rw-r--r-- | tko/parsers/test/inspect_parser_result_store.py | 12 | ||||
-rw-r--r-- | tko/parsers/test/scenario_base.py | 34 |
3 files changed, 47 insertions, 1 deletions
diff --git a/tko/parsers/test/execute_parser.py b/tko/parsers/test/execute_parser.py index 518d82b2..fb703f08 100644 --- a/tko/parsers/test/execute_parser.py +++ b/tko/parsers/test/execute_parser.py @@ -25,7 +25,7 @@ def main(): parser.print_help() sys.exit(1) - sto = scenario_base.load_parser_result_store(scenario_dirpath, 'c') + sto = scenario_base.load_parser_result_store(scenario_dirpath, True) results_dirpath = scenario_base.load_results_dir(scenario_dirpath) harness = scenario_base.new_parser_harness(results_dirpath) try: diff --git a/tko/parsers/test/inspect_parser_result_store.py b/tko/parsers/test/inspect_parser_result_store.py index 1887bb21..25af35d1 100644 --- a/tko/parsers/test/inspect_parser_result_store.py +++ b/tko/parsers/test/inspect_parser_result_store.py @@ -28,3 +28,15 @@ if not path.exists(scenario_dirpath) or not path.isdir(scenario_dirpath): sto = scenario_base.load_parser_result_store( scenario_dirpath, options.open_for_write) + + +def compare(left_tag, right_tag): + missing = set([left_tag, right_tag]).difference(sto.keys()) + if missing: + print 'Store does not have the following tag(s): ', ','.join(missing) + print 'Doing nothing.' + return + + for diffline in scenario_base.compare_parser_results( + sto[left_tag], sto[right_tag]): + print diffline diff --git a/tko/parsers/test/scenario_base.py b/tko/parsers/test/scenario_base.py index 9ad0da62..5947f933 100644 --- a/tko/parsers/test/scenario_base.py +++ b/tko/parsers/test/scenario_base.py @@ -3,6 +3,7 @@ from os import path import ConfigParser, os, shelve, shutil, sys, tarfile, tempfile, time +import difflib, itertools import common from autotest_lib.client.common_lib import utils from autotest_lib.tko import status_lib @@ -69,6 +70,12 @@ class ParserException(object): return self.__dict__ != other.__dict__ + def __str__(self): + sd = self.__dict__ + pairs = ['%s="%s"' % (k, sd[k]) for k in sorted(sd.keys())] + return "<%s: %s>" % (self.classname, ', '.join(pairs)) + + class ParserTestResult(object): """Abstract representation of test result parser state. @@ -105,6 +112,12 @@ class ParserTestResult(object): return self.__dict__ != other.__dict__ + def __str__(self): + sd = self.__dict__ + pairs = ['%s="%s"' % (k, sd[k]) for k in sorted(sd.keys())] + return "<%s: %s>" % (self.__class__.__name__, ', '.join(pairs)) + + def copy_parser_result(parser_result): """Copy parser_result into ParserTestResult instances. @@ -130,6 +143,27 @@ def copy_parser_result(parser_result): raise UnsupportedParserResultError +def compare_parser_results(left, right): + """Generates a textual report (for now) on the differences between. + + Args: + left: list of ParserTestResults or a single ParserException + right: list of ParserTestResults or a single ParserException + + Returns: Generator returned from difflib.Differ().compare() + """ + def to_los(obj): + """Generate a list of strings representation of object.""" + if type(obj) is list: + return [ + '%d) %s' % pair + for pair in itertools.izip(itertools.count(), obj)] + else: + return ['i) %s' % obj] + + return difflib.Differ().compare(to_los(left), to_los(right)) + + class ParserHarness(object): """Harness for objects related to the parser. |