def test_hash(self): for geo in (Point(1., 2.), LineString(((1., 2.), (3., 4.), (5., 6.))), _LinearRing(((1., 2.), (3., 4.), (5., 6.))), Polygon([(10.1, 10.0), (110.0, 10.0), (110., 110.0), (10., 110.0), (10., 10.0)], [[(20., 20.0), (20., 30.0), (30., 30.0), (30., 20.0), (20., 20.0)], [(40., 20.0), (40., 30.0), (50., 30.0), (50., 20.0), (40., 20.0)]])): self.assertEqual(len(set((geo, geo))), 1)
def test_eq(self): for geo in (Point(1., 2.), LineString(((1., 2.), (3., 4.), (5., 6.))), _LinearRing(((1., 2.), (3., 4.), (5., 6.))), Polygon([(10.1, 10.0), (110.0, 10.0), (110., 110.0), (10., 110.0), (10., 10.0)], [[(20., 20.0), (20., 30.0), (30., 30.0), (30., 20.0), (20., 20.0)], [(40., 20.0), (40., 30.0), (50., 30.0), (50., 20.0), (40., 20.0)]])): # same type self.assertEqual(geo, geo) # does not blow up on other types # specifically use assertFalse(eq) to make sure we're using the geo __eq__ operator self.assertFalse(geo == object())
def test_str_wkt(self): self.assertEqual(str(Point(1., 2.)), 'POINT (1.0 2.0)') self.assertEqual(str(Point()), "POINT (nan nan)") self.assertEqual(str(LineString(((1., 2.), (3., 4.), (5., 6.)))), 'LINESTRING (1.0 2.0, 3.0 4.0, 5.0 6.0)') self.assertEqual(str(_LinearRing(((1., 2.), (3., 4.), (5., 6.)))), 'LINEARRING (1.0 2.0, 3.0 4.0, 5.0 6.0)') self.assertEqual( str( Polygon([(10.1, 10.0), (110.0, 10.0), (110., 110.0), (10., 110.0), (10., 10.0)], [[(20., 20.0), (20., 30.0), (30., 30.0), (30., 20.0), (20., 20.0)], [(40., 20.0), (40., 30.0), (50., 30.0), (50., 20.0), (40., 20.0)]])), 'POLYGON ((10.1 10.0, 110.0 10.0, 110.0 110.0, 10.0 110.0, 10.0 10.0), (20.0 20.0, 20.0 30.0, 30.0 30.0, 30.0 20.0, 20.0 20.0), (40.0 20.0, 40.0 30.0, 50.0 30.0, 50.0 20.0, 40.0 20.0))' ) class LinearRing(_LinearRing): pass for cls in (LineString, LinearRing, Polygon): self.assertEqual(str(cls()), cls.__name__.upper() + " EMPTY")