add tdd script
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
__pycache__/
|
||||
tape.py
|
||||
test/
|
||||
pytest.ini
|
||||
website/
|
||||
@ -1,5 +1,4 @@
|
||||
import autopep8
|
||||
from yapf.yapflib.yapf_api import FormatCode
|
||||
import re
|
||||
import os
|
||||
files = os.listdir('snippets')
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import os
|
||||
import re
|
||||
codeRe = "```\s*python([\s\S]*?)```"
|
||||
def title_case(str):
|
||||
|
||||
22
scripts/tdd.py
Normal file
22
scripts/tdd.py
Normal file
@ -0,0 +1,22 @@
|
||||
import os,re
|
||||
|
||||
codeRe = "```\s*python([\s\S]*?)```"
|
||||
|
||||
snippets = [string.replace('.md','') for string in os.listdir('snippets')]
|
||||
|
||||
for snippet in snippets:
|
||||
os.makedirs('test/' + snippet,exist_ok=True)
|
||||
with open(f'snippets/{snippet}.md','r') as f:
|
||||
content = f.read()
|
||||
code = re.search(codeRe,content).group(1).strip()
|
||||
file_to_write_to = open(f'test/{snippet}/{snippet}.py','w')
|
||||
test_file = open(f'test/{snippet}/{snippet}_test.py','w')
|
||||
file_to_write_to.write(code)
|
||||
file_to_write_to.close()
|
||||
test_file.write(f'''
|
||||
import pytest,types,functools
|
||||
from {snippet} import {snippet}
|
||||
def {snippet}_test():
|
||||
assert isinstance({snippet}, (types.BuiltinFunctionType, types.FunctionType, functools.partial))
|
||||
'''.strip())
|
||||
test_file.close()
|
||||
Reference in New Issue
Block a user