Add progress bar visuals to tests.

This commit is contained in:
kenkeiras 2017-05-24 22:37:44 +02:00
parent 8e304b2a09
commit e0a5f02c34
3 changed files with 31 additions and 4 deletions

View File

@ -17,13 +17,13 @@ def main():
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,
(' : [Assertion] {}'.format(ae.args[0])) if len(ae.args) > 0
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 {} : [Exception] {}".format(test_name, e))
print(" \x1b[1;7;31m!\x1b[0m {}\n [Exception] {}".format(test_name, e))
failed = True
traceback.print_exc()

View File

@ -1,4 +1,5 @@
from ..knowledge_base import KnowledgeBase
from ..utils.visuals import show_progbar
def _assert(args):
assert(args)
@ -670,14 +671,20 @@ def main():
knowledge=base_knowledge,
)
for example_type, data in examples:
total = len(examples)
for i, (example_type, data) in enumerate(examples):
if example_type == 'full_example':
affirmation = {
'text': data['affirmation'],
'parsed': data['parsed'][1],
}
question = data
show_progbar(i, total, data['affirmation'])
differences = knowledge.train([affirmation])
show_progbar(i, total, data['text'])
differences = knowledge.train([question])
result, _, _ = knowledge.process(data['text'])
@ -690,7 +697,10 @@ def main():
f(knowledge)
elif example_type == 'text_example':
show_progbar(i, total, data['affirmation'])
affirmation = data['affirmation']
show_progbar(i, total, data['question'])
question = data['question']
_, _, _ = knowledge.process(affirmation)
@ -701,3 +711,5 @@ def main():
else:
raise NotImplementedError('Example type: {}'.format(example_type))
print("\r\x1b[K", end='')

View File

@ -0,0 +1,15 @@
def show_progbar(done, total, msg=''):
total_blocks = 10
blocks_done = (done * total_blocks) // total
blocks_to_go = total_blocks - blocks_done
print('\r\x1b[K' # Go to the start of the line
'\x1b[0m' # Restart the "style"
'|' # Put the first "|"
+ blocks_done * '' # Completed blocks
+ blocks_to_go * ' ' # Uncompleted blocks
+ '\x1b[7m|\x1b[0m' # End the bar
+ ' '
+ msg # Add message
+ '\r' # Go back to the start
, end='')