Merge pull request #8187 from ethereum/fixWindowsExtractTests

Fix extract tests on windows.
This commit is contained in:
chriseth 2020-01-23 17:40:11 +01:00 committed by GitHub
commit 0e3a2fec66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -6,12 +6,12 @@ import subprocess
import json import json
SOLC_BIN = sys.argv[1] SOLC_BIN = sys.argv[1]
REPORT_FILE = open("report.txt", "w") REPORT_FILE = open("report.txt", mode="w", encoding='utf8')
for optimize in [False, True]: for optimize in [False, True]:
for f in sorted(glob.glob("*.sol")): for f in sorted(glob.glob("*.sol")):
sources = {} sources = {}
sources[f] = {'content': open(f, 'r').read()} sources[f] = {'content': open(f, mode='r', encoding='utf8').read()}
input_json = { input_json = {
'language': 'Solidity', 'language': 'Solidity',
'sources': sources, 'sources': sources,

View File

@ -10,7 +10,7 @@ import sys
import re import re
def extract_test_cases(_path): def extract_test_cases(_path):
lines = open(_path, 'rb').read().splitlines() lines = open(_path, mode='rb', encoding='utf8').read().splitlines()
inside = False inside = False
delimiter = '' delimiter = ''
@ -22,7 +22,7 @@ def extract_test_cases(_path):
for l in lines: for l in lines:
if inside: if inside:
if l.strip().endswith(')' + delimiter + '";'): if l.strip().endswith(')' + delimiter + '";'):
open('%03d_%s.sol' % (ctr, test_name), 'wb').write(test) open('%03d_%s.sol' % (ctr, test_name), mode='wb', encoding='utf8').write(test)
ctr += 1 ctr += 1
inside = False inside = False
test = '' test = ''

View File

@ -13,7 +13,7 @@ import hashlib
from os.path import join, isfile from os.path import join, isfile
def extract_test_cases(path): def extract_test_cases(path):
lines = open(path, 'r').read().splitlines() lines = open(path, mode='r', encoding='utf8').read().splitlines()
inside = False inside = False
delimiter = '' delimiter = ''
@ -43,7 +43,7 @@ def extract_docs_cases(path):
tests = [] tests = []
# Collect all snippets of indented blocks # Collect all snippets of indented blocks
for l in open(path, 'r').read().splitlines(): for l in open(path, mode='r', encoding='utf8').read().splitlines():
if l != '': if l != '':
if not inside and l.startswith(' '): if not inside and l.startswith(' '):
# start new test # start new test
@ -72,14 +72,14 @@ def write_cases(f, tests):
# so before checking remove 4 spaces from each line. # so before checking remove 4 spaces from each line.
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE) remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
sol_filename = 'test_%s_%s.sol' % (hashlib.sha256(test.encode("utf-8")).hexdigest(), cleaned_filename) sol_filename = 'test_%s_%s.sol' % (hashlib.sha256(test.encode("utf-8")).hexdigest(), cleaned_filename)
open(sol_filename, 'w').write(remainder) open(sol_filename, mode='w', encoding='utf8').write(remainder)
def extract_and_write(f, path): def extract_and_write(f, path):
if docs: if docs:
cases = extract_docs_cases(path) cases = extract_docs_cases(path)
else: else:
if f.endswith('.sol'): if f.endswith('.sol'):
cases = [open(path, 'r').read()] cases = [open(path, mode='r', encoding='utf8').read()]
else: else:
cases = extract_test_cases(path) cases = extract_test_cases(path)
write_cases(f, cases) write_cases(f, cases)

View File

@ -31,7 +31,7 @@ def writeSourceToFile(lines):
# print "filePath is", filePath # print "filePath is", filePath
if filePath != False: if filePath != False:
os.system("mkdir -p " + filePath) os.system("mkdir -p " + filePath)
f = open(srcName, 'a+') f = open(srcName, mode='a+', encoding='utf8')
createdSources.append(srcName) createdSources.append(srcName)
i = 0 i = 0
for idx, line in enumerate(lines[1:]): for idx, line in enumerate(lines[1:]):
@ -48,7 +48,7 @@ def writeSourceToFile(lines):
if __name__ == '__main__': if __name__ == '__main__':
filePath = sys.argv[1] filePath = sys.argv[1]
# decide if file has multiple sources # decide if file has multiple sources
lines = open(filePath, 'rb').read().splitlines() lines = open(filePath, mode='rb', encoding='utf8').read().splitlines()
if lines[0][:12] == "==== Source:": if lines[0][:12] == "==== Source:":
hasMultipleSources = True hasMultipleSources = True
writeSourceToFile(lines) writeSourceToFile(lines)