即使答案相等,Django assertEquals()测试失败 [英] Django assertEquals() test failing even though answer is equal
本文介绍了即使答案相等,Django assertEquals()测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个功能:
from django.contrib.gis.measure import Distance, D
def RunLengthCalc(mod_ewdim, mod_ewspacing, cols):
y = D(inch=mod_ewspacing) # user input
x = D(inch=mod_ewdim) # user input
z = D(inch=3) # constant
lrun = ((x * cols) + (y * (cols - 1))) + zrun
return lrun
和我的测试:
def test_run_length_calculation(self):
l = RunLengthCalc(26.5, 1, 25)
self.assertEquals(l, D(inch=689.5))
但是当我运行测试我得到这个非常混乱的错误:
but when I run the test I get this very confusing error:
AssertionError: Distance(inch=689.5) != Distance(inch=689.5)
我无法解决问题在这里。
I can't work out what the problem is here.
任何帮助将不胜感激。
推荐答案
做一些有趣的事情,如何等距离等级实际上实现了:
There seems to be some funny business with how the Distance class equality is actually implemented:
https://github.com/django/django/blob/master/django/contrib/gis/measure.py#L87
阅读该代码,它看起来像你应该工作...但显然没有。
Reading that code, it looks like what you have should work... but apparently it doesn't.
我怀疑你可以解决你的问题比较如下所示的特定单位值:
I suspect you can fix your problem by comparing specific unit values like so:
self.assertEquals(l.inch,D(inch = 689.5).inch)
这篇关于即使答案相等,Django assertEquals()测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文