I have a function:
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
and my test:
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.
Any help would be much appreciated.
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)