lang-model/naive-nlu/tree_nlu/test.py

48 lines
1.2 KiB
Python

import traceback
import logging
import datetime
from .session import org_mode
from .tests import basic
from .tests import gac_100
from .tests import gac_extension
logging.getLogger().setLevel(logging.ERROR)
tests = (
("basic", basic),
("gac 100", gac_100),
("gac+", gac_extension),
)
def gen_session_name():
now = datetime.datetime.utcnow()
return "treeNLU-test-session-{}.org".format(
now.strftime("%y_%m_%d %H:%M:%S_%f"))
def main():
org_mode.create_global_session(gen_session_name())
failed = False
for test_name, test_module in tests:
try:
test_module.main()
print(" \x1b[1;32m✓\x1b[0m {}".format(test_name))
except AssertionError as ae:
print(" \x1b[1;31m✗\x1b[0m {}{}".format(test_name,
('\n [Assertion] {}'.format(ae.args[0])) if len(ae.args) > 0
else ''))
failed = True
except Exception as e:
print(" \x1b[1;7;31m!\x1b[0m {}\n [Exception] {}".format(test_name, e))
failed = True
traceback.print_exc()
raise
if failed:
exit(1)
if __name__ == '__main__':
main()