|
@@ -7,7 +7,11 @@ from datetime import datetime
|
|
import orjson
|
|
import orjson
|
|
import os
|
|
import os
|
|
import tempfile
|
|
import tempfile
|
|
-from tests_config import sql_parser_tests, sql_checker_tests
|
|
|
|
|
|
+import tests_config
|
|
|
|
+import importlib
|
|
|
|
+importlib.reload(tests_config)
|
|
|
|
+
|
|
|
|
+sql_parser_tests, sql_checker_tests = tests_config.sql_parser_tests, tests_config.sql_checker_tests
|
|
|
|
|
|
|
|
|
|
async def run_and_output(
|
|
async def run_and_output(
|
|
@@ -75,32 +79,33 @@ async def on_parser_modified():
|
|
print(datetime.now(), colored("all parser tests right!", "green"))
|
|
print(datetime.now(), colored("all parser tests right!", "green"))
|
|
|
|
|
|
|
|
|
|
-async def assert_check():
|
|
|
|
|
|
+async def assert_checks():
|
|
for sql, res in sql_checker_tests:
|
|
for sql, res in sql_checker_tests:
|
|
stdout, stderr = await run_and_output(
|
|
stdout, stderr = await run_and_output(
|
|
'xmake', 'run', "sql-checker",
|
|
'xmake', 'run', "sql-checker",
|
|
"-s", sql
|
|
"-s", sql
|
|
)
|
|
)
|
|
|
|
+ print(sql, res)
|
|
if res is True:
|
|
if res is True:
|
|
assert b'error' not in stdout, stdout.decode("utf-8")
|
|
assert b'error' not in stdout, stdout.decode("utf-8")
|
|
assert b'error' not in stderr, stderr.decode('utf-8')
|
|
assert b'error' not in stderr, stderr.decode('utf-8')
|
|
elif isinstance(res, str):
|
|
elif isinstance(res, str):
|
|
res = res.encode('utf-8')
|
|
res = res.encode('utf-8')
|
|
- assert res in stdout or res in stderr, stdout.decode("utf-8")
|
|
|
|
|
|
+ assert res in stderr, stderr.decode("utf-8")
|
|
else:
|
|
else:
|
|
assert False, f"{res} 不是合适的结果"
|
|
assert False, f"{res} 不是合适的结果"
|
|
|
|
|
|
async def on_checker_modified():
|
|
async def on_checker_modified():
|
|
print(datetime.now(), colored("run checker tests...", "yellow"))
|
|
print(datetime.now(), colored("run checker tests...", "yellow"))
|
|
try:
|
|
try:
|
|
- await assert_check()
|
|
|
|
|
|
+ await assert_checks()
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
print(datetime.now(), colored("all checker tests right!", "green"))
|
|
print(datetime.now(), colored("all checker tests right!", "green"))
|
|
|
|
|
|
|
|
|
|
async def restart():
|
|
async def restart():
|
|
- async for _ in awatch(__file__):
|
|
|
|
|
|
+ async for _ in awatch(__file__, "./tests_config.py"):
|
|
print("restart")
|
|
print("restart")
|
|
os.execl("/bin/python", Path(__file__).as_posix(), Path(__file__).as_posix())
|
|
os.execl("/bin/python", Path(__file__).as_posix(), Path(__file__).as_posix())
|
|
|
|
|