我一直在努力學習Python的艱辛之路第二版,它一直很棒。我的問題與練習49(http://learnpythonthehardway.org/book/ex49.html)有關,它是關於書寫鼻子單元測試,涵蓋書中給出的代碼的。我試圖寫一個測試,涵蓋這一功能:測試合適的對象是在鼻子中返回的(Learn Python the Hard Way Ex 49)
def parse_subject(word_list, subj):
verb = parse_verb(word_list)
obj = parse_object(word_list)
return Sentence(subj, verb, obj)
我試圖運行這個測試:
from nose.tools import *
from ex48 import engine
def test_parse_subject():
word_list = [('verb', 'verb'),
('direction', 'direction')]
test_subj = ('noun', 'noun')
test_verb = ('verb', 'verb')
test_obj = ('direction', 'direction')
assert_equal(engine.parse_subject(word_list, ('noun', 'noun')),
engine.Sentence(test_subj, test_verb, test_obj))
但它返回錯誤,因爲這兩個句子的對象不是EXACT相同的對象:
⚡ nosetests
.....F..........
======================================================================
FAIL: tests.engine_tests.test_parse_subject
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/nose/case.py", line 187, in runTest
self.test(*self.arg)
File "/Users/gregburek/code/LPTHW/projects/ex48/tests/engine_tests.py", line 59, in test_parse_subject
engine.Sentence(test_subj, test_verb, test_obj))
AssertionError: <ex48.engine.Sentence object at 0x101471390> != <ex48.engine.Sentence object at 0x1014713d0>
----------------------------------------------------------------------
Ran 16 tests in 0.018s
FAILED (failures=1)
如何我可以用鼻子來檢查兩個對象應該是一樣的嗎?