Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Merge 1cfaeb2 into b10403c
Browse files Browse the repository at this point in the history
  • Loading branch information
wdv4758h committed Jul 1, 2018
2 parents b10403c + 1cfaeb2 commit 9026acc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
4 changes: 3 additions & 1 deletion zdict/dictionaries/yahoo.py
Expand Up @@ -233,7 +233,9 @@ def getg(d):
node = node.select('> div')

p = None # optional
if len(node) == 5:
if len(node) == 6: # e.g. "metadata"
_, w, p, _, _, e = node
elif len(node) == 5:
_, w, p, _, e = node
elif len(node) == 4: # e.g. "hold on"
_, w, _, e = node
Expand Down
11 changes: 11 additions & 0 deletions zdict/dictionary.py
Expand Up @@ -141,6 +141,17 @@ def lookup(self, word):
except exceptions.NotFoundError as e:
self.color.print(e, 'yellow')
print()
except Exception as e:
import traceback
traceback.print_exc()
url = "https://github.com/zdict/zdict/issues"
print()
print("We have problem for this word 😢")
print("Please report this word to {}".format(url))
print("Dictionary: {}".format(self.title))
print("Word: '{}'".format(word))
import sys
sys.exit(1)
else:
self.save(record, word)
self.show(record)
Expand Down
48 changes: 28 additions & 20 deletions zdict/tests/dictionaries/test_yahoo.py
Expand Up @@ -10,14 +10,14 @@ class TestyDict:
@classmethod
def setup_class(cls):
cls.dict = YahooDict(get_args())
cls.word = 'style'
cls.record = cls.dict.query(cls.word)
cls.words = ['style', 'metadata']
cls.records = [cls.dict.query(word) for word in cls.words]

@classmethod
def teardown_class(cls):
del cls.dict
del cls.word
del cls.record
del cls.words
del cls.records

def test_provider(self):
assert self.dict.provider == 'yahoo'
Expand All @@ -32,35 +32,43 @@ def test__get_url(self):
def test_show(self):
# god bless this method, hope that it do not raise any exception
self.dict.args.verbose = False
self.dict.show(self.record)

for record in self.records:
self.dict.show(record)

def test_show_verbose(self):
# god bless this method, hope that it do not raise any exception
self.dict.args.verbose = True
self.dict.show(self.record)

for record in self.records:
self.dict.show(record)

@patch('zdict.dictionaries.yahoo.Record')
def test_query_normal(self, Record):
self.dict.args.verbose = False
self.dict.query(self.word)
Record.assert_called_with(
word=self.word,
content=self.record.content,
source='yahoo',
)

for i, word in enumerate(self.words):
self.dict.query(word)
Record.assert_called_with(
word=word,
content=self.records[i].content,
source='yahoo',
)

@patch('zdict.dictionaries.yahoo.Record')
def test_query_verbose(self, Record):
self.dict.args.verbose = True
self.dict.query(self.word)
Record.assert_called_with(
word=self.word,
content=self.record.content,
source='yahoo',
)

for i, word in enumerate(self.words):
self.dict.query(word)
Record.assert_called_with(
word=word,
content=self.records[i].content,
source='yahoo',
)

def test_query_not_found(self):
self.dict._get_raw = Mock(return_value='{"data": []}')
with raises(NotFoundError):
self.dict.query(self.word)
self.dict._get_raw.assert_called_with(self.word)
self.dict.query(self.words[0])
self.dict._get_raw.assert_called_with(self.words[0])

0 comments on commit 9026acc

Please sign in to comment.