Skip to content
Snippets Groups Projects
Commit 3ded83e8 authored by roadscape's avatar roadscape
Browse files

add unit stub generator

parent 36504d8c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
grep -rn $1 * --color=always --exclude-dir=docs/hive --exclude-dir=hivemind.egg-info | grep -v __pycache__ --color=auto grep -rn $1 * --color=always --exclude-dir=docs/hive --exclude-dir=hivemind.egg-info | grep -v __pycache__ --color=auto
#!/usr/bin/env bash
if [ -z "$1" ] if [ -z "$1" ]
then then
pylint hive/**/*.py -f colorized -r n pylint hive/**/*.py -f colorized -r n
......
#!/usr/bin/env bash
python3 -m cProfile -s cumtime hive/cli.py > profile.out python3 -m cProfile -s cumtime hive/cli.py > profile.out
less profile.out less profile.out
#!/usr/bin/env python3
import sys
import re
def _generate(infile):
path = infile.replace('.py', '').split('/')
methods = []
stubs = []
for line in open(infile, 'r'):
if line[0:3] == 'def':
line = line.strip()
m = re.match(r'^def\s([^\(]+)\(([^\)]*)\):$', line)
assert m and m[1], "`%s` no match" % line
method = m[1]
args = m[2]
methods.append(method)
stub = "def test_%s():\n assert %s(%s) == expected" % (method, method, args)
stubs.append(stub)
outfile = open('tests/test_' + '_'.join(path[1:]) + '.py', 'w')
outfile.write("from %s import (\n" % '.'.join(path))
for method in methods:
outfile.write(" %s,\n" % method)
outfile.write(")\n")
outfile.write("\n" + "\n\n".join(stubs))
outfile.close()
if __name__ == '__main__':
_generate(sys.argv[1])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment