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

48 lines
1.2 KiB
Python
Raw Normal View History

import traceback
2017-05-23 19:04:10 +02:00
import logging
2017-09-30 01:32:04 +02:00
import datetime
from .session import org_mode
2017-05-23 21:57:51 +02:00
from .tests import basic
2017-05-23 22:16:27 +02:00
from .tests import gac_100
2017-09-30 00:57:19 +02:00
from .tests import gac_extension
2017-05-23 19:04:10 +02:00
2017-09-17 21:28:25 -04:00
logging.getLogger().setLevel(logging.ERROR)
2017-05-23 19:04:10 +02:00
2017-05-23 21:57:51 +02:00
tests = (
("basic", basic),
2017-05-23 22:16:27 +02:00
("gac 100", gac_100),
2017-09-30 00:57:19 +02:00
("gac+", gac_extension),
2017-05-23 21:57:51 +02:00
)
2017-05-23 19:04:10 +02:00
2017-09-30 01:32:04 +02:00
def gen_session_name():
now = datetime.datetime.utcnow()
return "treeNLU-test-session-{}.org".format(
now.strftime("%y_%m_%d %H:%M:%S_%f"))
2017-05-23 19:04:10 +02:00
def main():
2017-09-30 01:32:04 +02:00
org_mode.create_global_session(gen_session_name())
failed = False
2017-05-23 21:57:51 +02:00
for test_name, test_module in tests:
try:
test_module.main()
print(" \x1b[1;32m✓\x1b[0m {}".format(test_name))
2017-05-23 22:16:27 +02:00
except AssertionError as ae:
2017-05-24 22:37:44 +02:00
print(" \x1b[1;31m✗\x1b[0m {}{}".format(test_name,
('\n [Assertion] {}'.format(ae.args[0])) if len(ae.args) > 0
2017-05-24 22:06:18 +02:00
else ''))
failed = True
2017-05-23 21:57:51 +02:00
except Exception as e:
2017-05-24 22:37:44 +02:00
print(" \x1b[1;7;31m!\x1b[0m {}\n [Exception] {}".format(test_name, e))
failed = True
traceback.print_exc()
2017-09-17 21:28:25 -04:00
raise
if failed:
exit(1)
2017-05-23 19:04:10 +02:00
if __name__ == '__main__':
main()