我目前正在做 Zed A. Shaw 的“Learn Python the Hard Way”,我在使用 assert_raises 的练习 49 上遇到了很多麻烦。这是我在测试文件中使用的代码:
def test_parseVerb():
assert_raises("ParserError",parser.parse_verb,[('stop', 'the'),
('noun', 'bear')])
这是 PowerShell 给我的错误:
======================================================================
ERROR: tests.parser_tests.test_parseVerb
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\MrnMicro\Python27\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Documents and Settings\sthma2\Documents\LPTHW\Projects\ex48\tests\parser_tests.py", line 37, in test_parseVer
b
assert_raises("ParserError",parser.parse_verb,fail_list)
File "C:\MrnMicro\Python27\lib\unittest\case.py", line 476, in assertRaises
callableObj(*args, **kwargs)
File "C:\MrnMicro\Python27\lib\unittest\case.py", line 117, in __exit__
if not issubclass(exc_type, self.expected):
TypeError: issubclass() arg 2 must be a class or tuple of classes
----------------------------------------------------------------------
Ran 10 tests in 0.016s
FAILED (errors=1)
老实说,我不知道发生了什么,如果有人可以提供帮助,将不胜感激!
谢谢 !
编辑
def parse_verb(word_list):
skip(word_list, 'stop')
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")