MCPcopy
hub / github.com/django/django / test_emptyCollections

Method test_emptyCollections

tests/gis_tests/geos_tests/test_geos.py:1258–1312  ·  view source on GitHub ↗

Testing empty geometries and collections.

(self)

Source from the content-addressed store, hash-verified

1256 self.assertEqual(8.0, mpoly.length)
1257
1258 def test_emptyCollections(self):
1259 "Testing empty geometries and collections."
1260 geoms = [
1261 GeometryCollection([]),
1262 fromstr("GEOMETRYCOLLECTION EMPTY"),
1263 GeometryCollection(),
1264 fromstr("POINT EMPTY"),
1265 Point(),
1266 fromstr("LINESTRING EMPTY"),
1267 LineString(),
1268 fromstr("POLYGON EMPTY"),
1269 Polygon(),
1270 fromstr("MULTILINESTRING EMPTY"),
1271 MultiLineString(),
1272 fromstr("MULTIPOLYGON EMPTY"),
1273 MultiPolygon(()),
1274 MultiPolygon(),
1275 ]
1276
1277 if numpy:
1278 geoms.append(LineString(numpy.array([])))
1279
1280 for g in geoms:
1281 with self.subTest(g=g):
1282 self.assertIs(g.empty, True)
1283
1284 # Testing len() and num_geom.
1285 if isinstance(g, Polygon):
1286 self.assertEqual(1, len(g)) # Has one empty linear ring
1287 self.assertEqual(1, g.num_geom)
1288 self.assertEqual(0, len(g[0]))
1289 elif isinstance(g, (Point, LineString)):
1290 self.assertEqual(1, g.num_geom)
1291 self.assertEqual(0, len(g))
1292 else:
1293 self.assertEqual(0, g.num_geom)
1294 self.assertEqual(0, len(g))
1295
1296 # Testing __getitem__ (doesn't work on Point or Polygon)
1297 if isinstance(g, Point):
1298 msg = "Invalid GEOS Geometry index:"
1299 with self.assertRaisesMessage(IndexError, msg):
1300 g.x
1301 elif isinstance(g, Polygon):
1302 lr = g.shell
1303 self.assertEqual("LINEARRING EMPTY", lr.wkt)
1304 self.assertEqual(0, len(lr))
1305 self.assertIs(lr.empty, True)
1306 msg = "invalid index: 0"
1307 with self.assertRaisesMessage(IndexError, msg):
1308 lr.__getitem__(0)
1309 else:
1310 msg = "invalid index: 0"
1311 with self.assertRaisesMessage(IndexError, msg):
1312 g.__getitem__(0)
1313
1314 def test_collection_dims(self):
1315 gc = GeometryCollection([])

Callers

nothing calls this directly

Calls 11

GeometryCollectionClass · 0.90
fromstrFunction · 0.90
PointClass · 0.90
LineStringClass · 0.90
PolygonClass · 0.90
MultiLineStringClass · 0.90
MultiPolygonClass · 0.90
arrayMethod · 0.80
assertRaisesMessageMethod · 0.80
appendMethod · 0.45
__getitem__Method · 0.45

Tested by

no test coverage detected