summaryrefslogtreecommitdiff
path: root/tests/gis_tests/geos_tests/test_io.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gis_tests/geos_tests/test_io.py')
-rw-r--r--tests/gis_tests/geos_tests/test_io.py41
1 files changed, 38 insertions, 3 deletions
diff --git a/tests/gis_tests/geos_tests/test_io.py b/tests/gis_tests/geos_tests/test_io.py
index 59cb54b6b4..920767ded4 100644
--- a/tests/gis_tests/geos_tests/test_io.py
+++ b/tests/gis_tests/geos_tests/test_io.py
@@ -1,17 +1,17 @@
from __future__ import unicode_literals
import binascii
-import unittest
from unittest import skipUnless
from django.contrib.gis.geos import (
- HAS_GEOS, GEOSGeometry, WKBReader, WKBWriter, WKTReader, WKTWriter,
+ HAS_GEOS, GEOSGeometry, Point, WKBReader, WKBWriter, WKTReader, WKTWriter,
)
+from django.test import SimpleTestCase
from django.utils.six import memoryview
@skipUnless(HAS_GEOS, "Geos is required.")
-class GEOSIOTest(unittest.TestCase):
+class GEOSIOTest(SimpleTestCase):
def test01_wktreader(self):
# Creating a WKTReader instance
@@ -109,3 +109,38 @@ class GEOSIOTest(unittest.TestCase):
wkb_w.srid = True
self.assertEqual(hex3d_srid, wkb_w.write_hex(g))
self.assertEqual(wkb3d_srid, wkb_w.write(g))
+
+ def test_wkt_writer_trim(self):
+ wkt_w = WKTWriter()
+ self.assertFalse(wkt_w.trim)
+ self.assertEqual(wkt_w.write(Point(1, 1)), b'POINT (1.0000000000000000 1.0000000000000000)')
+
+ wkt_w.trim = True
+ self.assertTrue(wkt_w.trim)
+ self.assertEqual(wkt_w.write(Point(1, 1)), b'POINT (1 1)')
+ self.assertEqual(wkt_w.write(Point(1.1, 1)), b'POINT (1.1 1)')
+ self.assertEqual(wkt_w.write(Point(1. / 3, 1)), b'POINT (0.3333333333333333 1)')
+
+ wkt_w.trim = False
+ self.assertFalse(wkt_w.trim)
+ self.assertEqual(wkt_w.write(Point(1, 1)), b'POINT (1.0000000000000000 1.0000000000000000)')
+
+ def test_wkt_writer_precision(self):
+ wkt_w = WKTWriter()
+ self.assertEqual(wkt_w.precision, None)
+ self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0.3333333333333333 0.6666666666666666)')
+
+ wkt_w.precision = 1
+ self.assertEqual(wkt_w.precision, 1)
+ self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0.3 0.7)')
+
+ wkt_w.precision = 0
+ self.assertEqual(wkt_w.precision, 0)
+ self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0 1)')
+
+ wkt_w.precision = None
+ self.assertEqual(wkt_w.precision, None)
+ self.assertEqual(wkt_w.write(Point(1. / 3, 2. / 3)), b'POINT (0.3333333333333333 0.6666666666666666)')
+
+ with self.assertRaisesMessage(AttributeError, 'WKT output rounding precision must be '):
+ wkt_w.precision = 'potato'