aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMatías A. Ré Medina <aereal@gmail.com>2018-07-05 08:20:17 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-07-09 18:28:09 +0800
commit1ebeb7e588a95a7ef57937d26752e0fbad606d20 (patch)
treef9d6e4f0764b47dca79214156ffd91d94f8374bf /scripts
parent7101a8905656d52cf9023a2e4340219d184920c3 (diff)
downloaddexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.tar
dexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.tar.gz
dexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.tar.bz2
dexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.tar.lz
dexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.tar.xz
dexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.tar.zst
dexon-solidity-1ebeb7e588a95a7ef57937d26752e0fbad606d20.zip
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.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/isolate_tests.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py
index 82dff1e0..352a2fde 100755
--- a/scripts/isolate_tests.py
+++ b/scripts/isolate_tests.py
@@ -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,24 +77,31 @@ 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
- 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)
- 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 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)