This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#101] Add unit test for YahooDict of vocabulary 'style'
- Loading branch information
shunyi
authored and
shunyi
committed
Aug 31, 2016
1 parent
9473b4f
commit daf9abc
Showing
1 changed file
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,66 @@ | ||
from pytest import raises | ||
from unittest.mock import Mock, patch | ||
|
||
from zdict.exceptions import NotFoundError | ||
from zdict.dictionaries.yahoo import YahooDict | ||
from zdict.zdict import get_args | ||
|
||
|
||
class TestyDict: | ||
def setup_method(self, method): | ||
self.dict = YahooDict(get_args()) | ||
@classmethod | ||
def setup_class(cls): | ||
cls.dict = YahooDict(get_args()) | ||
cls.word = 'style' | ||
cls.record = cls.dict.query(cls.word) | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
del cls.dict | ||
del cls.word | ||
del cls.record | ||
|
||
def teardown_method(self, method): | ||
del self.dict | ||
def test_provider(self): | ||
assert self.dict.provider == 'yahoo' | ||
|
||
def test_title(self): | ||
assert self.dict.title == 'Yahoo Dictionary' | ||
|
||
def test__get_url(self): | ||
url = 'https://tw.dictionary.search.yahoo.com/search?p=test' | ||
assert url == self.dict._get_url('test') | ||
|
||
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) | ||
|
||
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) | ||
|
||
@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', | ||
) | ||
|
||
@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', | ||
) | ||
|
||
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) |