summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2015-12-05 19:05:52 +0500
committerClaude Paroz <claude@2xlibre.net>2015-12-18 19:44:43 +0100
commitc984e2bc15aa41de87404d6dd5d7e64f1a8e5038 (patch)
tree650a79d43e111973ab77f4c6c25524f4e20519bf /tests
parentcd3c042b0473e762b0e89bc69a9244c4a1fed66e (diff)
Fixed #25869 -- Added trim and precision properties to WKTWriter.
Diffstat (limited to 'tests')
-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'