def test_load_bigram_dictionary_invalid_path(self, symspell_default): with TestCase.assertLogs("symspellpy.symspellpy.logger", level="ERROR") as cm: assert not symspell_default.load_bigram_dictionary( INVALID_PATH, 0, 2) assert (f"Bigram dictionary file not found at {Path(INVALID_PATH)}." == cm.records[0].getMessage())
def test_pickle_bytes(self, symspell_default_load): sym_spell, _ = symspell_default_load sym_spell_2 = SymSpell(123, 456, 789) assert sym_spell._count_threshold != sym_spell_2._count_threshold assert (sym_spell._max_dictionary_edit_distance != sym_spell_2._max_dictionary_edit_distance) assert sym_spell._prefix_length != sym_spell_2._prefix_length with TestCase.assertLogs("symspellpy.symspellpy.logger", level="WARNING") as cm: sym_spell_2.load_pickle(sym_spell.save_pickle(to_bytes=True), from_bytes=True) assert ( "Loading data which was created using different ('count_threshold', " "'max_dictionary_edit_distance', 'prefix_length') settings. Overwriting " "current SymSpell instance with loaded settings ..." ) == cm.records[0].getMessage() assert sym_spell.below_threshold_words == sym_spell_2.below_threshold_words assert sym_spell.bigrams == sym_spell_2.bigrams assert sym_spell.deletes == sym_spell_2.deletes assert sym_spell.words == sym_spell_2.words assert sym_spell._max_length == sym_spell_2._max_length assert sym_spell._count_threshold == sym_spell_2._count_threshold assert (sym_spell._max_dictionary_edit_distance == sym_spell_2._max_dictionary_edit_distance) assert sym_spell._prefix_length == sym_spell_2._prefix_length
def test_mako_error_handling(): ''' Tests error logging and re-raising of an Exception in Mako template by intentionally not passing a variable ''' kwargs = { 'report_name': 'my_report', 'info': ITEST, 'prefix': 'MAKO_TEST-', } test_case = TestCase() with test_case.assertLogs() as log_cm: with assert_raises(TypeError): render_template((TEST_OUT_DIR / 'never_created_file.rst'), **kwargs) test_case.assertIn( 'Exception raised in Mako template, which will be re-raised after logging line info:', log_cm.output[0]) test_case.assertIn('File ', log_cm.output[-1]) test_case.assertIn('line ', log_cm.output[-1]) test_case.assertIn( "in render_body: '% for suite_idx, suite in enumerate(test_suites, start=1):'", log_cm.output[-1])
def test_create_dictionary_invalid_path(self, symspell_default): with TestCase.assertLogs("symspellpy.symspellpy.logger", level="ERROR") as cm: assert not symspell_default.create_dictionary(INVALID_PATH) assert (f"Corpus not found at {Path(INVALID_PATH)}." == cm.records[0].getMessage())