Merge pull request #4434 from mattaereal/patch-4

Update isolate_tests.py
This commit is contained in:
chriseth 2018-07-09 22:47:34 +02:00 committed by GitHub
commit f6edb7fb8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ import sys
import re
import os
import hashlib
from os.path import join
from os.path import join, isfile
def extract_test_cases(path):
lines = open(path, 'rb').read().splitlines()
@ -77,12 +77,26 @@ def write_cases(tests):
for test in tests:
open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test)
def extract_and_write(f, path):
if docs:
cases = extract_docs_cases(path)
else:
if f.endswith('.sol'):
cases = [open(path, 'r').read()]
else:
cases = extract_test_cases(path)
write_cases(cases)
if __name__ == '__main__':
path = sys.argv[1]
docs = False
if len(sys.argv) > 2 and sys.argv[2] == 'docs':
docs = True
if isfile(path):
extract_and_write(path, path)
else:
for root, subdirs, files in os.walk(path):
if '_build' in subdirs:
subdirs.remove('_build')
@ -90,11 +104,4 @@ if __name__ == '__main__':
subdirs.remove('compilationTests')
for f in files:
path = join(root, f)
if docs:
cases = extract_docs_cases(path)
else:
if f.endswith(".sol"):
cases = [open(path, "r").read()]
else:
cases = extract_test_cases(path)
write_cases(cases)
extract_and_write(f, path)