我想为标准的PyHamcrest匹配器获取str,以便登录:
from hamcrest import equal_to
print str(equal_to('string'))
print unicode(equal_to(u'❤'))
第二次打印失败,因为matcher内部有一个“str”调用。 我用这门课解决了这个问题:
class UnicodeIsEqual(IsEqual):
def __str__(self):
return unicode(StringDescription().append_description_of(self))
print unicode(UnicodeIsEqual(u'❤'))
有没有更好的方法不用创建自定义匹配器?你知道吗
在需要时,通过使用包装类解决了此问题:
相关问题 更多 >
编程相关推荐