[GRASS-SVN] r60992 - in sandbox/wenzeslaus/gunittest: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 26 13:28:04 PDT 2014
Author: wenzeslaus
Date: 2014-06-26 13:28:04 -0700 (Thu, 26 Jun 2014)
New Revision: 60992
Modified:
sandbox/wenzeslaus/gunittest/checkers.py
sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
Log:
gunittest: improve handling of multiline strings in comparison with ellipsis
Modified: sandbox/wenzeslaus/gunittest/checkers.py
===================================================================
--- sandbox/wenzeslaus/gunittest/checkers.py 2014-06-26 20:26:14 UTC (rev 60991)
+++ sandbox/wenzeslaus/gunittest/checkers.py 2014-06-26 20:28:04 UTC (rev 60992)
@@ -385,9 +385,15 @@
key_equal=key_equal)
+# TODO: support also float (with E, e, inf, nan, ...?) and int (###, ##.)
+# http://hg.python.org/cpython/file/943d3e289ab4/Lib/decimal.py#l6098
+# perhaps a separate function?
# alternative names: looks like, correspond with/to
+# TODO: change checking over lines?
+# TODO: change parameter order?
+# TODO: the behavior with last \n is strange but now using DOTALL and $
def check_text_ellipsis(reference, actual):
- """
+ r"""
>>> check_text_ellipsis("Vector map <...> contains ... points.",
... "Vector map <bridges> contains 5268 points.")
True
@@ -395,7 +401,7 @@
... "user: some_user\\nname: elevation")
True
>>> check_text_ellipsis("user: ...\\nname: elevation",
- ... "user: \\nname: elevation",)
+ ... "user: \\nname: elevation")
False
The ellipsis is always considered even if it is followed by another
@@ -403,30 +409,34 @@
ellipsis will work as well as a line filled with undefined number of dots.
>>> check_text_ellipsis("The result is ....",
- ... "The result is 25.",)
+ ... "The result is 25.")
True
>>> check_text_ellipsis("max ..... ...",
- ... "max ....... 6",)
+ ... "max ....... 6")
True
However, there is no way how to express that the dot should be in the
beginning and the ellipsis is at the end of the group of dots.
>>> check_text_ellipsis("The result is ....",
- ... "The result is .25",)
+ ... "The result is .25")
False
+ The matching goes over lines (TODO: should this be changed?):
+ >>> check_text_ellipsis("a=11\nb=...", "a=11\nb=22\n")
+ True
+
This function is based on regular expression containg .+ but no other
regular expression matching will be done.
>>> check_text_ellipsis("Result: [569] (...)",
- ... "Result: 9 (too high)",)
+ ... "Result: 9 (too high)")
False
"""
ref_escaped = re.escape(reference)
exp = re.compile(r'\\\.\\\.\\\.') # matching escaped ...
- ref_regexp = exp.sub('.+', ref_escaped)
- if re.match(ref_regexp, actual):
+ ref_regexp = exp.sub('.+', ref_escaped) + "$"
+ if re.match(ref_regexp, actual, re.DOTALL):
return True
else:
return False
Modified: sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py
===================================================================
--- sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py 2014-06-26 20:26:14 UTC (rev 60991)
+++ sandbox/wenzeslaus/gunittest/testsuite/test_assertions.py 2014-06-26 20:28:04 UTC (rev 60992)
@@ -22,6 +22,10 @@
self.assertLooksLike,
"Generated map is elevation.",
"Generated map is <...>")
+ self.assertLooksLike("Projection string: '+proj=longlat +datum=WGS84'",
+ "Projection string: ...")
+ self.assertLooksLike("a=123\nb=456\nc=789",
+ "a=...\nb=...\nc=...")
R_UNIVAR_ELEVATION_SUBSET = """n=2025000
More information about the grass-commit
mailing list