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

51 lines
1.3 KiB
Python
Raw Normal View History

import traceback
2017-05-23 17:04:10 +00:00
import logging
2017-09-29 23:32:04 +00:00
from .session import org_mode
2018-04-01 18:24:09 +00:00
from .tests import tokenization
2017-05-23 19:57:51 +00:00
from .tests import basic
2017-05-23 20:16:27 +00:00
from .tests import gac_100
2017-09-29 22:57:19 +00:00
from .tests import gac_extension
2017-05-23 17:04:10 +00:00
2017-09-18 01:28:25 +00:00
logging.getLogger().setLevel(logging.ERROR)
2017-05-23 17:04:10 +00:00
2017-05-23 19:57:51 +00:00
tests = (
2018-04-01 18:24:09 +00:00
("tokenization", tokenization),
2017-05-23 19:57:51 +00:00
("basic", basic),
2017-05-23 20:16:27 +00:00
("gac 100", gac_100),
2017-09-29 22:57:19 +00:00
("gac+", gac_extension),
2017-05-23 19:57:51 +00:00
)
2017-05-23 17:04:10 +00:00
2017-09-29 23:32:04 +00:00
def gen_session_name():
2017-10-01 15:10:50 +00:00
return "treeNLU-test-session.org"
2017-09-29 23:32:04 +00:00
2017-05-23 17:04:10 +00:00
def main():
2017-09-29 23:32:04 +00:00
org_mode.create_global_session(gen_session_name())
failed = False
2017-05-23 19:57:51 +00:00
for test_name, test_module in tests:
try:
2018-04-01 18:24:09 +00:00
with org_mode.global_session().log(test_name):
test_module.main()
print(" \x1b[1;32m✓\x1b[0m {}".format(test_name))
2017-05-23 20:16:27 +00:00
except AssertionError as ae:
2017-05-24 20:37:44 +00:00
print(" \x1b[1;31m✗\x1b[0m {}{}".format(test_name,
('\n [Assertion] {}'.format(ae.args[0])) if len(ae.args) > 0
2017-05-24 20:06:18 +00:00
else ''))
2018-04-01 18:24:09 +00:00
traceback.print_exc()
failed = True
2017-05-23 19:57:51 +00:00
except Exception as e:
2017-05-24 20:37:44 +00:00
print(" \x1b[1;7;31m!\x1b[0m {}\n [Exception] {}".format(test_name, e))
failed = True
traceback.print_exc()
2017-09-18 01:28:25 +00:00
raise
2017-10-01 15:10:50 +00:00
org_mode.global_session().close()
if failed:
exit(1)
2017-05-23 17:04:10 +00:00
if __name__ == '__main__':
main()