Changeset 1054

Show
Ignore:
Timestamp:
02/26/08 14:34:38
Author:
mattrussell
Message:

- Made all code work with Python 2.4.3, 2.5.1, will test with all variations.

(see tests/rundoctests.dist)

- Made tests use ELLIPSIS to avoid output transmogification due to floating point representation.


Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • GeoJSON/trunk/CHANGES.txt

    r1040 r1054  
    33 
    44 
     5- Made all code work with Python 2.4.3, 2.5.1, will test with all variations. 
     6  (see tests/rundoctests.dist) 
    57 
    6 - Added respresentations of the default GeoJSON types in feauture.py and 
    7   geometry.py 
    8 - input to {dumps,dump} must be 'mapping' like objects or support __geo_interface__ 
    9 - default geometry crs of EPSG 4326 will added if none provided 
    10 - Can use geojson.<type> to implement a __geo_interface__ 
    11 - Can nest a geometry object anywhere in a json structure (see doctests including_additional_members.txt) 
    12 - Can encode and decode geojson.<type> objects in addition to mappings  
    13 - Better error reporting if incorrect geojson type specified. 
    14 - Added additional doc-tests for FeatureColletions and object API. 
    15  
    16  
     8- Made tests use ELLIPSIS to avoid output transmogification due to floating point representation.  
    179   
    18 Last-Modified: MattRussell 25/01/2008 
     10Last-Modified: MattRussell 26/02/2008 
  • GeoJSON/trunk/geojson/base.py

    r1040 r1054  
    5454                geojson_factory = getattr(geojson, type_) 
    5555                if not issubclass(geojson_factory, GeoJSON): 
    56                     raise TypeError("Not a valid GeoJSON type: %r (geojson_factory: %r, cls: %r)" % (type_, geojson_factory, cls)) 
     56                    raise TypeError("""\ 
     57                    Not a valid GeoJSON type: 
     58                    %r (geojson_factory: %r, cls: %r) 
     59                    """ % (type_, geojson_factory, cls)) 
    5760                instance = geojson_factory(**d) 
    5861            except (AttributeError, KeyError), invalid: 
  • GeoJSON/trunk/geojson/crs.py

    r1040 r1054  
    88    def __init__(self, properties=None, **extra): 
    99        super(CoordinateReferenceSystem, self).__init__(**extra) 
    10         self.properties = properties if properties else {} 
     10        self.properties = properties or {} 
    1111 
    1212    @property 
     
    2121    def __init__(self, properties=None, **extra): 
    2222        super(EPSG, self).__init__(**extra) 
    23         self.properties = properties if properties else {"code": 4326} 
     23        self.properties = properties or {"code": 4326} 
  • GeoJSON/trunk/geojson/feature.py

    r1040 r1054  
    2323        self.id = id 
    2424        self.geometry = self.to_instance(geometry, strict=True) 
    25         if properties is None: 
    26             properties = {} 
    27         self.properties = properties  
     25        self.properties = properties or {} 
    2826 
    2927    @property 
  • GeoJSON/trunk/geojson/geometry.py

    r1040 r1054  
    1  
    21from geojson.base import GeoJSON 
    32import geojson.crs  
     
    2019        d.update(coordinates=self.coordinates, crs=crs) 
    2120        return d 
     21 
    2222 
    2323class GeometryCollection(GeoJSON): 
     
    5959class MultiPolygon(Geometry): pass 
    6060 
    61            
  • GeoJSON/trunk/tests/blog.txt

    r935 r1054  
    33 
    44 
    5    >>> d = {"blog": {"posts": [{"atom:summary": "post 1", "type": "atom:item", "atom:description": "i love blogging"}, {"atom:summary": "post 2 from CA", "type": "atom:item", "location": {"type": "Point", "coordinates": [-120, 40]}, "atom:description": "geoblogging in California"}], "location": {"type": "Polygon", "coordinates": [[[-121, 39], [-119, 39], [-119, 41], [-121, 41], [-121, 39]]]}}} 
     5   >>> d = {"blog": {"posts": [{"atom:summary": "post 1", "type": "atom:item", "atom:description": "i love blogging"}, {"atom:summary": "post 2 from CA", "type": "atom:item", "location": {"type": "Point", "coordinates": [-120.2138, 40.1231]}, "atom:description": "geoblogging in California"}], "location": {"type": "Polygon", "coordinates": [[[-121.5627, 39.8173], [-119.5221, 39.8173], [-119.1232, 41.1231], [-121.5632, 41.3321], [-121.2156, 39.8103]]]}}} 
    66 
    77  >>> import geojson 
     
    1010 
    1111  >>> json = geojson.dumps(d) 
    12   >>> json 
    13   '{"blog": {"posts": [{"atom:summary": "post 1", "type": "atom:item", "atom:description": "i love blogging"}, {"atom:summary": "post 2 from CA", "type": "atom:item", "location": {"type": "Point", "coordinates": [-120, 40]}, "atom:description": "geoblogging in California"}], "location": {"type": "Polygon", "coordinates": [[[-121, 39], [-119, 39], [-119, 41], [-121, 41], [-121, 39]]]}}}' 
     12  >>> json # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE  
     13  '{"blog": {"posts": [{"atom:summary": "post 1", "type": "atom:item", "atom:description": "i love blogging"}, {"atom:summary": "post 2 from CA", "type": "atom:item", "location": {"type": "Point", "coordinates": [-120..., 40...]}, "atom:description": "geoblogging in California"}], "location": {"type": "Polygon", "coordinates": [[[-121..., 39...], [-119..., 39...], [-119..., 41...], [-121..., 41...], [-121..., 39...]]]}}}' 
    1414 
    1515  Decoding 
     
    1818  >>> type(o) 
    1919  <type 'dict'> 
    20   >>> o 
    21   {u'blog': {u'posts': [{u'atom:summary': u'post 1', u'type': u'atom:item', u'atom:description': u'i love blogging'}, {u'atom:summary': u'post 2 from CA', u'type': u'atom:item', u'location': {u'type': u'Point', u'coordinates': [-120, 40]}, u'atom:description': u'geoblogging in California'}], u'location': {u'type': u'Polygon', u'coordinates': [[[-121, 39], [-119, 39], [-119, 41], [-121, 41], [-121, 39]]]}}} 
     20  >>> o # doctest: +ELLIPSIS  
     21  {u'blog': {u'posts': [{u'atom:summary': u'post 1', u'type': u'atom:item', u'atom:description': u'i love blogging'}, {u'atom:summary': u'post 2 from CA', u'type': u'atom:item', u'location': {u'type': u'Point', u'coordinates': [-120..., 40...]}, u'atom:description': u'geoblogging in California'}], u'location': {u'type': u'Polygon', u'coordinates': [[[-121..., 39...], [-119..., 39...], [-119..., 41...], [-121..., 41...], [-121..., 39...]]]}}} 
    2222 
  • GeoJSON/trunk/tests/c2c_features.txt

    r1040 r1054  
    2727  ...                } 
    2828 
    29   >>> from shapely.geometry import Point 
    30   >>> f = Feature(12, Point(9, 5), foo='bar') 
     29  >>> class Point(object): 
     30  ...    """Mock shapely point.""" 
     31  ...    def __init__(self, x, y): 
     32  ...        self.x = x; self.y = y 
     33  ...    @property 
     34  ...    def __geo_interface__(self): 
     35  ...        return dict(type="Point", coordinates=[self.x, self.y]) 
     36 
     37  >>> f = Feature(12, Point(49.132323, 55.341411), foo='bar') 
    3138  >>> import geojson 
    32   >>> geojson.dumps(f) 
    33   '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [9.0, 5.0]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}' 
     39  >>> geojson.dumps(f) # doctest: +ELLIPSIS  
     40  '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [49..., 55...]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}' 
    3441  >>> c = FeatureCollection([f]) 
    35   >>> geojson.dumps(c) 
    36   '{"type": "FeatureCollection", "features": [{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [9.0, 5.0]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}]}' 
     42  >>> geojson.dumps(c) # doctest: +ELLIPSIS 
     43  '{"type": "FeatureCollection", "features": [{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [49..., 55...]}, "type": "Feature", "properties": {"foo": "bar"}, "id": 12}]}' 
  • GeoJSON/trunk/tests/featurecollection.txt

    r1040 r1054  
    1010  ...                      "id": "1", 
    1111  ...                      "geometry": {"type": "Point", 
    12   ...                                   "coordinates": [0, 1]}}]} 
     12  ...                                   "coordinates": [44.556, 67.192]}}]} 
    1313 
    1414 
     
    1717  >>> import geojson 
    1818  >>> json = geojson.dumps(fc) 
    19   >>> json 
    20   '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [0, 1]}, "type": "Feature", "id": "1"}]}' 
     19  >>> json  # doctest: +ELLIPSIS 
     20  '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [44..., 67...]}, "type": "Feature", "id": "1"}]}' 
    2121 
    2222  Decoding 
    2323   
    2424  >>> fcb = geojson.loads(json) 
    25   >>> fcb 
    26   {u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'Point', u'coordinates': [0, 1]}, u'type': u'Feature', u'id': u'1'}]} 
     25  >>> fcb  # doctest: +ELLIPSIS 
     26  {u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'Point', u'coordinates': [44..., 67...]}, u'type': u'Feature', u'id': u'1'}]} 
    2727 
    2828 
     
    3030----------------------------------------------------------- 
    3131   
    32   >>> features = [geojson.Feature(id=1, geometry=geojson.Point(coordinates=(0, 1)))] 
     32  >>> features = [geojson.Feature(id=1, geometry=geojson.Point(coordinates=(53.04781795911469, -4.10888671875)))] 
    3333  >>> fco = geojson.FeatureCollection(features=features) 
    34   >>> fco.features 
    35   [Feature(geometry={'crs': {'type': 'EPSG', 'properties': {'code': 4326}}, 'type': 'Point', 'coordinates': (0, 1)}, properties={}, id=1)] 
     34  >>> fco.features  # doctest: +ELLIPSIS 
     35  [Feature(geometry={'crs': {'type': 'EPSG', 'properties': {'code': 4326}}, 'type': 'Point', 'coordinates': (53..., -4...)}, properties={}, id=1)] 
    3636 
    3737 
     
    3939 
    4040  >>> json = geojson.dumps(fco) 
    41   >>> json 
    42   '{"type": "FeatureCollection", "features": [{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [0, 1]}, "type": "Feature", "properties": {}, "id": 1}]}' 
     41  >>> json  # doctest: +ELLIPSIS 
     42  '{"type": "FeatureCollection", "features": [{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [53..., -4...]}, "type": "Feature", "properties": {}, "id": 1}]}' 
    4343 
    4444   
     
    4747  >>> hook = lambda ob: geojson.GeoJSON.to_instance(ob, geojson.feature) 
    4848  >>> fc = geojson.loads(json, object_hook=hook) 
    49   >>> fc.features 
    50   [Feature(geometry={'crs': {'type': 'EPSG', 'properties': {u'code': 4326}}, 'type': 'Point', 'coordinates': [0, 1]}, properties={}, id=1)] 
     49  >>> fc.features  # doctest: +ELLIPSIS 
     50  [Feature(geometry={'crs': {'type': 'EPSG', 'properties': {u'code': 4326}}, 'type': 'Point', 'coordinates': [53..., -4...]}, properties={}, id=1)] 
    5151   
    52   >>> fc.features[0].geometry 
    53   Point(crs={'type': 'EPSG', 'properties': {u'code': 4326}}, coordinates=[0, 1]) 
     52  >>> fc.features[0].geometry  # doctest: +ELLIPSIS 
     53  Point(crs={'type': 'EPSG', 'properties': {u'code': 4326}}, coordinates=[53..., -4...]) 
    5454 
    5555  >>> geometry = fc.features[0].geometry 
    56   >>> geometry.coordinates 
    57   [0, 1
    58   >>>  
     56  >>> geometry.coordinates  # doctest: +ELLIPSIS 
     57  [53..., -4...
     58  
    5959 
     60- It may be used from any object, consider: 
     61 
     62  >>> class Point(object): 
     63  ...     """Mock shapely point.""" 
     64  ...     def __init__(self, x, y): 
     65  ...         self.x = x 
     66  ...         self.y = y 
     67  ...     @property 
     68  ...     def __geo_interface__(self): 
     69  ...         return geojson.Point(coordiantes=[self.x, self.y]) 
     70 
     71  >>> p = Point(53.04781795911469, -4.10888671875) 
     72  >>> geojson.dumps(p)  # doctest: +ELLIPSIS 
     73  '{"type": "Point", "coordiantes": [53..., -4...], "coordinates": [], "crs": {"type": "EPSG", "properties": {"code": 4326}}}' 
  • GeoJSON/trunk/tests/features.txt

    r1040 r1054  
    88  ...   'type': 'Feature', 
    99  ...   'id': '1', 
    10   ...   'geometry': {'type': 'Point', 'coordinates': [0, 0]}, 
     10  ...   'geometry': {'type': 'Point', 'coordinates': [53.04781795911469, -4.10888671875]}, 
    1111  ...   'properties': {'title': 'Dict 1'}, 
    1212  ... } 
     
    1717 
    1818  >>> json = geojson.dumps(f) 
    19   >>> json 
    20   '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [0, 0]}, "type": "Feature", "properties": {"title": "Dict 1"}, "id": "1"}' 
     19  >>> json  # doctest: +ELLIPSIS 
     20  '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [53..., -4...]}, "type": "Feature", "properties": {"title": "Dict 1"}, "id": "1"}' 
    2121 
    2222  Decoding 
    2323 
    2424  >>> o = geojson.loads(json) 
    25   >>> o 
    26   {u'geometry': {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [0, 0]}, u'type': u'Feature', u'properties': {u'title': u'Dict 1'}, u'id': u'1'} 
     25  >>> o  # doctest: +ELLIPSIS 
     26  {u'geometry': {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [53..., -4...]}, u'type': u'Feature', u'properties': {u'title': u'Dict 1'}, u'id': u'1'} 
    2727 
    2828 
     
    3232  >>> from geojson.examples import SimpleWebFeature 
    3333  >>> feature = SimpleWebFeature(id='1', 
    34   ...             geometry={'type': 'Point', 'coordinates': [0.0, 0.0]}, 
     34  ...             geometry={'type': 'Point', 'coordinates': [53.04781795911469, -4.10888671875]}, 
    3535  ...             title=u'Feature 1', summary=u'The first feature', 
    3636  ...             link='http://example.org/features/1') 
     
    4646  >>> feature.properties['link'] 
    4747  'http://example.org/features/1' 
    48   >>> feature.geometry 
    49   {'type': 'Point', 'coordinates': [0.0, 0.0]} 
     48  >>> feature.geometry  # doctest: +ELLIPSIS 
     49  {'type': 'Point', 'coordinates': [53..., -4...]} 
    5050 
    5151  Encoding 
    5252 
    53   >>> geojson.dumps(feature) 
    54   '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [0.0, 0.0]}, "type": "Feature", "properties": {"summary": "The first feature", "link": "http:\\/\\/example.org\\/features\\/1", "title": "Feature 1"}, "id": "1"}' 
     53  >>> geojson.dumps(feature)  # doctest: +ELLIPSIS 
     54  '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [53..., -4...]}, "type": "Feature", "properties": {"summary": "The first feature", "link": "http:\\/\\/example.org\\/features\\/1", "title": "Feature 1"}, "id": "1"}' 
    5555 
    5656  Decoding 
    5757 
    58   >>> factory = geojson.examples.createSimpleWebFeature 
    59   >>> json = '{"geometry": {"type": "Point", "coordinates": [0.0, 0.0]}, "id": "1", "properties": {"summary": "The first feature", "link": "http:\\/\\/example.org\\/features\\/1", "title": "Feature 1"}}' 
     58  >>> factory = geojson.examples.createSimpleWebFeature  
     59  >>> json = '{"geometry": {"type": "Point", "coordinates": [53.04781795911469, -4.10888671875]}, "id": "1", "properties": {"summary": "The first feature", "link": "http:\\/\\/example.org\\/features\\/1", "title": "Feature 1"}}' 
    6060  >>> feature = geojson.loads(json, object_hook=factory) 
    6161  >>> type(feature) 
     
    6969  >>> feature.properties['link'] 
    7070  'http://example.org/features/1' 
    71   >>> feature.geometry 
    72   {'type': 'Point', 'coordinates': [0.0, 0.0]} 
     71  >>> feature.geometry  # doctest: +ELLIPSIS 
     72  {'type': 'Point', 'coordinates': [53..., -4...]} 
    7373 
    7474Test the geo interface 
     
    8686 
    8787  >>> ob = Thingy('1', 'thingy one', -106.0, 40.0) 
    88   >>> ob.__geo_interface__['geometry'] 
    89   {'type': 'Point', 'coordinates': (-106.0, 40.0)} 
    90   >>> geojson.dumps(ob) 
    91   '{"geometry": {"type": "Point", "coordinates": [-106.0, 40.0]}, "id": "1", "properties": {"title": "thingy one"}}' 
     88  >>> ob.__geo_interface__['geometry']  # doctest: +ELLIPSIS 
     89  {'type': 'Point', 'coordinates': (-106..., 40...)} 
     90  >>> geojson.dumps(ob)  # doctest: +ELLIPSIS 
     91  '{"geometry": {"type": "Point", "coordinates": [-106..., 40...]}, "id": "1", "properties": {"title": "thingy one"}}' 
  • GeoJSON/trunk/tests/geometry.txt

    r1040 r1054  
    1717 
    1818  >>> json = geojson.dumps(g) 
    19   >>> json 
    20   '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [1.3, -54.23242]}' 
     19  >>> json # doctest: +ELLIPSIS 
     20  '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [1..., -54...]}' 
    2121 
    2222  Decoding 
    2323 
    2424  >>> o = geojson.loads(json) 
    25   >>> o 
    26   {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [1.3, -54.232419999999998]} 
     25  >>> o # doctest: +ELLIPSIS 
     26  {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [1..., -54...]} 
    2727 
    2828 
     
    3232  >>> ls = geojson.geometry.LineString(((52.1, -34.131), (65.231, -34.234)), crs=geojson.crs.EPSG()) 
    3333 
    34   >>> ls.__geo_interface__ 
    35   {'crs': {'type': 'EPSG', 'properties': {'code': 4326}}, 'type': 'LineString', 'coordinates': ((52.100000000000001, -34.131), (65.230999999999995, -34.234000000000002))} 
     34  >>> ls.__geo_interface__ # doctest: +ELLIPSIS 
     35  {'crs': {'type': 'EPSG', 'properties': {'code': 4326}}, 'type': 'LineString', 'coordinates': ((52.100000000000001, -34.131), (65..., -34...))} 
    3636 
    3737  >>> ls.type 
    3838  'LineString' 
    39   >>> ls.coordinates 
    40   ((52.100000000000001, -34.131), (65.230999999999995, -34.234000000000002)) 
     39  >>> ls.coordinates # doctest: +ELLIPSIS 
     40  ((52..., -34...), (65..., -34...)) 
    4141 
    4242  Encoding 
    4343 
    4444  >>> json = geojson.dumps(ls) 
    45   >>> json 
    46   '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "LineString", "coordinates": [[52.1, -34.131], [65.231, -34.234]]}' 
     45  >>> json # doctest: +ELLIPSIS 
     46  '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "LineString", "coordinates": [[52..., -34...], [65..., -34...]]}' 
    4747 
    4848  Decoding 
    49   >>> geojson.loads(json) 
    50   {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'LineString', u'coordinates': [[52.100000000000001, -34.131], [65.230999999999995, -34.234000000000002]]} 
     49  >>> geojson.loads(json) # doctest: +ELLIPSIS 
     50  {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'LineString', u'coordinates': [[52..., -34...], [65..., -34...]]} 
    5151 
    5252  >>> factory = lambda o: geojson.GeoJSON.to_instance(o, geojson.geometry) 
     
    5656  >>> geom.type 
    5757  'LineString' 
    58   >>> geom.coordinates 
    59   [[52.100000000000001, -34.131], [65.230999999999995, -34.234000000000002]] 
     58  >>> geom.coordinates # doctest: +ELLIPSIS 
     59  [[52..., -34...], [65..., -34...]] 
    6060 
    6161 
     
    6868  >>> ls = geojson.geometry.LineString(coords, crs=EPSG(properties=dict(code=2423))) 
    6969 
    70   >>> ls.__geo_interface__ 
    71   {'crs': {'type': 'EPSG', 'properties': {'code': 2423}}, 'type': 'LineString', 'coordinates': ((-1918145.0108183471, -4098018.9166399641), (-680004.67204747663, -3864394.3196185972))} 
     70  >>> ls.__geo_interface__ # doctest: +ELLIPSIS 
     71  {'crs': {'type': 'EPSG', 'properties': {'code': 2423}}, 'type': 'LineString', 'coordinates': ((-1918145..., -4098018...), (-680004..., -3864394...))} 
    7272 
    7373  It satisfies the geometry protocol 
    7474 
    7575  >>> json = geojson.dumps(ls) 
    76   >>> json 
    77   '{"crs": {"type": "EPSG", "properties": {"code": 2423}}, "type": "LineString", "coordinates": [[-1918145.01082, -4098018.91664], [-680004.672047, -3864394.31962]]}' 
     76  >>> json # doctest: +ELLIPSIS 
     77  '{"crs": {"type": "EPSG", "properties": {"code": 2423}}, "type": "LineString", "coordinates": [[-1918145..., -4098018...], [-680004..., -3864394...]]}' 
    7878 
    7979  Decoding 
    80   >>> geojson.loads(json) 
    81   {u'crs': {u'type': u'EPSG', u'properties': {u'code': 2423}}, u'type': u'LineString', u'coordinates': [[-1918145.01082, -4098018.91664], [-680004.67204700003, -3864394.3196200002]]} 
     80  >>> geojson.loads(json) # doctest: +ELLIPSIS 
     81  {u'crs': {u'type': u'EPSG', u'properties': {u'code': 2423}}, u'type': u'LineString', u'coordinates': [[-1918145..., -4098018...], [-680004..., -3864394...]]} 
    8282  
    8383 
     
    8888  >>> geom.type 
    8989  'LineString' 
    90   >>> geom.coordinates 
    91   [[-1918145.01082, -4098018.91664], [-680004.67204700003, -3864394.3196200002]] 
     90  >>> geom.coordinates # doctest: +ELLIPSIS 
     91  [[-1918145..., -4098018...], [-680004..., -3864394...]] 
    9292  
    9393 
     
    100100  >>> ls = geojson.geometry.LineString(coords, crs=EPSG(properties=dict(code=2423))) 
    101101 
    102   >>> ls.__geo_interface__ 
    103   {'crs': {'type': 'EPSG', 'properties': {'code': 2423}}, 'type': 'LineString', 'coordinates': ((-1918145.0108183471, -4098018.9166399641), (-680004.67204747663, -3864394.3196185972))} 
     102  >>> ls.__geo_interface__ # doctest: +ELLIPSIS 
     103  {'crs': {'type': 'EPSG', 'properties': {'code': 2423}}, 'type': 'LineString', 'coordinates': ((-1918145..., -4098018...), (-680004..., -3864394...))} 
    104104 
    105105  It satisfies the geometry protocol 
     
    108108  >>> ls.type 
    109109  'LineString' 
    110   >>> ls.coordinates 
    111   ((-1918145.0108183471, -4098018.9166399641), (-680004.67204747663, -3864394.3196185972)) 
     110  >>> ls.coordinates # doctest: +ELLIPSIS 
     111  ((-1918145..., -4098018...), (-680004..., -3864394...)) 
    112112 
    113113  Encoding 
    114114 
    115115  >>> json = geojson.dumps(ls) 
    116   >>> json 
    117   '{"crs": {"type": "EPSG", "properties": {"code": 2423}}, "type": "LineString", "coordinates": [[-1918145.01082, -4098018.91664], [-680004.672047, -3864394.31962]]}' 
     116  >>> json # doctest: +ELLIPSIS 
     117  '{"crs": {"type": "EPSG", "properties": {"code": 2423}}, "type": "LineString", "coordinates": [[-1918145..., -4098018...], [-680004..., -3864394...]]}' 
    118118 
    119119  Decoding 
    120   >>> geojson.loads(json) 
    121   {u'crs': {u'type': u'EPSG', u'properties': {u'code': 2423}}, u'type': u'LineString', u'coordinates': [[-1918145.01082, -4098018.91664], [-680004.67204700003, -3864394.3196200002]]} 
     120  >>> geojson.loads(json)  # doctest: +ELLIPSIS 
     121  {u'crs': {u'type': u'EPSG', u'properties': {u'code': 2423}}, u'type': u'LineString', u'coordinates': [[-1918145..., -4098018...], [-680004..., -3864394...]]} 
    122122  
    123123  >>> factory = lambda o: geojson.GeoJSON.to_instance(o, geojson.geometry) 
     
    127127  >>> geom.type 
    128128  'LineString' 
    129   >>> geom.coordinates 
    130   [[-1918145.01082, -4098018.91664], [-680004.67204700003, -3864394.3196200002]] 
     129  >>> geom.coordinates  # doctest: +ELLIPSIS 
     130  [[-1918145..., -4098018...], [-680004..., -3864394...]] 
    131131  
    132132 
     
    143143 
    144144  >>> ob = PointThingy(-106.0, 40.0) 
    145   >>> ob.__geo_interface__['coordinates'] 
    146   (-106.0, 40.0
    147   >>> geojson.dumps(ob) 
    148   '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [-106.0, 40.0]}' 
     145  >>> ob.__geo_interface__['coordinates']  # doctest: +ELLIPSIS 
     146  (-106..., 40...
     147  >>> geojson.dumps(ob)  # doctest: +ELLIPSIS 
     148  '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [-106..., 40...]}' 
  • GeoJSON/trunk/tests/including_additional_members.txt

    r1040 r1054  
    5454  >>> json = geojson.dumps(r) 
    5555   
    56   >>> json 
    57   '{"description": "A nice bike ride around some mountains", "title": "Snowdonia circular", "geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "LineString", "coordinates": [[1.0, 2.0], [2.0, 3.2]]}, "type": "Feature", "properties": {}, "id": null}' 
     56  >>> json  # doctest: +ELLIPSIS 
     57  '{"description": "A nice bike ride around some mountains", "title": "Snowdonia circular", "geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "LineString", "coordinates": [[1..., 2...], [2..., 3...]]}, "type": "Feature", "properties": {}, "id": null}' 
    5858 
    59   >>> r = geojson.loads(json) 
    60   >>> r 
    61   {u'description': u'A nice bike ride around some mountains', u'title': u'Snowdonia circular', u'geometry': {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'LineString', u'coordinates': [[1.0, 2.0], [2.0, 3.2000000000000002]]}, u'id': None, u'type': u'Feature', u'properties': {}} 
     59  >>> r = geojson.loads(json)  
     60  >>> r # doctest: +ELLIPSIS 
     61  {u'description': u'A nice bike ride around some mountains', u'title': u'Snowdonia circular', u'geometry': {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'LineString', u'coordinates': [[1..., 2...], [2..., 3...]]}, u'id': None, u'type': u'Feature', u'properties': {}} 
    6262 
  • GeoJSON/trunk/tests/objects.txt

    r1040 r1054  
    1919 
    2020  >>> json = geojson.dumps(lat_lon) 
    21   >>> json 
    22   '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [4.53242, -54.1231]}' 
     21  >>> json # doctest: +ELLIPSIS 
     22  '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [4..., -54...]}' 
    2323 
    2424  Objects with a __geo_interface__ attribute or property can be nested in geojson feature: 
     
    2929 
    3030  >>> json = geojson.dumps(f) 
    31   >>> json 
    32   '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [4.53242, -54.1231]}, "type": "Feature", "properties": {}, "id": null}' 
     31  >>> json # doctest: +ELLIPSIS 
     32  '{"geometry": {"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [4..., -54...]}, "type": "Feature", "properties": {}, "id": null}' 
    3333 
    3434  geojson types can be used to implemented a __geo_interface__: 
     
    5050  >>> ll2 = LatLon2(-54.1231, 4.53242) 
    5151  >>> json2 = geojson.dumps(ll2) 
    52   >>> json2 
    53   '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [4.53242, -54.1231]}' 
     52  >>> json2 # doctest: +ELLIPSIS 
     53  '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [4..., -54...]}' 
    5454   
    5555 
     
    5858 
    5959  >>> feature_dict = geojson.loads(json) 
    60   >>> print feature_dict 
    61   {u'geometry': {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [4.5324200000000001, -54.123100000000001]}, u'type': u'Feature', u'properties': {}, u'id': None} 
     60  >>> feature_dict # doctest: +ELLIPSIS 
     61  {u'geometry': {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [4..., -54...]}, u'type': u'Feature', u'properties': {}, u'id': None} 
    6262 
    63     - or to an object, via a factory. Here we'll create GeoJSON object. 
     63  - or to an object, via a factory. Here we'll create GeoJSON object. 
    6464 
    65   >>> ll2 = LatLon2(1,1)  
    66   >>> json = geojson.dumps(ll2) 
    67   >>> json 
    68   '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [1, 1]}' 
    69   >>> geojson.loads(json) 
    70   {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [1, 1]} 
     65  >>> ll2 = LatLon2(43.3,-154.1)  
     66  >>> json = geojson.dumps(ll2)  
     67  >>> json # doctest: +ELLIPSIS 
     68  '{"crs": {"type": "EPSG", "properties": {"code": 4326}}, "type": "Point", "coordinates": [-154..., 43...]}' 
     69   
     70  >>> geojson.loads(json) # doctest: +ELLIPSIS 
     71  {u'crs': {u'type': u'EPSG', u'properties': {u'code': 4326}}, u'type': u'Point', u'coordinates': [-154..., 43...]} 
     72   
    7173  >>> factory = lambda ob: geojson.GeoJSON.to_instance(ob) 
    7274  >>> geometry = geojson.loads(json, object_hook=factory) 
    73   >>> geometry   
    74   Point(crs={'type': 'EPSG', 'properties': {u'code': 4326}}, coordinates=[1, 1]) 
     75  >>> geometry  # doctest: +ELLIPSIS      
     76  Point(crs={'type': 'EPSG', 'properties': {u'code': 4326}}, coordinates=[-154..., 43...]) 
    7577 
    7678  
  • GeoJSON/trunk/tests/runalldoctests.py

    r935 r1054  
    66try: 
    77    import pkg_resources 
    8     pkg_resources.require('PCL-GeoJSON'
     8    pkg_resources.require("PCL-GeoJSON"
    99except: 
    1010    pass 
    1111 
     12 
    1213def run(pattern): 
    1314    if pattern is None: 
    14         testfiles = glob.glob('*.txt'
     15        testfiles = glob.glob("*.txt"
    1516    else: 
    1617        testfiles = glob.glob(pattern) 
    17     for file in testfiles:  
     18    for file in testfiles: 
    1819        doctest.testfile(file) 
     20 
    1921 
    2022if __name__ == "__main__": 
     
    2628    pattern = None 
    2729    for o, a in opts: 
    28         if o == '-t'
     30        if o == "-t"
    2931            pattern = a 
    3032    run(pattern) 
  • GeoJSON/trunk/tests/rundoctests.dist

    r935 r1054  
    1 #!/bin/sh 
     1#!/bin/bash 
    22#export PYTHONPATH="/home/sean/Projects/GeoJSON/dev-packages" 
    3 python runalldoctests.py -v 
     3 
     4for python_version in python python2.4 python2.5; do 
     5    py_exec_path=$(which "$python_version"); 
     6    if [ -e "$py_exec_path" ] &&  [ -x "$py_exec_path" ]; then 
     7        echo "Testing under $python_version ($py_exec_path)"  
     8        "$python_version" runalldoctests.py -v  
     9    fi 
     10done