MCPcopy
hub / github.com/django/django / test_linestring

Method test_linestring

tests/gis_tests/geos_tests/test_geos.py:448–512  ·  view source on GitHub ↗

Testing LineString objects.

(self)

Source from the content-addressed store, hash-verified

446 self.assertIs(p.valid, True)
447
448 def test_linestring(self):
449 "Testing LineString objects."
450 prev = fromstr("POINT(0 0)")
451 for line in self.geometries.linestrings:
452 ls = fromstr(line.wkt)
453 with self.subTest(line=line):
454 self.assertEqual(ls.geom_type, "LineString")
455 self.assertEqual(ls.geom_typeid, 1)
456 self.assertEqual(ls.dims, 1)
457 self.assertIs(ls.empty, False)
458 self.assertIs(ls.ring, False)
459 if hasattr(line, "centroid"):
460 self.assertEqual(line.centroid, ls.centroid.tuple)
461 if hasattr(line, "tup"):
462 self.assertEqual(line.tup, ls.tuple)
463
464 self.assertEqual(ls, fromstr(line.wkt))
465 self.assertIs(ls == prev, False) # Use assertIs() to test __eq__.
466 ls_len = len(ls)
467 msg = f"invalid index: {ls_len}"
468 with self.assertRaisesMessage(IndexError, msg):
469 ls.__getitem__(ls_len)
470 prev = ls
471
472 # Creating a LineString from a tuple, list, and numpy array
473 self.assertEqual(ls, LineString(ls.tuple)) # tuple
474 self.assertEqual(ls, LineString(*ls.tuple)) # as individual arguments
475 self.assertEqual(
476 ls, LineString([list(tup) for tup in ls.tuple])
477 ) # as list
478 # Point individual arguments
479 self.assertEqual(
480 ls.wkt, LineString(*tuple(Point(tup) for tup in ls.tuple)).wkt
481 )
482 if numpy:
483 self.assertEqual(
484 ls, LineString(numpy.array(ls.tuple))
485 ) # as numpy array
486
487 with self.assertRaisesMessage(
488 TypeError, "Each coordinate should be a sequence (list or tuple)"
489 ):
490 LineString((0, 0))
491
492 with self.assertRaisesMessage(
493 ValueError, "LineString requires at least 2 points, got 1."
494 ):
495 LineString([(0, 0)])
496
497 if numpy:
498 with self.assertRaisesMessage(
499 ValueError, "LineString requires at least 2 points, got 1."
500 ):
501 LineString(numpy.array([(0, 0)]))
502
503 with mock.patch("django.contrib.gis.geos.linestring.numpy", False):
504 with self.assertRaisesMessage(
505 TypeError, "Invalid initialization input for LineStrings."

Callers

nothing calls this directly

Calls 7

fromstrFunction · 0.90
LineStringClass · 0.90
PointClass · 0.90
assertRaisesMessageMethod · 0.80
arrayMethod · 0.80
__getitem__Method · 0.45
patchMethod · 0.45

Tested by

no test coverage detected