From 5f113bc7a9272c9917d3c701eb63a6b98005254f Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 3 Feb 2014 23:33:26 -0800 Subject: Issue #94: Include the sources element --- tests/farm/html/gold_x_xml/coverage.xml | 3 +++ tests/farm/html/gold_y_xml_branch/coverage.xml | 3 +++ tests/farm/html/run_a_xml_1.py | 1 + tests/farm/html/run_a_xml_2.py | 1 + tests/farm/html/run_y_xml_branch.py | 1 + tests/farm/html/src/coverage.xml | 3 +++ 6 files changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/farm/html/gold_x_xml/coverage.xml b/tests/farm/html/gold_x_xml/coverage.xml index 912112f2..d5a8c442 100644 --- a/tests/farm/html/gold_x_xml/coverage.xml +++ b/tests/farm/html/gold_x_xml/coverage.xml @@ -3,6 +3,9 @@ SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'> + + + diff --git a/tests/farm/html/gold_y_xml_branch/coverage.xml b/tests/farm/html/gold_y_xml_branch/coverage.xml index ecbe0073..86e9e73c 100644 --- a/tests/farm/html/gold_y_xml_branch/coverage.xml +++ b/tests/farm/html/gold_y_xml_branch/coverage.xml @@ -3,6 +3,9 @@ SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'> + + + diff --git a/tests/farm/html/run_a_xml_1.py b/tests/farm/html/run_a_xml_1.py index 3d187023..21d83d55 100644 --- a/tests/farm/html/run_a_xml_1.py +++ b/tests/farm/html/run_a_xml_1.py @@ -16,6 +16,7 @@ runfunc(html_it, rundir="src") compare("gold_x_xml", "xml_1", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), + (r'(.*)', ''), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_1") diff --git a/tests/farm/html/run_a_xml_2.py b/tests/farm/html/run_a_xml_2.py index 53691ead..e63e7ead 100644 --- a/tests/farm/html/run_a_xml_2.py +++ b/tests/farm/html/run_a_xml_2.py @@ -16,6 +16,7 @@ runfunc(html_it, rundir="src") compare("gold_x_xml", "xml_2", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), + (r'(.*)', ''), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_2") diff --git a/tests/farm/html/run_y_xml_branch.py b/tests/farm/html/run_y_xml_branch.py index 88a2e44e..ab8deef4 100644 --- a/tests/farm/html/run_y_xml_branch.py +++ b/tests/farm/html/run_y_xml_branch.py @@ -16,6 +16,7 @@ runfunc(xml_it, rundir="src") compare("gold_y_xml_branch", "xml_branch", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), + (r'(.*)', ''), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_branch") diff --git a/tests/farm/html/src/coverage.xml b/tests/farm/html/src/coverage.xml index 128cf750..e20cdaec 100644 --- a/tests/farm/html/src/coverage.xml +++ b/tests/farm/html/src/coverage.xml @@ -3,6 +3,9 @@ SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'> + + + -- cgit v1.2.1 From b45f28a29661a60b0a45efafd6e875ceb34146b7 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 4 Feb 2014 06:31:53 -0800 Subject: Test value inside element --- tests/farm/html/run_a_xml_1.py | 6 +++++- tests/farm/html/run_a_xml_2.py | 6 +++++- tests/farm/html/run_y_xml_branch.py | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/farm/html/run_a_xml_1.py b/tests/farm/html/run_a_xml_1.py index 21d83d55..8b5aa97b 100644 --- a/tests/farm/html/run_a_xml_1.py +++ b/tests/farm/html/run_a_xml_1.py @@ -1,3 +1,5 @@ +relative_path = None + def html_it(): """Run coverage and make an XML report for a.""" import coverage @@ -6,6 +8,8 @@ def html_it(): import a # pragma: nested cov.stop() # pragma: nested cov.xml_report(a, outfile="../xml_1/coverage.xml") + global relative_path + relative_path = cov.file_locator.relative_dir.rstrip('/') import os if not os.path.exists("xml_1"): @@ -16,7 +20,7 @@ runfunc(html_it, rundir="src") compare("gold_x_xml", "xml_1", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), - (r'(.*)', ''), + (r'', '%s' % relative_path), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_1") diff --git a/tests/farm/html/run_a_xml_2.py b/tests/farm/html/run_a_xml_2.py index e63e7ead..1d6b8394 100644 --- a/tests/farm/html/run_a_xml_2.py +++ b/tests/farm/html/run_a_xml_2.py @@ -1,3 +1,5 @@ +relative_path = None + def html_it(): """Run coverage and make an XML report for a.""" import coverage @@ -6,6 +8,8 @@ def html_it(): import a # pragma: nested cov.stop() # pragma: nested cov.xml_report(a) + global relative_path + relative_path = cov.file_locator.relative_dir.rstrip('/') import os if not os.path.exists("xml_2"): @@ -16,7 +20,7 @@ runfunc(html_it, rundir="src") compare("gold_x_xml", "xml_2", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), - (r'(.*)', ''), + (r'', '%s' % relative_path), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_2") diff --git a/tests/farm/html/run_y_xml_branch.py b/tests/farm/html/run_y_xml_branch.py index ab8deef4..b8feab64 100644 --- a/tests/farm/html/run_y_xml_branch.py +++ b/tests/farm/html/run_y_xml_branch.py @@ -1,3 +1,5 @@ +relative_path = None + def xml_it(): """Run coverage and make an XML report for y.""" import coverage @@ -6,6 +8,8 @@ def xml_it(): import y # pragma: nested cov.stop() # pragma: nested cov.xml_report(y, outfile="../xml_branch/coverage.xml") + global relative_path + relative_path = cov.file_locator.relative_dir.rstrip('/') import os if not os.path.exists("xml_branch"): @@ -16,7 +20,7 @@ runfunc(xml_it, rundir="src") compare("gold_y_xml_branch", "xml_branch", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), - (r'(.*)', ''), + (r'', '%s' % relative_path), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_branch") -- cgit v1.2.1 From 67dda6193ac439de034a6c1236800500be8c7193 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 25 Apr 2014 06:56:45 -0700 Subject: Update tests to handle XML whitespaces differences in Python 2.6. Apply the regexp scrubs to the entire file instead of individual lines for this to work. --- tests/farm/html/run_a_xml_1.py | 3 ++- tests/farm/html/run_a_xml_2.py | 3 ++- tests/farm/html/run_y_xml_branch.py | 3 ++- tests/test_farm.py | 19 ++++++++----------- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/farm/html/run_a_xml_1.py b/tests/farm/html/run_a_xml_1.py index 8b5aa97b..04fdfd4b 100644 --- a/tests/farm/html/run_a_xml_1.py +++ b/tests/farm/html/run_a_xml_1.py @@ -20,7 +20,8 @@ runfunc(html_it, rundir="src") compare("gold_x_xml", "xml_1", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), - (r'', '%s' % relative_path), + (r'(\s)*?(.*)(\s)*?', + '%s' % relative_path), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_1") diff --git a/tests/farm/html/run_a_xml_2.py b/tests/farm/html/run_a_xml_2.py index 1d6b8394..205ca453 100644 --- a/tests/farm/html/run_a_xml_2.py +++ b/tests/farm/html/run_a_xml_2.py @@ -20,7 +20,8 @@ runfunc(html_it, rundir="src") compare("gold_x_xml", "xml_2", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), - (r'', '%s' % relative_path), + (r'(\s)*?(.*)(\s)*?', + '%s' % relative_path), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_2") diff --git a/tests/farm/html/run_y_xml_branch.py b/tests/farm/html/run_y_xml_branch.py index b8feab64..18d7f7d9 100644 --- a/tests/farm/html/run_y_xml_branch.py +++ b/tests/farm/html/run_y_xml_branch.py @@ -20,7 +20,8 @@ runfunc(xml_it, rundir="src") compare("gold_y_xml_branch", "xml_branch", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), - (r'', '%s' % relative_path), + (r'(\s)*?(.*)(\s)*?', + '%s' % relative_path), (r'/code/coverage/?[-.\w]*', '/code/coverage/VER'), ]) clean("xml_branch") diff --git a/tests/test_farm.py b/tests/test_farm.py index c86983e5..65016b34 100644 --- a/tests/test_farm.py +++ b/tests/test_farm.py @@ -256,8 +256,8 @@ class FarmTestCase(object): # ourselves. text_diff = [] for f in diff_files: - left = open(os.path.join(dir1, f), "rU").readlines() - right = open(os.path.join(dir2, f), "rU").readlines() + left = open(os.path.join(dir1, f), "rU").read() + right = open(os.path.join(dir2, f), "rU").read() if scrubs: left = self._scrub(left, scrubs) right = self._scrub(right, scrubs) @@ -271,19 +271,16 @@ class FarmTestCase(object): if not right_extra: assert not right_only, "Files in %s only: %s" % (dir2, right_only) - def _scrub(self, strlist, scrubs): - """Scrub uninteresting data from the strings in `strlist`. + def _scrub(self, strdata, scrubs): + """Scrub uninteresting data from the payload in `strdata`. `scrubs is a list of (find, replace) pairs of regexes that are used on - each string in `strlist`. A list of scrubbed strings is returned. + `strdata`. A string is returned. """ - scrubbed = [] - for s in strlist: - for rgx_find, rgx_replace in scrubs: - s = re.sub(rgx_find, rgx_replace, s) - scrubbed.append(s) - return scrubbed + for rgx_find, rgx_replace in scrubs: + strdata = re.sub(rgx_find, rgx_replace, strdata) + return strdata def contains(self, filename, *strlist): """Check that the file contains all of a list of strings. -- cgit v1.2.1