Skip to content

Commit

Permalink
Make test/ files obey flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvine committed Jul 16, 2021
1 parent 63f5ab2 commit 54bc1c2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
5 changes: 5 additions & 0 deletions test/__init__.py
@@ -1,2 +1,7 @@
__all__ = [
"test_basic",
"test_combine",
]

from . import test_basic
from . import test_combine
42 changes: 19 additions & 23 deletions test/test_basic.py
@@ -1,6 +1,6 @@
import unittest
import markovify
import sys, os
import os
import operator


Expand Down Expand Up @@ -45,27 +45,27 @@ def test_make_sentence_with_start(self):
text_model = self.sherlock_model
start_str = "Sherlock Holmes"
sent = text_model.make_sentence_with_start(start_str)
assert sent != None
assert sent is not None
assert start_str == sent[: len(start_str)]

def test_make_sentence_with_start_one_word(self):
text_model = self.sherlock_model
start_str = "Sherlock"
sent = text_model.make_sentence_with_start(start_str)
assert sent != None
assert sent is not None
assert start_str == sent[: len(start_str)]

def test_make_sentence_with_start_one_word_that_doesnt_begin_a_sentence(self):
text_model = self.sherlock_model
start_str = "dog"
with self.assertRaises(KeyError) as context:
sent = text_model.make_sentence_with_start(start_str)
with self.assertRaises(KeyError):
text_model.make_sentence_with_start(start_str)

def test_make_sentence_with_word_not_at_start_of_sentence(self):
text_model = self.sherlock_model
start_str = "dog"
sent = text_model.make_sentence_with_start(start_str, strict=False)
assert sent != None
assert sent is not None
assert start_str == sent[: len(start_str)]

def test_make_sentence_with_words_not_at_start_of_sentence(self):
Expand All @@ -74,29 +74,27 @@ def test_make_sentence_with_words_not_at_start_of_sentence(self):
# " was I " has 2 matches in sherlock.txt
start_str = "was I"
sent = text_model.make_sentence_with_start(start_str, strict=False, tries=50)
assert sent != None
assert sent is not None
assert start_str == sent[: len(start_str)]

def test_make_sentence_with_words_not_at_start_of_sentence_miss(self):
text_model = self.sherlock_model_ss3
start_str = "was werewolf"
with self.assertRaises(markovify.text.ParamError):
sent = text_model.make_sentence_with_start(
start_str, strict=False, tries=50
)
text_model.make_sentence_with_start(start_str, strict=False, tries=50)

def test_make_sentence_with_words_not_at_start_of_sentence_of_state_size(self):
text_model = self.sherlock_model_ss2
start_str = "was I"
sent = text_model.make_sentence_with_start(start_str, strict=False, tries=50)
assert sent != None
assert sent is not None
assert start_str == sent[: len(start_str)]

def test_make_sentence_with_words_to_many(self):
text_model = self.sherlock_model
start_str = "dog is good"
with self.assertRaises(markovify.text.ParamError) as context:
sent = text_model.make_sentence_with_start(start_str, strict=False)
with self.assertRaises(markovify.text.ParamError):
text_model.make_sentence_with_start(start_str, strict=False)

def test_make_sentence_with_start_three_words(self):
start_str = "Sherlock Holmes was"
Expand All @@ -107,7 +105,7 @@ def test_make_sentence_with_start_three_words(self):
except markovify.text.ParamError:
assert True

with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
text_model.make_sentence_with_start(start_str)
text_model = self.sherlock_model_ss3
sent = text_model.make_sentence_with_start("Sherlock", tries=50)
Expand Down Expand Up @@ -150,25 +148,23 @@ def test_newline_text(self):
model.make_sentence()

def test_bad_corpus(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
markovify.Chain(corpus="testing, testing", state_size=2)

def test_bad_json(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
markovify.Chain.from_json(1)

def test_custom_regex(self):
with self.assertRaises(Exception) as context:
model = markovify.NewlineText(
with self.assertRaises(Exception):
markovify.NewlineText(
"This sentence contains a custom bad character: #.", reject_reg=r"#"
)

with self.assertRaises(Exception) as context:
model = markovify.NewlineText("This sentence (would normall fail")
with self.assertRaises(Exception):
markovify.NewlineText("This sentence (would normall fail")

model = markovify.NewlineText(
"This sentence (would normall fail", well_formed=False
)
markovify.NewlineText("This sentence (would normall fail", well_formed=False)


class MarkovifyTest(MarkovifyTestBase):
Expand Down
32 changes: 16 additions & 16 deletions test/test_combine.py
@@ -1,6 +1,6 @@
import unittest
import markovify
import sys, os
import os
import operator


Expand Down Expand Up @@ -28,48 +28,48 @@ def test_double_weighted(self):

def test_combine_chains(self):
chain = sherlock_model.chain
combo = markovify.combine([chain, chain])
markovify.combine([chain, chain])

def test_combine_dicts(self):
_dict = sherlock_model.chain.model
combo = markovify.combine([_dict, _dict])
markovify.combine([_dict, _dict])

def test_combine_lists(self):
_list = list(sherlock_model.chain.model.items())
combo = markovify.combine([_list, _list])
markovify.combine([_list, _list])

def test_bad_types(self):
with self.assertRaises(Exception) as context:
combo = markovify.combine(["testing", "testing"])
with self.assertRaises(Exception):
markovify.combine(["testing", "testing"])

def test_bad_weights(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
text_model = sherlock_model
combo = markovify.combine([text_model, text_model], [0.5])
markovify.combine([text_model, text_model], [0.5])

def test_mismatched_state_sizes(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
text_model_a = markovify.Text(sherlock, state_size=2)
text_model_b = markovify.Text(sherlock, state_size=3)
combo = markovify.combine([text_model_a, text_model_b])
markovify.combine([text_model_a, text_model_b])

def test_mismatched_model_types(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
text_model_a = sherlock_model
text_model_b = markovify.NewlineText(sherlock)
combo = markovify.combine([text_model_a, text_model_b])
markovify.combine([text_model_a, text_model_b])

def test_compiled_model_fail(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
model_a = sherlock_model
model_b = sherlock_model_compiled
combo = markovify.combine([model_a, model_b])
markovify.combine([model_a, model_b])

def test_compiled_chain_fail(self):
with self.assertRaises(Exception) as context:
with self.assertRaises(Exception):
model_a = sherlock_model.chain
model_b = sherlock_model_compiled.chain
combo = markovify.combine([model_a, model_b])
markovify.combine([model_a, model_b])

def test_combine_no_retain(self):
text_model = sherlock_model_no_retain
Expand Down
3 changes: 1 addition & 2 deletions test/test_itertext.py
@@ -1,7 +1,6 @@
import unittest
import markovify
import sys, os
import operator
import os


class MarkovifyTest(unittest.TestCase):
Expand Down

0 comments on commit 54bc1c2

Please sign in to comment.