[python-geojson] 01/04: New upstream version 2.0.0
Bas Couwenberg
sebastic at debian.org
Wed Aug 23 14:59:13 UTC 2017
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository python-geojson.
commit de135469824ced6db70380f3300c80ba9396027e
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Wed Aug 23 16:52:01 2017 +0200
New upstream version 2.0.0
---
.travis.yml | 2 +-
CHANGELOG.rst | 14 +++++++
README.rst | 75 +++++++++++++++++++----------------
geojson/__init__.py | 2 -
geojson/_version.py | 2 +-
geojson/base.py | 23 +++++++++++
geojson/feature.py | 7 ++++
geojson/geometry.py | 47 ++++++++++++++++------
geojson/validation.py | 100 -----------------------------------------------
setup.py | 2 +-
tests/test_validation.py | 58 +++++++++++++++------------
tox.ini | 2 +-
12 files changed, 159 insertions(+), 175 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index f3c75a1..6e94bff 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,8 +4,8 @@ python:
- "3.3"
- "3.4"
- "3.5"
+ - "3.6"
- "pypy"
- - "pypy3"
install:
- pip install flake8
- pip install codecov
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 9b9d4cd..f56744b 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,20 @@
Changes
=======
+2.0.0 (2017-07-28)
+------------------
+
+- Rewrite of validation mechanism (breaking change).
+
+ - https://github.com/frewsxcv/python-geojson/pull/98
+
+1.3.5 (2017-04-24)
+------------------
+
+- Changed the validator to allow elevation
+
+ - https://github.com/frewsxcv/python-geojson/pull/92
+
1.3.4 (2017-02-11)
------------------
diff --git a/README.rst b/README.rst
index ebc7ffd..f1be0e7 100644
--- a/README.rst
+++ b/README.rst
@@ -21,7 +21,7 @@ This library contains:
Installation
------------
-python-geojson is compatible with Python 2.6, 2.7, 3.2, 3.3, 3.4 and 3.5. It is listed on `PyPi as 'geojson'`_. The recommended way to install is via pip_:
+python-geojson is compatible with Python 2.6, 2.7, 3.3, 3.4, 3.5 and 3.6. It is listed on `PyPi as 'geojson'`_. The recommended way to install is via pip_:
.. code::
@@ -35,7 +35,7 @@ GeoJSON Objects
This library implements all the `GeoJSON Objects`_ described in `The GeoJSON Format Specification`_.
-.. _GeoJSON Objects: http://www.geojson.org/geojson-spec.html#geojson-objects
+.. _GeoJSON Objects: https://tools.ietf.org/html/rfc7946#section-3
Point
~~~~~
@@ -47,10 +47,10 @@ Point
>>> Point((-115.81, 37.24)) # doctest: +ELLIPSIS
{"coordinates": [-115.8..., 37.2...], "type": "Point"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/b5768a857f5598e405fa>`__. General information about Point can be found in `Section 2.1.2`_ and `Appendix A: Point`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/b5768a857f5598e405fa>`__. General information about Point can be found in `Section 3.1.2`_ and `Appendix A: Points`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.2: http://www.geojson.org/geojson-spec.html#point
-.. _Appendix A\: Point: http://www.geojson.org/geojson-spec.html#id2
+.. _Section 3.1.2: https://tools.ietf.org/html/rfc7946#section-3.1.2
+.. _Appendix A\: Points: https://tools.ietf.org/html/rfc7946#appendix-A.1
MultiPoint
~~~~~~~~~~
@@ -62,10 +62,10 @@ MultiPoint
>>> MultiPoint([(-155.52, 19.61), (-156.22, 20.74), (-157.97, 21.46)]) # doctest: +ELLIPSIS
{"coordinates": [[-155.5..., 19.6...], [-156.2..., 20.7...], [-157.9..., 21.4...]], "type": "MultiPoint"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/be02025c1eb3aa2040ee>`__. General information about MultiPoint can be found in `Section 2.1.3`_ and `Appendix A: MultiPoint`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/be02025c1eb3aa2040ee>`__. General information about MultiPoint can be found in `Section 3.1.3`_ and `Appendix A: MultiPoints`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.3: http://www.geojson.org/geojson-spec.html#multipoint
-.. _Appendix A\: MultiPoint: http://www.geojson.org/geojson-spec.html#id5
+.. _Section 3.1.3: https://tools.ietf.org/html/rfc7946#section-3.1.3
+.. _Appendix A\: MultiPoints: https://tools.ietf.org/html/rfc7946#appendix-A.4
LineString
@@ -78,10 +78,10 @@ LineString
>>> LineString([(8.919, 44.4074), (8.923, 44.4075)]) # doctest: +ELLIPSIS
{"coordinates": [[8.91..., 44.407...], [8.92..., 44.407...]], "type": "LineString"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/758563182ca49ce8e8bb>`__. General information about LineString can be found in `Section 2.1.4`_ and `Appendix A: LineString`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/758563182ca49ce8e8bb>`__. General information about LineString can be found in `Section 3.1.4`_ and `Appendix A: LineStrings`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.4: http://www.geojson.org/geojson-spec.html#linestring
-.. _Appendix A\: LineString: http://www.geojson.org/geojson-spec.html#id3
+.. _Section 3.1.4: https://tools.ietf.org/html/rfc7946#section-3.1.4
+.. _Appendix A\: LineStrings: https://tools.ietf.org/html/rfc7946#appendix-A.2
MultiLineString
~~~~~~~~~~~~~~~
@@ -96,10 +96,10 @@ MultiLineString
... ]) # doctest: +ELLIPSIS
{"coordinates": [[[3.7..., 9.2...], [-130.9..., 1.52...]], [[23.1..., -34.2...], [-1.3..., -4.6...], [3.4..., 77.9...]]], "type": "MultiLineString"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/20b6522d8242ede00bb3>`__. General information about MultiLineString can be found in `Section 2.1.5`_ and `Appendix A: MultiLineString`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/20b6522d8242ede00bb3>`__. General information about MultiLineString can be found in `Section 3.1.5`_ and `Appendix A: MultiLineStrings`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.5: http://www.geojson.org/geojson-spec.html#multilinestring
-.. _Appendix A\: MultiLineString: http://www.geojson.org/geojson-spec.html#id6
+.. _Section 3.1.5: https://tools.ietf.org/html/rfc7946#section-3.1.5
+.. _Appendix A\: MultiLineStrings: https://tools.ietf.org/html/rfc7946#appendix-A.5
Polygon
~~~~~~~
@@ -119,10 +119,10 @@ Polygon
... ]) # doctest: +ELLIPSIS
{"coordinates": [[[2.3..., 57.32...], [23.19..., -20.2...], [-120.4..., 19.1...]], [[-5.2..., 23.5...], [15.2..., -10.8...], [-20.5..., 1.5...], [-5.2..., 23.5...]]], "type": "Polygon"}
-Visualize the results of the example above `here <https://gist.github.com/frewsxcv/b2f5c31c10e399a63679>`__. General information about Polygon can be found in `Section 2.1.6`_ and `Appendix A: Polygon`_ within `The GeoJSON Format Specification`_.
+Visualize the results of the example above `here <https://gist.github.com/frewsxcv/b2f5c31c10e399a63679>`__. General information about Polygon can be found in `Section 3.1.6`_ and `Appendix A: Polygons`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.6: http://www.geojson.org/geojson-spec.html#polygon
-.. _Appendix A\: Polygon: http://www.geojson.org/geojson-spec.html#id4
+.. _Section 3.1.6: https://tools.ietf.org/html/rfc7946#section-3.1.6
+.. _Appendix A\: Polygons: https://tools.ietf.org/html/rfc7946#appendix-A.3
MultiPolygon
~~~~~~~~~~~~
@@ -137,10 +137,10 @@ MultiPolygon
... ]) # doctest: +ELLIPSIS
{"coordinates": [[[[3.7..., 9.2...], [-130.9..., 1.5...], [35.1..., 72.23...]]], [[[23.1..., -34.2...], [-1.3..., -4.6...], [3.4..., 77.9...]]]], "type": "MultiPolygon"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/e0388485e28392870b74>`__. General information about MultiPolygon can be found in `Section 2.1.7`_ and `Appendix A: MultiPolygon`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/e0388485e28392870b74>`__. General information about MultiPolygon can be found in `Section 3.1.7`_ and `Appendix A: MultiPolygons`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.7: http://www.geojson.org/geojson-spec.html#multipolygon
-.. _Appendix A\: MultiPolygon: http://www.geojson.org/geojson-spec.html#id7
+.. _Section 3.1.7: https://tools.ietf.org/html/rfc7946#section-3.1.7
+.. _Appendix A\: MultiPolygons: https://tools.ietf.org/html/rfc7946#appendix-A.6
GeometryCollection
~~~~~~~~~~~~~~~~~~
@@ -156,10 +156,10 @@ GeometryCollection
>>> GeometryCollection([my_point, my_line]) # doctest: +ELLIPSIS
{"geometries": [{"coordinates": [23.53..., -63.1...], "type": "Point"}, {"coordinates": [[-152.6..., 51.2...], [5.2..., 10.6...]], "type": "LineString"}], "type": "GeometryCollection"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/6ec8422e97d338a101b0>`__. General information about GeometryCollection can be found in `Section 2.1.8`_ and `Appendix A: GeometryCollection`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/6ec8422e97d338a101b0>`__. General information about GeometryCollection can be found in `Section 3.1.8`_ and `Appendix A: GeometryCollections`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.1.8: http://www.geojson.org/geojson-spec.html#geometry-collection
-.. _Appendix A\: GeometryCollection: http://www.geojson.org/geojson-spec.html#geometrycollection
+.. _Section 3.1.8: https://tools.ietf.org/html/rfc7946#section-3.1.8
+.. _Appendix A\: GeometryCollections: https://tools.ietf.org/html/rfc7946#appendix-A.7
Feature
~~~~~~~
@@ -179,9 +179,9 @@ Feature
>>> Feature(geometry=my_point, id=27) # doctest: +ELLIPSIS
{"geometry": {"coordinates": [-3.68..., 40.4...], "type": "Point"}, "id": 27, "properties": {}, "type": "Feature"}
-Visualize the results of the examples above `here <https://gist.github.com/frewsxcv/4488d30209d22685c075>`__. General information about Feature can be found in `Section 2.2`_ within `The GeoJSON Format Specification`_.
+Visualize the results of the examples above `here <https://gist.github.com/frewsxcv/4488d30209d22685c075>`__. General information about Feature can be found in `Section 3.2`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.2: http://geojson.org/geojson-spec.html#feature-objects
+.. _Section 3.2: https://tools.ietf.org/html/rfc7946#section-3.2
FeatureCollection
~~~~~~~~~~~~~~~~~
@@ -197,9 +197,9 @@ FeatureCollection
>>> FeatureCollection([my_feature, my_other_feature]) # doctest: +ELLIPSIS
{"features": [{"geometry": {"coordinates": [1.643..., -19.12...], "type": "Point"}, "properties": {}, "type": "Feature"}, {"geometry": {"coordinates": [-80.23..., -22.53...], "type": "Point"}, "properties": {}, "type": "Feature"}], "type": "FeatureCollection"}
-Visualize the result of the example above `here <https://gist.github.com/frewsxcv/34513be6fb492771ef7b>`__. General information about FeatureCollection can be found in `Section 2.3`_ within `The GeoJSON Format Specification`_.
+Visualize the result of the example above `here <https://gist.github.com/frewsxcv/34513be6fb492771ef7b>`__. General information about FeatureCollection can be found in `Section 3.3`_ within `The GeoJSON Format Specification`_.
-.. _Section 2.3: http://geojson.org/geojson-spec.html#feature-collection-objects
+.. _Section 3.3: https://tools.ietf.org/html/rfc7946#section-3.3
GeoJSON encoding/decoding
-------------------------
@@ -281,16 +281,25 @@ map_coords
validation
~~~~~~~~~~
-:code:`geojson.is_valid` provides validation of GeoJSON objects.
+
+:code:`is_valid` property provides simple validation of GeoJSON objects.
+
+.. code:: python
+
+ >>> import geojson
+
+ >>> obj = geojson.Point((-3.68,40.41,25.14,10.34))
+ >>> obj.is_valid
+ False
+
+:code:`errors` method provides collection of errors when validation GeoJSON objects.
.. code:: python
>>> import geojson
- >>> validation = geojson.is_valid(geojson.Point((-3.68,40.41,25.14)))
- >>> validation['valid']
- 'no'
- >>> validation['message']
+ >>> obj = geojson.Point((-3.68,40.41,25.14,10.34))
+ >>> obj.errors()
'the "coordinates" member must be a single position'
generate_random
@@ -323,5 +332,5 @@ Credits
.. _GeoJSON: http://geojson.org/
-.. _The GeoJSON Format Specification: http://www.geojson.org/geojson-spec.html
+.. _The GeoJSON Format Specification: https://tools.ietf.org/html/rfc7946
.. _\_\_geo\_interface\_\_ Specification: https://gist.github.com/sgillies/2217756
diff --git a/geojson/__init__.py b/geojson/__init__.py
index 887f9db..18d1532 100644
--- a/geojson/__init__.py
+++ b/geojson/__init__.py
@@ -5,7 +5,6 @@ from geojson.geometry import MultiLineString, MultiPoint, MultiPolygon
from geojson.geometry import GeometryCollection
from geojson.feature import Feature, FeatureCollection
from geojson.base import GeoJSON
-from geojson.validation import is_valid
from geojson._version import __version__, __version_info__
__all__ = ([dump, dumps, load, loads, GeoJSONEncoder] +
@@ -15,5 +14,4 @@ __all__ = ([dump, dumps, load, loads, GeoJSONEncoder] +
[GeometryCollection] +
[Feature, FeatureCollection] +
[GeoJSON] +
- [is_valid] +
[__version__, __version_info__])
diff --git a/geojson/_version.py b/geojson/_version.py
index 35531d9..3394157 100644
--- a/geojson/_version.py
+++ b/geojson/_version.py
@@ -1,2 +1,2 @@
-__version__ = "1.3.4"
+__version__ = "2.0.0"
__version_info__ = tuple(map(int, __version__.split(".")))
diff --git a/geojson/base.py b/geojson/base.py
index 692141f..47fda14 100644
--- a/geojson/base.py
+++ b/geojson/base.py
@@ -125,3 +125,26 @@ class GeoJSON(dict):
raise ValueError(msg)
instance = ob
return instance
+
+ @property
+ def is_valid(self):
+ return not self.errors()
+
+ def check_list_errors(self, checkFunc, lst):
+ """Validation helper function."""
+ # check for errors on each subitem, filter only subitems with errors
+ results = (checkFunc(i) for i in lst)
+ return [err for err in results if err]
+
+ def errors(self):
+ """Return validation errors (if any).
+ Implement in each subclass.
+ """
+
+ # make sure that each subclass implements it's own validation function
+ if self.__class__ != GeoJSON:
+ raise NotImplementedError(self.__class__)
+
+ # check for errors on own dict (self)
+ results = {key: obj.errors() for (key, obj) in self.iteritems()}
+ return {key: err for (key, err) in results.iteritems() if err}
diff --git a/geojson/feature.py b/geojson/feature.py
index dc9625d..260a568 100644
--- a/geojson/feature.py
+++ b/geojson/feature.py
@@ -30,6 +30,10 @@ class Feature(GeoJSON):
if geometry else None)
self["properties"] = properties or {}
+ def errors(self):
+ geo = self.get('geometry')
+ return geo.errors() if geo else None
+
class FeatureCollection(GeoJSON):
"""
@@ -46,3 +50,6 @@ class FeatureCollection(GeoJSON):
"""
super(FeatureCollection, self).__init__(**extra)
self["features"] = features
+
+ def errors(self):
+ return self.check_list_errors(lambda x: x.errors(), self.features)
diff --git a/geojson/geometry.py b/geojson/geometry.py
index 931eccd..517fe5b 100644
--- a/geojson/geometry.py
+++ b/geojson/geometry.py
@@ -2,7 +2,6 @@ import sys
from decimal import Decimal
from geojson.base import GeoJSON
-from geojson.validation import is_valid
class Geometry(GeoJSON):
@@ -30,10 +29,9 @@ class Geometry(GeoJSON):
self["coordinates"] = coordinates or []
self.clean_coordinates(self["coordinates"])
if validate:
- validation = is_valid(self)
- if validation['valid'] == 'no':
- raise ValueError('{}: {}'.format(
- validation['message'], coordinates))
+ errors = self.errors()
+ if errors:
+ raise ValueError('{}: {}'.format(errors, coordinates))
if crs:
self["crs"] = self.to_instance(crs, strict=True)
@@ -58,28 +56,55 @@ class GeometryCollection(GeoJSON):
# Marker classes.
+def check_point(coord):
+ if len(coord) not in (2, 3):
+ return 'the "coordinates" member must be a single position'
+
+
class Point(Geometry):
- pass
+ def errors(self):
+ return check_point(self['coordinates'])
class MultiPoint(Geometry):
- pass
+ def errors(self):
+ return self.check_list_errors(check_point, self['coordinates'])
+
+
+def check_line_string(coord):
+ if len(coord) < 2:
+ return ('the "coordinates" member must be an array of '
+ 'two or more positions')
class LineString(MultiPoint):
- pass
+ def errors(self):
+ return check_line_string(self['coordinates'])
class MultiLineString(Geometry):
- pass
+ def errors(self):
+ return self.check_list_errors(check_line_string, self['coordinates'])
+
+
+def check_polygon(coord):
+ lengths = all(len(elem) >= 4 for elem in coord)
+ if lengths is False:
+ return 'LinearRing must contain with 4 or more positions'
+
+ isring = all(elem[0] == elem[-1] for elem in coord)
+ if isring is False:
+ return 'The first and last positions in LinearRing must be equivalent'
class Polygon(Geometry):
- pass
+ def errors(self):
+ return check_polygon(self['coordinates'])
class MultiPolygon(Geometry):
- pass
+ def errors(self):
+ return self.check_list_errors(check_polygon, self['coordinates'])
class Default(object):
diff --git a/geojson/validation.py b/geojson/validation.py
deleted file mode 100644
index e1afa37..0000000
--- a/geojson/validation.py
+++ /dev/null
@@ -1,100 +0,0 @@
-import geojson
-
-
-def is_valid(obj):
- """ IsValid provides validation for GeoJSON objects
- All of error messages obtained from the official site
- http://geojson.org/geojson-spec.html
-
- Args:
- obj(geoJSON object): check validation
-
- Returns:
- dict of two parameters 'valid' and 'message'.
- In the case if geoJSON object is valid, returns
- {valid: 'yes', message: ''}
- If json objects is not valid, returns
- {valid: 'no', message:'explanation, why this object is not valid'}
-
- Example:
- >> point = Point((10,20), (30,40))
- >> IsValid(point)
- >> {valid: 'yes', message: ''}
- """
-
- if not isinstance(obj, geojson.GeoJSON):
- return output('this is not GeoJSON object')
-
- if isinstance(obj, geojson.Point):
- if len(obj['coordinates']) != 2:
- return output('the "coordinates" member must be a single position')
-
- if isinstance(obj, geojson.MultiPoint):
- if checkListOfObjects(obj['coordinates'], lambda x: len(x) == 2):
- return output(
- 'the "coordinates" member must be an array of positions'
- )
-
- if isinstance(obj, geojson.LineString):
- if len(obj['coordinates']) < 2:
- return output('the "coordinates" member must be an array '
- 'of two or more positions')
-
- if isinstance(obj, geojson.MultiLineString):
- coord = obj['coordinates']
- if checkListOfObjects(coord, lambda x: len(x) >= 2):
- return output('the "coordinates" member must be an array '
- 'of LineString coordinate arrays')
-
- if isinstance(obj, geojson.Polygon):
- coord = obj['coordinates']
- lengths = all([len(elem) >= 4 for elem in coord])
- if lengths is False:
- return output('LinearRing must contain with 4 or more positions')
-
- isring = all([elem[0] == elem[-1] for elem in coord])
- if isring is False:
- return output('The first and last positions in LinearRing'
- 'must be equivalent')
-
- if isinstance(obj, geojson.MultiPolygon):
- if checkListOfObjects(obj['coordinates'], lambda x: is_polygon(x)):
- return output('the "coordinates" member must be an array'
- 'of Polygon coordinate arrays')
-
- return output('')
-
-
-def is_polygon(coords):
- lengths = all(len(elem) >= 4 for elem in coords)
- isring = all(elem[0] == elem[-1] for elem in coords)
- return lengths and isring
-
-
-def checkListOfObjects(coord, pred):
- """ This method provides checking list of geojson objects such Multipoint or
- MultiLineString that each element of the list is valid geojson object.
- This is helpful method for IsValid.
-
- :param coord: List of coordinates
- :type coord: list
- :param pred: Predicate to check validation of each member in the coord
- :type pred: function
- :return: True if list contains valid objects, False otherwise
- :rtype: bool
- """
- return not isinstance(coord, list) or not all([pred(ls) for ls in coord])
-
-
-def output(message):
- """ Output result for IsValid
-
- :param message: If message is not empty, object is not valid
- :type message: str
- """
- result = {'valid': 'no', 'message': ''}
- if message != '':
- result['message'] = message
- return result
- result['valid'] = 'yes'
- return result
diff --git a/setup.py b/setup.py
index 3166430..49caf29 100644
--- a/setup.py
+++ b/setup.py
@@ -66,10 +66,10 @@ setup(
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
- "Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
+ "Programming Language :: Python :: 3.6",
"Topic :: Scientific/Engineering :: GIS",
]
)
diff --git a/tests/test_validation.py b/tests/test_validation.py
index 45d47d4..50331be 100644
--- a/tests/test_validation.py
+++ b/tests/test_validation.py
@@ -7,16 +7,12 @@ import unittest
import geojson
-is_valid = geojson.is_valid
-YES = 'yes'
-NO = 'no'
-
class TestValidationGeometry(unittest.TestCase):
def test_invalid_geometry_with_validate(self):
self.assertRaises(
- ValueError, geojson.Point, (10, 20, 30), validate=True)
+ ValueError, geojson.Point, (10, 20, 30, 40), validate=True)
def test_invalid_geometry_without_validate(self):
try:
@@ -32,63 +28,75 @@ class TestValidationGeometry(unittest.TestCase):
except ValueError:
self.fail("Point raised ValueError unexpectedly")
+ def test_valid_geometry_with_elevation(self):
+ try:
+ geojson.Point((10, 20, 30), validate=True)
+ geojson.Point((10, 20, 30), validate=False)
+ except ValueError:
+ self.fail("Point raised ValueError unexpectedly")
-class TestValidationGeoJSONObject(unittest.TestCase):
- def test_invalid_jsonobject(self):
- obj = [1, 2, 3]
- self.assertEqual(is_valid(obj)['valid'], NO)
+class TestValidationGeoJSONObject(unittest.TestCase):
def test_valid_jsonobject(self):
point = geojson.Point((-10.52, 2.33))
- self.assertEqual(is_valid(point)['valid'], YES)
+ self.assertEqual(point.is_valid, True)
class TestValidationPoint(unittest.TestCase):
def test_invalid_point(self):
- point = geojson.Point((10, 20, 30))
- self.assertEqual(is_valid(point)['valid'], NO)
+ point = geojson.Point((10, 20, 30, 40))
+ self.assertEqual(point.is_valid, False)
def test_valid_point(self):
point = geojson.Point((-3.68, 40.41))
- self.assertEqual(is_valid(point)['valid'], YES)
+ self.assertEqual(point.is_valid, True)
+
+ def test_valid_point_with_elevation(self):
+ point = geojson.Point((-3.68, 40.41, 3.45))
+ self.assertEqual(point.is_valid, True)
class TestValidationMultipoint(unittest.TestCase):
def test_invalid_multipoint(self):
mpoint = geojson.MultiPoint(
- [(3.5887, 10.44558), (2.5555, 3.887), (2.44, 3.44, 2.555)])
- self.assertEqual(is_valid(mpoint)['valid'], NO)
+ [(3.5887,), (3.5887, 10.44558),
+ (2.5555, 3.887, 4.56), (2.44, 3.44, 2.555, 4.56)])
+ self.assertEqual(mpoint.is_valid, False)
def test_valid_multipoint(self):
mpoint = geojson.MultiPoint([(10, 20), (30, 40)])
- self.assertEqual(is_valid(mpoint)['valid'], YES)
+ self.assertEqual(mpoint.is_valid, True)
+
+ def test_valid_multipoint_with_elevation(self):
+ mpoint = geojson.MultiPoint([(10, 20, 30), (30, 40, 50)])
+ self.assertEqual(mpoint.is_valid, True)
class TestValidationLineString(unittest.TestCase):
def test_invalid_linestring(self):
ls = geojson.LineString([(8.919, 44.4074)])
- self.assertEqual(is_valid(ls)['valid'], NO)
+ self.assertEqual(ls.is_valid, False)
def test_valid_linestring(self):
ls = geojson.LineString([(10, 5), (4, 3)])
- self.assertEqual(is_valid(ls)['valid'], YES)
+ self.assertEqual(ls.is_valid, True)
class TestValidationMultiLineString(unittest.TestCase):
def test_invalid_multilinestring(self):
mls = geojson.MultiLineString([[(10, 5), (20, 1)], []])
- self.assertEqual(is_valid(mls)['valid'], NO)
+ self.assertEqual(mls.is_valid, False)
def test_valid_multilinestring(self):
ls1 = [(3.75, 9.25), (-130.95, 1.52)]
ls2 = [(23.15, -34.25), (-1.35, -4.65), (3.45, 77.95)]
mls = geojson.MultiLineString([ls1, ls2])
- self.assertEqual(is_valid(mls)['valid'], YES)
+ self.assertEqual(mls.is_valid, True)
class TestValidationPolygon(unittest.TestCase):
@@ -96,17 +104,17 @@ class TestValidationPolygon(unittest.TestCase):
def test_invalid_polygon(self):
poly1 = geojson.Polygon(
[[(2.38, 57.322), (23.194, -20.28), (-120.43, 19.15)]])
- self.assertEqual(is_valid(poly1)['valid'], NO)
+ self.assertEqual(poly1.is_valid, False)
poly2 = geojson.Polygon(
[[(2.38, 57.322), (23.194, -20.28),
(-120.43, 19.15), (2.38, 57.323)]])
- self.assertEqual(is_valid(poly2)['valid'], NO)
+ self.assertEqual(poly2.is_valid, False)
def test_valid_polygon(self):
poly = geojson.Polygon(
[[(2.38, 57.322), (23.194, -20.28),
(-120.43, 19.15), (2.38, 57.322)]])
- self.assertEqual(is_valid(poly)['valid'], YES)
+ self.assertEqual(poly.is_valid, True)
class TestValidationMultiPolygon(unittest.TestCase):
@@ -117,7 +125,7 @@ class TestValidationMultiPolygon(unittest.TestCase):
poly2 = [(2.38, 57.322), (23.194, -20.28),
(-120.43, 19.15), (2.38, 57.322)]
multipoly = geojson.MultiPolygon([poly1, poly2])
- self.assertEqual(is_valid(multipoly)['valid'], NO)
+ self.assertEqual(multipoly.is_valid, False)
def test_valid_multipolygon(self):
poly1 = [[(2.38, 57.322), (23.194, -20.28),
@@ -127,4 +135,4 @@ class TestValidationMultiPolygon(unittest.TestCase):
poly3 = [[(3.14, 23.17), (51.34, 27.14),
(22, -18.11), (3.14, 23.17)]]
multipoly = geojson.MultiPolygon([poly1, poly2, poly3])
- self.assertEqual(is_valid(multipoly)['valid'], YES)
+ self.assertEqual(multipoly.is_valid, True)
diff --git a/tox.ini b/tox.ini
index e4608b3..767887a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,7 +4,7 @@
# and then run "tox" from this directory.
[tox]
-envlist = py{27,33,34,35}, pypy, pypy3
+envlist = py{27,33,34,35,36}, pypy, pypy3
[testenv]
commands = {envpython} setup.py test
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-geojson.git
More information about the Pkg-grass-devel
mailing list