diff --git a/tests/tests.py b/tests/tests.py index 512cb76..795538b 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -19,14 +19,14 @@ def test_meaning_valid_phrase(self): result = '[{"seq": 0, "text": "Present participle of hum."}]' middle_val = json.loads(result) expected_result = json.dumps(middle_val) - if sys.version_info[:2] <= (2, 7): ## python 2 + if sys.version_info[:2] <= (2, 7): ## python 2 self.assertItemsEqual(current_result, expected_result) else: # python 3 """ - assertItemsEqual() was renamed to assertCountEqual() - Why I am not using assertEqual() here? + assertItemsEqual() was renamed to assertCountEqual() + Why I am not using assertEqual() here? - Reference: + Reference: - http://stackoverflow.com/a/7473137/3834059 - https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertItemsEqual - https://docs.python.org/3/library/unittest.html?highlight=assertcountequal#unittest.TestCase.assertCountEqual @@ -37,7 +37,7 @@ def test_meaning_valid_phrase(self): def test_meaning_not_valid_phrase(self): current_result = vb.meaning("sxsw") self.assertFalse(current_result) - + def test_synonym_valid_phrase(self): current_result = vb.synonym("repudiate") result = '[{"seq": 0, "text": "deny"}]' @@ -51,7 +51,7 @@ def test_synonym_valid_phrase(self): def test_synonym_not_valid_phrase(self): current_result = vb.synonym("sxsw") self.assertFalse(current_result) - + def test_antonym_valid_phrase_1(self): current_result = vb.antonym("love") result = '{"text": ["hate"]}' diff --git a/vocabulary/vocabulary.py b/vocabulary/vocabulary.py index 49aeec9..485c510 100644 --- a/vocabulary/vocabulary.py +++ b/vocabulary/vocabulary.py @@ -122,7 +122,7 @@ def __parse_content(tuc_content, content_to_be_parsed): ## for 'meanings', 'contents_raw' is a list for meaning_content in contents_raw: initial_parsed_content[i] = meaning_content['text'] - i +=1 + i += 1 final_parsed_content = {} ## removing duplicates(if any) from the dictionary @@ -178,7 +178,6 @@ def meaning(phrase, source_lang="en", dest_lang="en"): return False '''get meanings''' meanings_list = Vocabulary.__parse_content(tuc_content, "meanings") - # return meanings_list return json.dumps(meanings_list) else: return False @@ -204,13 +203,8 @@ def synonym(phrase, source_lang="en", dest_lang="en"): return False synonyms_list = Vocabulary.__parse_content(tuc_content, "phrase") if synonyms_list: - # return synonyms_list return json.dumps(synonyms_list) - else: - return False - - else: - return False + return False ## TO-DO: ## if this gives me no results, will query "bighugelabs" @@ -241,12 +235,8 @@ def translate(phrase, source_lang, dest_lang): return False translations_list = Vocabulary.__parse_content(tuc_content, "phrase") if translations_list: - # return synonyms_list return json.dumps(translations_list) - else: - return False - else: - return False + return False @@ -295,7 +285,6 @@ def antonym(phrase): final_dictionary[key] = value antonyms.append(final_dictionary) - # return json.dumps(final_dictionary) return final_dictionary else: return False @@ -327,7 +316,6 @@ def part_of_speech(phrase): final_list.append({ "seq": i, "text": key, "example:" :value}) i += 1 return json.dumps(final_list) - # return final_list else: return False else: @@ -352,7 +340,6 @@ def usage_example(phrase): if word_examples: ## reforamatting "word_examples" using "__clean_dict()" return json.dumps(Vocabulary.__clean_dict(word_examples)) - # return Vocabulary.__clean_dict(word_examples) else: return False else: @@ -373,7 +360,7 @@ def pronunciation(phrase): ''' Refer : http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence ''' - ## TODO: Fix the unicode issue mentioned in + ## TODO: Fix the unicode issue mentioned in ## https://github.com/prodicus/vocabulary#181known-issues if sys.version_info[:2] <= (2, 7): ## python2 return json_obj @@ -396,6 +383,5 @@ def hyphenation(phrase): json_obj = Vocabulary.__return_json(url) if json_obj: return json.dumps(json_obj) - # return json_obj else: return False