Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_custom_regex(self):
with self.assertRaises(Exception) as context:
model = 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')
model = markovify.NewlineText('This sentence (would normall fail', well_formed = False)
def test_combine_retain_on_no_retain(self):
text_model_a = sherlock_model_no_retain
text_model_b = sherlock_model
combo = markovify.combine([ text_model_a, text_model_b ])
assert(combo.retain_original)
assert(combo.parsed_sentences == text_model_b.parsed_sentences)
def test_combine_lists(self):
_list = list(sherlock_model.chain.model.items())
combo = markovify.combine([ _list, _list ])
def test_mismatched_state_sizes(self):
with self.assertRaises(Exception) as context:
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 ])
def test_mismatched_model_types(self):
with self.assertRaises(Exception) as context:
text_model_a = sherlock_model
text_model_b = markovify.NewlineText(sherlock)
combo = markovify.combine([ text_model_a, text_model_b ])
def test_simple(self):
text_model = sherlock_model
combo = markovify.combine([ text_model, text_model ], [ 0.5, 0.5 ])
assert(combo.chain.model == text_model.chain.model)
def test_compiled_model_fail(self):
with self.assertRaises(Exception) as context:
model_a = sherlock_model
model_b = sherlock_model_compiled
combo = markovify.combine([ model_a, model_b ])
def test_bad_json(self):
with self.assertRaises(Exception) as context:
markovify.Chain.from_json(1)
def test_chain(self):
text_model = self.sherlock_model
chain_json = text_model.chain.to_json()
stored_chain = markovify.Chain.from_json(chain_json)
assert(get_sorted(stored_chain.to_json()) == get_sorted(chain_json))
new_text_model = markovify.Text.from_chain(chain_json)
assert(get_sorted(new_text_model.chain.to_json()) == get_sorted(chain_json))
sent = new_text_model.make_sentence()
assert(len(sent) != 0)
def testCheckModels(self):
for m in self.tm.models.values():
self.assertIsInstance(m, markovify.text.NewlineText)