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

Commit

Permalink
Merge pull request #102 from zdict/issue-100
Browse files Browse the repository at this point in the history
[#101] Add unit test for YahooDict of vocabulary 'style'
  • Loading branch information
M157q committed Aug 31, 2016
2 parents 92eae41 + daf9abc commit 05e5c81
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions zdict/tests/dictionaries/test_yahoo.py
@@ -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)

0 comments on commit 05e5c81

Please sign in to comment.