Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't display training progress bars while tests are running #1183

Merged
merged 2 commits into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions chatterbot/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Trainer(object):
def __init__(self, storage, **kwargs):
self.storage = storage
self.logger = logging.getLogger(__name__)
self.show_training_progress = kwargs.get('show_training_progress', True)

def train(self, *args, **kwargs):
"""
Expand Down Expand Up @@ -81,7 +82,11 @@ def train(self, conversation):
previous_statement_text = None

for conversation_count, text in enumerate(conversation):
print_progress_bar("List Trainer", conversation_count + 1, len(conversation))
if self.show_training_progress:
print_progress_bar(
'List Trainer',
conversation_count + 1, len(conversation)
)

statement = self.get_or_create(text)

Expand Down Expand Up @@ -121,11 +126,13 @@ def train(self, *corpus_paths):
corpus_files = self.corpus.list_corpus_files(corpus_path)
for corpus_count, corpus in enumerate(corpora):
for conversation_count, conversation in enumerate(corpus):
print_progress_bar(
str(os.path.basename(corpus_files[corpus_count])) + " Training",
conversation_count + 1,
len(corpus)
)

if self.show_training_progress:
print_progress_bar(
str(os.path.basename(corpus_files[corpus_count])) + ' Training',
conversation_count + 1,
len(corpus)
)

previous_statement_text = None

Expand Down
4 changes: 3 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests_django.test_settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
test_runner = TestRunner(
verbosity=2
)
failures = test_runner.run_tests(['tests_django'])
sys.exit(bool(failures))
7 changes: 2 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ universal = 1
description-file = README.md

[nosetests]
verbosity = 3
exclude = (?:^tests_django$)
with-coverage = true
cover-package = chatterbot
Expand All @@ -16,8 +17,4 @@ cover-package = chatterbot
# H306: imports not in alphabetical order (time, os)
ignore = H306
max_line_length = 175
exclude =
.eggs,
.git,
.tox,
build,
exclude = .eggs, .git, .tox, build,
1 change: 1 addition & 0 deletions tests/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get_kwargs(self):
return {
'input_adapter': 'chatterbot.input.VariableInputTypeAdapter',
'output_adapter': 'chatterbot.output.OutputAdapter',
'show_training_progress': False,
# Run the test database in-memory
'database': None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_filter_selection(self):
from chatterbot.trainers import ListTrainer

self.chatbot.filters = (RepetitiveResponseFilter(), )
self.chatbot.set_trainer(ListTrainer)
self.chatbot.set_trainer(ListTrainer, **self.get_kwargs())

self.chatbot.train([
'Hello',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
from chatterbot.trainers import ListTrainer
from chatterbot.comparisons import sentiment_comparison

self.chatbot.set_trainer(ListTrainer)
self.chatbot.set_trainer(ListTrainer, **self.get_kwargs())
self.adapter = BestMatch(
statement_comparison_function=sentiment_comparison
)
Expand Down
2 changes: 1 addition & 1 deletion tests/logic_adapter_tests/test_data_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self):
self.chatbot.logic = DummyMutatorLogicAdapter()
self.chatbot.logic.set_chatbot(self.chatbot)

self.chatbot.set_trainer(ListTrainer)
self.chatbot.set_trainer(ListTrainer, **self.get_kwargs())

self.chatbot.train([
'Hello',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class ChatterBotCorpusTrainingTestCase(TestCase):
def setUp(self):
super(ChatterBotCorpusTrainingTestCase, self).setUp()
self.chatbot = ChatBot(**settings.CHATTERBOT)
self.chatbot.set_trainer(ChatterBotCorpusTrainer)
self.chatbot.set_trainer(
ChatterBotCorpusTrainer,
**settings.CHATTERBOT
)

def tearDown(self):
super(ChatterBotCorpusTrainingTestCase, self).setUp()
Expand Down
1 change: 1 addition & 0 deletions tests_django/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'training_data': [
'chatterbot.corpus.english.greetings'
],
'show_training_progress': False,
'logic_adapters': [
{
'import_path': 'chatterbot.logic.BestMatch',
Expand Down