lundi 9 février 2015

How to patch and verify if a Class was instantiated with a specific parameter? [duplicate]


This question already has an answer here:




In a nutshell this is the class I would like to test. To see if Tokenizer('english') was created with 'english'.



def summarize(news):
language = 'english'
parser = PlaintextParser.from_string(news.body, Tokenizer(language))


This is the test



@mock.patch.object(PlaintextParser, 'from_string')
@mock.patch('sumy.nlp.tokenizers.Tokenizer')
def test_summarize_tokenizer_is_called_with_english(self, token_mock, parser_mock):
news_mock = mock.MagicMock()
body = u"xx"
type(news_mock).body = mock.PropertyMock(return_value=body)
Summarizer.summarize(news_mock)
token_mock.assert_called_with('english')


I keep getting:



AssertionError: Expected call: Tokenizer('english')
Not called


But this should pass. What am I missing please?


Aucun commentaire:

Enregistrer un commentaire