Skip to content

Commit

Permalink
Handle words without grammar information
Browse files Browse the repository at this point in the history
Before this commit, grammar_raw returned None if no '.grammatik' element is found. This leads to TypeError in 'Word.grammar' and seems unintuitive, since in other cases an empty list is retuned (see GH-21).
Now grammar_raw returns an empty list if no grammar section is found.
  • Loading branch information
pajowu authored and radomirbosak committed Jan 17, 2021
1 parent 922b708 commit 1213d4f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion duden/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def grammar_raw(self):
"""
section = self.soup.find('div', id='grammatik')
if not section:
return None
return []

table_nodes = self.soup.find_all('div', class_='wrap-table') \
+ self.soup.find_all('table', class_='mere-table')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/Qat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ word_separation:
meaning_overview: null
origin: null
compounds: null
grammar_raw: null
grammar_raw: []
synonyms: null
words_before:
- q, Q
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/einfach.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ compounds:
- passen
- stimmen
- werden
grammar_raw: null
grammar_raw: []
synonyms:
- einmal, nicht doppelt, nicht mehrfachbequem
words_before:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_online_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,8 @@ def test_word_grammar(parsed_word, expected_dict):
for tags, string in expected_grammar]

assert parsed_word.grammar_raw == expected_grammar

def test_empty_grammar():
word = get("Wahlbeobachter")
assert word.grammar_raw == []
assert word.grammar() == []

0 comments on commit 1213d4f

Please sign in to comment.