root/geojson/trunk/tests/blog.txt

Revision 1054 (checked in by mattrussell, 9 months ago)

- 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.


  • Property svn:eol-style set to native
Line 
1 Tests of the feature protocol embedded in a arbitrary json document
2 ===================================================================
3
4
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]]]}}}
6
7   >>> import geojson
8
9   Encoding
10
11   >>> json = geojson.dumps(d)
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...]]]}}}'
14
15   Decoding
16
17   >>> o = geojson.loads(json)
18   >>> type(o)
19   <type 'dict'>
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...]]]}}}
22
Note: See TracBrowser for help on using the browser.