即使答案相等,Django assertEquals()测试失败

时间:2012-10-25 23:37:13

标签: django django-testing

我有一个功能:

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))

但是当我运行测试时,我得到了这个非常令人困惑的错误:

AssertionError: Distance(inch=689.5) != Distance(inch=689.5)

我无法解决这里的问题。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

似乎有一些有趣的业务与Distance类相等如何实际实现:

https://github.com/django/django/blob/master/django/contrib/gis/measure.py#L87

阅读该代码,它看起来像你应该工作的......但显然它没有。

我怀疑你可以通过比较特定的单位值来解决你的问题:

self.assertEquals(l.inch, D(inch=689.5).inch)

相关问题