Permalink
Browse files

Overhaul of time and feature/record tests.

  • Loading branch information...
1 parent cfd45a4 commit 13171d98fa5cd9fc561cf40d09c1c61f2a1043a9 @sgillies committed Mar 10, 2012
Showing with 86 additions and 69 deletions.
  1. +69 −25 tests/test_feature.py
  2. +17 −44 tests/test_rfc3339.py
View
@@ -5,43 +5,87 @@
import unittest
from fiona import collection
+from fiona.collection import Collection
from fiona.ogrext import featureRT
#logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
-class PointTest(unittest.TestCase):
- def test_point(self):
+class PointRoundTripTest(unittest.TestCase):
+ def setUp(self):
+ schema = {'geometry': 'Point', 'properties': {'title': 'str'}}
+ self.c = Collection(
+ "/tmp/foo.shp", "w", driver="ESRI Shapefile", schema=schema)
+ def test_geometry(self):
f = { 'id': '1',
'geometry': {'type': 'Point', 'coordinates': (0.0, 0.0)},
'properties': {'title': u'foo'} }
- schema = {'geometry': 'Point', 'properties': {'title': 'str'}}
- with collection("/tmp/foo.shp", "w", "ESRI Shapefile", schema) as c:
- g = featureRT(f, c)
- self.failUnless(g.has_key('id'))
- self.failUnlessEqual(g['properties']['title'], 'foo')
- def test_linestring(self):
+ g = featureRT(f, self.c)
+ self.failUnlessEqual(
+ sorted(g['geometry'].items()),
+ [('coordinates', (0.0, 0.0)), ('type', 'Point')])
+ def test_properties(self):
+ f = { 'id': '1',
+ 'geometry': {'type': 'Point', 'coordinates': (0.0, 0.0)},
+ 'properties': {'title': u'foo'} }
+ g = featureRT(f, self.c)
+ self.failUnlessEqual(g['properties']['title'], 'foo')
+
+class LineStringRoundTripTest(unittest.TestCase):
+ def setUp(self):
+ schema = {'geometry': 'LineString', 'properties': {'title': 'str'}}
+ self.c = Collection(
+ "/tmp/foo.shp", "w", "ESRI Shapefile", schema=schema)
+ def test_geometry(self):
f = { 'id': '1',
'geometry': { 'type': 'LineString',
'coordinates': [(0.0, 0.0), (1.0, 1.0)] },
'properties': {'title': u'foo'} }
- schema = {'geometry': 'LineString', 'properties': {'title': 'str'}}
- with collection("/tmp/foo.shp", "w", "ESRI Shapefile", schema) as c:
- g = featureRT(f, c)
- self.failUnless(g.has_key('id'))
- self.failUnlessEqual(
- g['geometry']['coordinates'], [(0.0, 0.0), (1.0, 1.0)] )
- self.failUnlessEqual(g['properties']['title'], 'foo')
- def test_polygon(self):
+ g = featureRT(f, self.c)
+ self.failUnlessEqual(
+ sorted(g['geometry'].items()),
+ [('coordinates', [(0.0, 0.0), (1.0, 1.0)]),
+ ('type', 'LineString')])
+ def test_properties(self):
+ f = { 'id': '1',
+ 'geometry': {'type': 'Point', 'coordinates': (0.0, 0.0)},
+ 'properties': {'title': u'foo'} }
+ g = featureRT(f, self.c)
+ self.failUnlessEqual(g['properties']['title'], 'foo')
+
+class PolygonRoundTripTest(unittest.TestCase):
+ def setUp(self):
+ schema = {'geometry': 'Polygon', 'properties': {'title': 'str'}}
+ self.c = Collection(
+ "/tmp/foo.shp", "w", "ESRI Shapefile", schema=schema)
+ def test_geometry(self):
f = { 'id': '1',
'geometry': { 'type': 'Polygon',
- 'coordinates': [[(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]] },
+ 'coordinates':
+ [[(0.0, 0.0),
+ (0.0, 1.0),
+ (1.0, 1.0),
+ (1.0, 0.0),
+ (0.0, 0.0)]] },
'properties': {'title': u'foo'} }
- schema = {'geometry': 'Polygon', 'properties': {'title': 'str'}}
- with collection("/tmp/foo.shp", "w", "ESRI Shapefile", schema) as c:
- g = featureRT(f, c)
- self.failUnless(g.has_key('id'))
- self.failUnlessEqual(
- g['geometry']['coordinates'],
- [[(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]] )
- self.failUnlessEqual(g['properties']['title'], 'foo')
+ g = featureRT(f, self.c)
+ self.failUnlessEqual(
+ sorted(g['geometry'].items()),
+ [('coordinates', [[(0.0, 0.0),
+ (0.0, 1.0),
+ (1.0, 1.0),
+ (1.0, 0.0),
+ (0.0, 0.0)]]),
+ ('type', 'Polygon')])
+ def test_properties(self):
+ f = { 'id': '1',
+ 'geometry': { 'type': 'Polygon',
+ 'coordinates':
+ [[(0.0, 0.0),
+ (0.0, 1.0),
+ (1.0, 1.0),
+ (1.0, 0.0),
+ (0.0, 0.0)]] },
+ 'properties': {'title': u'foo'} }
+ g = featureRT(f, self.c)
+ self.failUnlessEqual(g['properties']['title'], 'foo')
View
@@ -9,66 +9,39 @@
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
class DateParseTest(unittest.TestCase):
-
+
def test_yyyymmdd(self):
- y, m, d, hh, mm, ss, ff = parse_date("2012-01-29")
- self.failUnlessEqual(y, 2012)
- self.failUnlessEqual(m, 1)
- self.failUnlessEqual(d, 29)
- self.failUnlessEqual(hh, 0)
+ self.failUnlessEqual(
+ parse_date("2012-01-29"), (2012, 1, 29, 0, 0, 0, 0.0))
class TimeParseTest(unittest.TestCase):
def test_hhmmss(self):
- y, m, d, hh, mm, ss, ff = parse_time("10:11:12")
- self.failUnlessEqual(y, 0)
- self.failUnlessEqual(hh, 10)
- self.failUnlessEqual(mm, 11)
- self.failUnlessEqual(ss, 12)
- self.failUnlessEqual(ff, 0.0)
+ self.failUnlessEqual(
+ parse_time("10:11:12"), (0, 0, 0, 10, 11, 12, 0.0))
def test_hhmm(self):
- y, m, d, hh, mm, ss, ff = parse_time("10:11")
- self.failUnlessEqual(y, 0)
- self.failUnlessEqual(hh, 10)
- self.failUnlessEqual(mm, 11)
- self.failUnlessEqual(ss, 0)
- self.failUnlessEqual(ff, 0.0)
+ self.failUnlessEqual(
+ parse_time("10:11"), (0, 0, 0, 10, 11, 0, 0.0))
def test_hhmmssff(self):
- y, m, d, hh, mm, ss, ff = parse_time("10:11:12.42")
- self.failUnlessEqual(y, 0)
- self.failUnlessEqual(hh, 10)
- self.failUnlessEqual(mm, 11)
- self.failUnlessEqual(ss, 12)
- self.failUnlessEqual(ff, 0.42*1000000.0)
+ self.failUnlessEqual(
+ parse_time("10:11:12.42"),
+ (0, 0, 0, 10, 11, 12, 0.42*1000000.0))
def test_hhmmssz(self):
- y, m, d, hh, mm, ss, ff = parse_time("10:11:12Z")
- self.failUnlessEqual(y, 0)
- self.failUnlessEqual(hh, 10)
- self.failUnlessEqual(mm, 11)
- self.failUnlessEqual(ss, 12)
- self.failUnlessEqual(ff, 0.0)
+ self.failUnlessEqual(
+ parse_time("10:11:12Z"), (0, 0, 0, 10, 11, 12, 0.0))
def test_hhmmssoff(self):
- y, m, d, hh, mm, ss, ff = parse_time("10:11:12-01:00")
- self.failUnlessEqual(y, 0)
- self.failUnlessEqual(hh, 10)
- self.failUnlessEqual(mm, 11)
- self.failUnlessEqual(ss, 12)
- self.failUnlessEqual(ff, 0.0)
+ self.failUnlessEqual(
+ parse_time("10:11:12-01:00"), (0, 0, 0, 10, 11, 12, 0.0))
class DatetimeParseTest(unittest.TestCase):
def test_yyyymmdd(self):
- y, m, d, hh, mm, ss, ff = parse_datetime("2012-01-29T10:11:12")
- self.failUnlessEqual(y, 2012)
- self.failUnlessEqual(m, 1)
- self.failUnlessEqual(d, 29)
- self.failUnlessEqual(hh, 10)
- self.failUnlessEqual(mm, 11)
- self.failUnlessEqual(ss, 12)
- self.failUnlessEqual(ff, 0.0)
+ self.failUnlessEqual(
+ parse_datetime("2012-01-29T10:11:12"),
+ (2012, 1, 29, 10, 11, 12, 0.0))

0 comments on commit 13171d9

Please sign in to comment.