'Test the `Length` function.'

@skipUnlessDBFeature('has_Length_function')
def test_length(self):

    len_m1 = 473504.769553813
    len_m2 = 4617.668
    if connection.features.supports_length_geodetic:
        qs = Interstate.objects.annotate(length=Length('path'))
        tol = (2 if oracle else 3)
        self.assertAlmostEqual(len_m1, qs[0].length.m, tol)
    else:
        with self.assertRaises(NotImplementedError):
            list(Interstate.objects.annotate(length=Length('path')))
    i10 = SouthTexasInterstate.objects.annotate(length=Length('path')).get(name='I-10')
    self.assertAlmostEqual(len_m2, i10.length.m, 2)
    self.assertTrue(SouthTexasInterstate.objects.annotate(length=Length('path')).filter(length__gt=4000).exists())
    qs = Interstate.objects.annotate(length=Length(i10.path))
    self.assertAlmostEqual(qs.first().length.m, len_m2, 2)
