我有两个相同问题的测试方法,这是主类中的原始方法:
def get_num_words(self, word_part):
""" 1 as default, may want 0 as an invalid case """
if word_part[3] == '0a':
self.num_words = 10
else:
self.num_words = int(word_part[3])
return self.num_words
def get_num_pointers(self, before_at):
self.num_pointers = int(before_at.split()[-1])
return self.num_pointers
这是两个测试类:
def test_get_num_words(self):
word_part = ['13797906', '23', 'n', '04', 'flood', '0', 'inundation', '0', 'deluge', '0', 'torrent', '0', '005', '@', '13796604', 'n', '0000', '+', '00603894', 'a', '0401', '+', '00753137', 'v', '0302', '+', '01527311', 'v', '0203', '+', '02361703', 'v', '0101', '|', 'an', 'overwhelming', 'number', 'or', 'amount;', '"a', 'flood', 'of', 'requests";', '"a', 'torrent', 'of', 'abuse"']
expected = 04
real = self.wn.get_num_words(word_part)
for r, a in zip(real, expected):
self.assertEqual(r, a)
def test_get_num_pointers(self):
before_at = '13797906 23 n 04 flood 0 inundation 0 deluge 0 torrent 0 005'
expected = 5
real = self.wn.get_num_pointers(before_at)
for r, a in zip(real, expected):
self.assertEqual(r, a)
这是他们给出的错误:TypeError: zip argument #1 must support iteration
程序完全运行,这是仅有的 2 个测试在 20 个不同的测试中不起作用。