mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Change isolate_tests to support single files as an input
On the documentation the examples for the usage of isolate_tests.py are shown with single files, and it's currently not working. It only works for folders or wildcards that return more than one file, since that's how os.walk works within a loop for that cases. Proposed an simple and easy fix. I extracted the core functionality for extracting tests from files, and made another function called `extract_and_write` If the program receives a single file the function `extract_and_write` is called once, it even works for `docs` when specified. If the program receives a path or a wildcard, works as used to.
This commit is contained in:
parent
7101a89056
commit
1ebeb7e588
@ -10,7 +10,7 @@ import sys
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
from os.path import join
|
from os.path import join, isfile
|
||||||
|
|
||||||
def extract_test_cases(path):
|
def extract_test_cases(path):
|
||||||
lines = open(path, 'rb').read().splitlines()
|
lines = open(path, 'rb').read().splitlines()
|
||||||
@ -77,19 +77,8 @@ def write_cases(tests):
|
|||||||
for test in tests:
|
for test in tests:
|
||||||
open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test)
|
open('test_%s.sol' % hashlib.sha256(test).hexdigest(), 'wb').write(test)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
path = sys.argv[1]
|
|
||||||
docs = False
|
|
||||||
if len(sys.argv) > 2 and sys.argv[2] == 'docs':
|
|
||||||
docs = True
|
|
||||||
|
|
||||||
for root, subdirs, files in os.walk(path):
|
def extract_and_write(f, path):
|
||||||
if '_build' in subdirs:
|
|
||||||
subdirs.remove('_build')
|
|
||||||
if 'compilationTests' in subdirs:
|
|
||||||
subdirs.remove('compilationTests')
|
|
||||||
for f in files:
|
|
||||||
path = join(root, f)
|
|
||||||
if docs:
|
if docs:
|
||||||
cases = extract_docs_cases(path)
|
cases = extract_docs_cases(path)
|
||||||
else:
|
else:
|
||||||
@ -98,3 +87,21 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
cases = extract_test_cases(path)
|
cases = extract_test_cases(path)
|
||||||
write_cases(cases)
|
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')
|
||||||
|
if 'compilationTests' in subdirs:
|
||||||
|
subdirs.remove('compilationTests')
|
||||||
|
for f in files:
|
||||||
|
path = join(root, f)
|
||||||
|
extract_and_write(f, path)
|
||||||
|
Loading…
Reference in New Issue
Block a user