mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský