summaryrefslogtreecommitdiff
blob: 0712f15770777fefa0e92ac3762cf91341ee9680 (plain)
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
From dc6b83bec9bdcc149db08711cc9dfd555a8620fa Mon Sep 17 00:00:00 2001
From: Tom Hughes <tom@compton.nu>
Date: Fri, 6 Apr 2018 13:59:08 +0100
Subject: [PATCH] Support Python3 in approval tests

---
 scripts/approvalTests.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/scripts/approvalTests.py b/scripts/approvalTests.py
index a2ab5d5a2..16cc7b7d2 100755
--- a/scripts/approvalTests.py
+++ b/scripts/approvalTests.py
@@ -72,10 +72,17 @@
 
 overallResult = 0
 
+def openFile(file, mode):
+    try:
+        return open(file, mode, encoding='utf-8', errors='surrogateescape')
+    except TypeError:
+        import io
+        return io.open(file, mode, encoding='utf-8', errors='surrogateescape')
+
 def diffFiles(fileA, fileB):
-    with open(fileA, 'r') as file:
+    with openFile(fileA, 'r') as file:
         aLines = [line.rstrip() for line in file.readlines()]
-    with open(fileB, 'r') as file:
+    with openFile(fileB, 'r') as file:
         bLines = [line.rstrip() for line in file.readlines()]
 
     shortenedFilenameA = fileA.rsplit(os.sep, 1)[-1]
@@ -139,8 +146,8 @@ def approve(baseName, args):
     subprocess.call(args, stdout=f, stderr=f)
     f.close()
 
-    rawFile = open(rawResultsPath, 'r')
-    filteredFile = open(filteredResultsPath, 'w')
+    rawFile = openFile(rawResultsPath, 'r')
+    filteredFile = openFile(filteredResultsPath, 'w')
     for line in rawFile:
         filteredFile.write(filterLine(line).rstrip() + "\n")
     filteredFile.close()