def main(): logger = log.setup_custom_logger(__name__) parser = argparse.ArgumentParser( description='Get synonyms of German words from www.openthesaurus.de') parser.add_argument( '--form', required=False, action='store', choices=['long', 'short'], type=str, default='short', help= "Defaults to form=short which means that short versions of synonyms will be returned, " "without nach/zu prefixes/suffixes." "On the other hand, form=long returns the full versions of synonyms including nach/zu, " "sich prefixes/suffixes") required = parser.add_argument_group('required arguments') required.add_argument('--word', type=str, action='store', required=True, help="A word from which synonyms will be obtained") args = parser.parse_args() open_thesaurus = OpenThesaurusWeb() synonyms = open_thesaurus.get_synonyms(word=args.word, form=args.form) logger.info(synonyms)
def test_get_synonyms_empty_wrong_input_word_special_characters(self): # arrange word = None # act instance = OpenThesaurusWeb() synonyms = instance.get_synonyms(word=word) # assert self.assertFalse(synonyms)
def test_get_synonyms_empty_wrong_input_word(self): # arrange word = '' # act instance = OpenThesaurusWeb() synonyms = instance.get_synonyms(word=word) # assert self.assertFalse(synonyms)
def test_get_synonyms_empty_no_word_in_dictionary(self): # arrange word = 'Taking' # act instance = OpenThesaurusWeb() synonyms = instance.get_synonyms(word=word) # assert self.assertFalse(synonyms)
def test_entry_word_valid_german(self): # arrange word = 'München' # act instance = OpenThesaurusWeb() valid = instance.is_entry_word_valid(word=word) # assert self.assertTrue(valid)
def test_entry_word_valid(self): # arrange word = 'Taking' # act instance = OpenThesaurusWeb() valid = instance.is_entry_word_valid(word=word) # assert self.assertTrue(valid)
def test_entry_word_valid_special_characters(self): # arrange word = 'Taking!"WDSDA sadsad!!!' # act instance = OpenThesaurusWeb() valid = instance.is_entry_word_valid(word=word) # assert self.assertTrue(valid)
def test_entry_word_not_valid(self): # arrange word = '' # act instance = OpenThesaurusWeb() valid = instance.is_entry_word_valid(word=word) # assert self.assertFalse(valid)
def test_entry_word_not_valid_all_special_charaters(self): # arrange word = '!!!$!!!"??' # act instance = OpenThesaurusWeb() valid = instance.is_entry_word_valid(word=word) # assert self.assertFalse(valid)
def test_get_synonyms_short_not_empty(self): # arrange word = 'gehen' # act instance = OpenThesaurusWeb() synonyms = instance.get_synonyms(word=word) # assert self.assertTrue(synonyms)
def test_runtime_error_wrong_type(self): # arrange word = 'München' # act instance = OpenThesaurusWeb() synonyms = instance.get_synonyms(word=word, form='sadsa') # assert self.assertRaises(RuntimeError) self.assertFalse(synonyms)
def test_get_synonyms_long_short_equal(self): # arrange word = 'München' # act instance = OpenThesaurusWeb() synonyms_short = instance.get_synonyms(word=word) synonyms_long = instance.get_synonyms(word=word, form='long') # assert synonyms_long_len = len(".".join(synonyms_long)) synonyms_short_len = len(".".join(synonyms_short)) self.assertLessEqual(synonyms_short_len, synonyms_long_len)