mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix extract tests on windows.
This commit is contained in:
parent
3add37a2c9
commit
8f36dd1571
@ -6,12 +6,12 @@ import subprocess
|
||||
import json
|
||||
|
||||
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 f in sorted(glob.glob("*.sol")):
|
||||
sources = {}
|
||||
sources[f] = {'content': open(f, 'r').read()}
|
||||
sources[f] = {'content': open(f, mode='r', encoding='utf8').read()}
|
||||
input_json = {
|
||||
'language': 'Solidity',
|
||||
'sources': sources,
|
||||
|
@ -10,7 +10,7 @@ import sys
|
||||
import re
|
||||
|
||||
def extract_test_cases(_path):
|
||||
lines = open(_path, 'rb').read().splitlines()
|
||||
lines = open(_path, mode='rb', encoding='utf8').read().splitlines()
|
||||
|
||||
inside = False
|
||||
delimiter = ''
|
||||
@ -22,7 +22,7 @@ def extract_test_cases(_path):
|
||||
for l in lines:
|
||||
if inside:
|
||||
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
|
||||
inside = False
|
||||
test = ''
|
||||
|
@ -13,7 +13,7 @@ import hashlib
|
||||
from os.path import join, isfile
|
||||
|
||||
def extract_test_cases(path):
|
||||
lines = open(path, 'r').read().splitlines()
|
||||
lines = open(path, mode='r', encoding='utf8').read().splitlines()
|
||||
|
||||
inside = False
|
||||
delimiter = ''
|
||||
@ -43,7 +43,7 @@ def extract_docs_cases(path):
|
||||
tests = []
|
||||
|
||||
# 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 not inside and l.startswith(' '):
|
||||
# start new test
|
||||
@ -72,14 +72,14 @@ def write_cases(f, tests):
|
||||
# so before checking remove 4 spaces from each line.
|
||||
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
|
||||
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):
|
||||
if docs:
|
||||
cases = extract_docs_cases(path)
|
||||
else:
|
||||
if f.endswith('.sol'):
|
||||
cases = [open(path, 'r').read()]
|
||||
cases = [open(path, mode='r', encoding='utf8').read()]
|
||||
else:
|
||||
cases = extract_test_cases(path)
|
||||
write_cases(f, cases)
|
||||
|
@ -31,7 +31,7 @@ def writeSourceToFile(lines):
|
||||
# print "filePath is", filePath
|
||||
if filePath != False:
|
||||
os.system("mkdir -p " + filePath)
|
||||
f = open(srcName, 'a+')
|
||||
f = open(srcName, mode='a+', encoding='utf8')
|
||||
createdSources.append(srcName)
|
||||
i = 0
|
||||
for idx, line in enumerate(lines[1:]):
|
||||
@ -48,7 +48,7 @@ def writeSourceToFile(lines):
|
||||
if __name__ == '__main__':
|
||||
filePath = sys.argv[1]
|
||||
# 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:":
|
||||
hasMultipleSources = True
|
||||
writeSourceToFile(lines)
|
||||
|
Loading…
Reference in New Issue
Block a user