简体   繁体   English

doctest预期为True,得到True

[英]doctest expected True, got True

doctest is hard to control. doctest很难控制。 I encontered a problem like that 我遇到了这样的问题

function 功能

from collections import namedtuple

Match = namedtuple('Match', ['token_string', 'normalised_token',
                     'brand_name', 'brand_id',
                     'score'])


def make_match(tokens, normalised, brand, score):
"""
Examples:
>>> make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)==Match('Jack Jones','JackJones','Jack Jones','X023',0.6)
True 
>>> make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)==('Jack Jones','JackJones','Jack Jones','X023',0.6)
True
>>> match=make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)
>>> match.token_string=='Jack Jones'
True
"""
return Match(token_string=tokens,
         normalised_token=normalised,
         brand_name=brand[0],
         brand_id=brand[1],
         score=score)

but got an error 但是有一个错误

Failed example:
make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)==Match('Jack Jones','JackJones','Jack Jones','X023',0.6)
Expected:
    True 
Got:
    True

1 items had failures: 1个项目有故障:

Isn't Expected matched exactly Got ? 难道不是完全匹配了吗? Thank you very much 1 of 4 in utilization.make_match Test Failed 1 failures. 非常感谢利用率4中的1。make_match 测试失败 1个失败。

您在指定期望返回值的行上有尾随空格,因此doctest实际上将字符串"True "与实际返回值True

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python doctest失败,原因是“预期”和“等于”相等 - Python doctest failed for equal “Expected” and “Got” TypeError:不兼容的可广播尺寸。 预期(False),得到(True) - TypeError: Incompatible broadcastable dimensions. Expected (False,), got (True,) 字段“id”需要一个数字但得到了(<orderitem: 1 of dummy> , 真的)</orderitem:> - Field 'id' expected a number but got (<OrderItem: 1 of Dummy 1>, True) python doctest:预期结果与“got”结果相同,但测试失败 - python doctest: expected result is the same as the “got” result but the test failed Django TypeError:字段“id”需要一个数字但得到了<homeworkForm bound=True, valid=Unknown, fields=(title;descripiton;due)> - Django TypeError: Field 'id' expected a number but got <homeworkForm bound=True, valid=Unknown, fields=(title;descripiton;due)> TypeError:字段'id'需要一个数字,但得到(<group: customer> , 真) DJANGO 错误</group:> - TypeError: Field 'id' expected a number but got (<Group: customer>, True) DJANGO ERROR `from_numpy()` 导致 Expected vec.is_mps() 为真,但结果为假 - `from_numpy()` leads to Expected vec.is_mps() to be true, but got false doctest期望什么都没有 - doctest Expected nothing 如何在我的 doctest 中只为完整的单词匹配返回 TRUE? - How do I only return TRUE for full word matches in my doctest? Pytorch autograd 引发错误:“预期 isFloatingType(grads[i].type().scalarType()) 为真,但在 loss.backward() 时为假” - Pytorch autograd raising the error: "Expected isFloatingType(grads[i].type().scalarType()) to be true, but got false" when loss.backward()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM