Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Use io.open in approvalTests.py regardless of Python version

Both Python 2.7 and 3.x support full-featured io.open, so we
can avoid using a polyfill over this.
Commit
375f2052bde3236953905021a52eabe073dac0a6
Author
Martin Hořeňovský ·
Parents
dc6b83bec9bd

Files · Download .tar.gz

Changes

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

diff --git a/scripts/approvalTests.py b/scripts/approvalTests.py
index 16cc7b7d..ee6a8f15 100755
--- a/scripts/approvalTests.py
+++ b/scripts/approvalTests.py
@@ -2,6 +2,7 @@
 
 from  __future__ import print_function
 
+import io
 import os
 import sys
 import subprocess
@@ -72,17 +73,11 @@ else:
 
 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 openFile(fileA, 'r') as file:
+    with io.open(fileA, 'r', encoding='utf-8', errors='surrogateescape') as file:
         aLines = [line.rstrip() for line in file.readlines()]
-    with openFile(fileB, 'r') as file:
+    with io.open(fileB, 'r', encoding='utf-8', errors='surrogateescape') as file:
         bLines = [line.rstrip() for line in file.readlines()]
 
     shortenedFilenameA = fileA.rsplit(os.sep, 1)[-1]
@@ -146,8 +141,8 @@ def approve(baseName, args):
     subprocess.call(args, stdout=f, stderr=f)
     f.close()
 
-    rawFile = openFile(rawResultsPath, 'r')
-    filteredFile = openFile(filteredResultsPath, 'w')
+    rawFile = io.open(rawResultsPath, 'r', encoding='utf-8', errors='surrogateescape')
+    filteredFile = io.open(filteredResultsPath, 'w', encoding='utf-8', errors='surrogateescape')
     for line in rawFile:
         filteredFile.write(filterLine(line).rstrip() + "\n")
     filteredFile.close()