1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
From: chrysn <chrysn@fsfe.org>
Date: Thu, 4 Jun 2015 21:17:27 +0200
Subject: add float normalization to test_cmdline_tool
this helps removing the need for OPENSCAD_TESTING
---
tests/test_cmdline_tool.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tests/test_cmdline_tool.py b/tests/test_cmdline_tool.py
index a750bb4..1d6fe9a 100755
--- a/tests/test_cmdline_tool.py
+++ b/tests/test_cmdline_tool.py
@@ -94,12 +94,38 @@ def execute_and_redirect(cmd, params, outfile):
if outfile == subprocess.PIPE: return (retval, out)
else: return retval
+def normalize_string(s):
+ """Apply all modifications to an output string which would have been
+ applied if OPENSCAD_TESTING was defined at build time of the executable.
+
+ This truncates all floats, removes ', timestamp = ...' parts. The function
+ is idempotent.
+
+ This also normalizes away import paths from 'file = ' arguments."""
+
+ s = re.sub(', timestamp = [0-9]+', '', s)
+ def floatrep(match):
+ value = float(match.groups()[0])
+ if abs(value) < 10**-12:
+ return "0"
+ if abs(value) >= 10**6:
+ return "%d"%value
+ return "%.6g"%value
+ s = re.sub('(-?[0-9]+\\.[0-9]+(e[+-][0-9]+)?)', floatrep, s)
+
+ def pathrep(match):
+ return match.groups()[0] + match.groups()[2]
+ s = re.sub('(file = ")([^"/]*/)*([^"]*")', pathrep, s)
+
+ return s
+
def get_normalized_text(filename):
try:
f = open(filename)
text = f.read()
except:
text = ''
+ text = normalize_string(text)
return text.strip("\r\n").replace("\r\n", "\n") + "\n"
def compare_text(expected, actual):
|