mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #25869 -- Added trim and precision properties to WKTWriter.
This commit is contained in:
committed by
Claude Paroz
parent
cd3c042b04
commit
c984e2bc15
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user