File: add-float-normalization-to-test_cmdline_tool.patch

package info (click to toggle)
openscad 2015.03-2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 30,804 kB
  • ctags: 5,692
  • sloc: cpp: 39,386; sh: 3,856; ansic: 3,674; python: 1,393; yacc: 496; lex: 272; lisp: 159; makefile: 67; xml: 60
file content (52 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download
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):