automatic regressive testing
This commit is contained in:
parent
3879263121
commit
5017ce2736
@ -1,4 +1,4 @@
|
|||||||
from trace_commentor import Commentor
|
from test_utils import *
|
||||||
|
|
||||||
|
|
||||||
def test_function_def():
|
def test_function_def():
|
||||||
@ -6,5 +6,8 @@ def test_function_def():
|
|||||||
@Commentor()
|
@Commentor()
|
||||||
def target():
|
def target():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print(target())
|
asserteq_or_print(target(), '''
|
||||||
|
def target():
|
||||||
|
pass
|
||||||
|
''')
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from trace_commentor import Commentor
|
from trace_commentor import Commentor
|
||||||
|
from test_utils import asserteq_or_print
|
||||||
|
|
||||||
|
|
||||||
def test_binop():
|
def test_binop():
|
||||||
@ -6,5 +7,29 @@ def test_binop():
|
|||||||
@Commentor()
|
@Commentor()
|
||||||
def target():
|
def target():
|
||||||
1 + 1
|
1 + 1
|
||||||
|
|
||||||
print(target())
|
asserteq_or_print(
|
||||||
|
target(), '''
|
||||||
|
def target():
|
||||||
|
1 + 1
|
||||||
|
"""
|
||||||
|
2 : 1 + 1
|
||||||
|
"""
|
||||||
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
def test_binop_cascade():
|
||||||
|
|
||||||
|
@Commentor()
|
||||||
|
def target():
|
||||||
|
1 + 1 + 1
|
||||||
|
|
||||||
|
asserteq_or_print(
|
||||||
|
target(), '''
|
||||||
|
def target():
|
||||||
|
1 + 1 + 1
|
||||||
|
"""
|
||||||
|
2 : 1 + 1
|
||||||
|
3 : 1 + 1 + 1
|
||||||
|
"""
|
||||||
|
''')
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from trace_commentor import Commentor
|
from test_utils import *
|
||||||
|
|
||||||
|
|
||||||
def test_constant():
|
def test_constant():
|
||||||
@ -7,4 +7,8 @@ def test_constant():
|
|||||||
def target():
|
def target():
|
||||||
1
|
1
|
||||||
|
|
||||||
print(target())
|
asserteq_or_print(target(),
|
||||||
|
'''
|
||||||
|
def target():
|
||||||
|
1
|
||||||
|
''')
|
||||||
|
|||||||
7
tests/test_utils.py
Normal file
7
tests/test_utils.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from trace_commentor import flags, Commentor
|
||||||
|
|
||||||
|
def asserteq_or_print(value, ground_truth):
|
||||||
|
if flags.DEBUG or flags.PRINT:
|
||||||
|
print(value)
|
||||||
|
else:
|
||||||
|
assert value == ground_truth.strip("\n"), "\n".join(["\n\n<<<<<<<< VALUE", value, "========================", ground_truth.strip("\n"), ">>>>>>>> GROUND\n"])
|
||||||
@ -1,4 +1,9 @@
|
|||||||
DEBUG = False
|
import os
|
||||||
|
|
||||||
|
bool_env = lambda name: os.environ.get(name, "false").lower() in ('true', '1', 'yes')
|
||||||
|
|
||||||
|
DEBUG = bool_env("DEBUG")
|
||||||
|
PRINT = bool_env("PRINT")
|
||||||
INDENT = 4
|
INDENT = 4
|
||||||
SOURCE = 1
|
SOURCE = 1
|
||||||
COMMENT = 2
|
COMMENT = 2
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from .. import flags
|
|||||||
from ..utils import to_source
|
from ..utils import to_source
|
||||||
|
|
||||||
def FunctionDef(self, cmtor):
|
def FunctionDef(self, cmtor):
|
||||||
cmtor.append_source("def function():")
|
cmtor.append_source(f"def {self.name}():")
|
||||||
cmtor.indent += flags.INDENT
|
cmtor.indent += flags.INDENT
|
||||||
|
|
||||||
for stmt in self.body:
|
for stmt in self.body:
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
def Pass(self, cmtor):
|
def Pass(self, cmtor):
|
||||||
cmtor.append("pass")
|
pass
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import astor
|
import astor
|
||||||
import inspect
|
import inspect
|
||||||
from . import flags
|
from . import flags
|
||||||
@ -5,8 +6,8 @@ from . import flags
|
|||||||
def sign(line: str, depth=1):
|
def sign(line: str, depth=1):
|
||||||
if flags.DEBUG:
|
if flags.DEBUG:
|
||||||
currentframe = inspect.currentframe()
|
currentframe = inspect.currentframe()
|
||||||
outerframe = inspect.getouterframes(currentframe, depth)
|
outerframe = inspect.getouterframes(currentframe, 1)[depth]
|
||||||
debug_msg = outerframe[1][3]
|
debug_msg = f"{outerframe.function} @ {os.path.relpath(outerframe.filename)}:{outerframe.lineno}"
|
||||||
return f"{line} --- {debug_msg}"
|
return f"{line} --- {debug_msg}"
|
||||||
else:
|
else:
|
||||||
return line
|
return line
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user