nhueffme: thuban/Extensions/ogr/test test_OGRShapestore.py, 1.1, 1.2
cvs@intevation.de
cvs at intevation.de
Mon Dec 20 15:13:59 CET 2004
Author: nhueffme
Update of /thubanrepository/thuban/Extensions/ogr/test
In directory doto:/tmp/cvs-serv29961/Extensions/ogr/test
Modified Files:
test_OGRShapestore.py
Log Message:
Fixed some issues from Bernhard.
Index: test_OGRShapestore.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/ogr/test/test_OGRShapestore.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test_OGRShapestore.py 7 Dec 2004 16:44:51 -0000 1.1
+++ test_OGRShapestore.py 20 Dec 2004 14:13:57 -0000 1.2
@@ -35,15 +35,23 @@
support.initthuban()
from Extensions.ogr.ogrshapes import OGRShapeStore, OGRShape, \
- SHAPETYPE_ARC, RAW_OGRSHAPES
+ SHAPETYPE_ARC
+from Thuban.Model.data import RAW_PYTHON
from Thuban.Model.table import FIELDTYPE_INT
from Thuban.Model.session import Session
+def skip_if_no_ogr():
+ if ogr is None:
+ raise support.SkipTest("Can't run ogr tests because ogr counldn't be imported.")
+
class TestOGRShapeStore(unittest.TestCase, support.FloatComparisonMixin):
def setUp(self):
- """Initialize self.session"""
+ """Initialize self.session and open shapefile, if ogr could be
+ imported.
+ """
+ skip_if_no_ogr()
self.session = Session("Test Session")
self.filename = os.path.join("..", "Data", "iceland","roads-line.shp")
self.store = OGRShapeStore(self.session, self.filename, "roads-line")
@@ -52,6 +60,7 @@
"""Call self.session.Destroy() and reset self.session to None"""
self.session.Destroy()
self.session = None
+ self.store = None
def test_shape_type(self):
"""Test OGRShapeStore.ShapeType() with arc shapes"""
@@ -59,13 +68,13 @@
def test_raw_format(self):
"""Test OGRShapeStore.RawShapeFormat() with ogr file"""
- self.assertEquals(self.store.RawShapeFormat(), RAW_OGRSHAPES)
+ self.assertEquals(self.store.RawShapeFormat(), RAW_PYTHON)
def test_boundingbox(self):
"""Test OGRShapeStore.BoundingBox() with arc shapes"""
self.assertFloatSeqEqual(self.store.BoundingBox(),
- [-24.450359344482422, 63.426830291748047,
- -13.55668830871582, 66.520111083984375])
+ [-24.450359344482422, 63.426830291748047,
+ -13.55668830871582, 66.520111083984375])
def test_num_shapes(self):
"""Test OGRShapeStore.NumShapes() with arc shapes"""
@@ -74,28 +83,28 @@
def test_shapes_in_region(self):
"""Test OGRShapeStore.ShapesInRegion() with arc shapes"""
shapes = self.store.ShapesInRegion((-22.78, 63.96, -22.72, 64.0))
- self.assertEquals([s.ShapeID() for s in shapes],
- [769, 771])
+ self.assertEquals([s.ShapeID() for s in shapes], [769, 771])
def test_all_shapes(self):
"""Test OGRShapeStore.AllShapes()"""
self.assertEquals([s.ShapeID() for s in self.store.AllShapes()],
- range(self.store.NumShapes()))
+ range(self.store.NumShapes()))
def test_shape_Points(self):
"""Test OGRShapeStore.Shape() with arc shapes"""
self.assertPointListEquals(self.store.Shape(32).Points(),
- [[(-15.08217430114746, 66.2773818969726),
- (-15.02635002136230, 66.2733917236328)]])
+ [[(-15.08217430114746, 66.2773818969726),
+ (-15.02635002136230, 66.2733917236328)]])
def test_shape_shapeid(self):
"""Test OGRShapeStore.Shape(i).ShapeID()"""
self.assertEquals(self.store.Shape(5).ShapeID(), 5)
def test_shape_compute_bbox(self):
- """Test bbox of one shape"""
- self.assertFloatSeqEqual(self.store.Shape(32).compute_bbox(),
- (-15.08217430114746, 66.2733917236328,-15.02635002136230, 66.2773818969726))
+ """Test bbox of one shape"""
+ self.assertFloatSeqEqual(self.store.Shape(32).compute_bbox(),
+ (-15.08217430114746, 66.2733917236328,
+ -15.02635002136230, 66.2773818969726))
class TestOGRTable(unittest.TestCase, support.FloatComparisonMixin):
@@ -105,7 +114,7 @@
self.session = Session("Test Session")
self.filename = os.path.join("..","Data", "iceland","roads-line.shp")
self.store = OGRShapeStore(self.session, self.filename, "roads-line")
- self.table = self.store.Table()
+ self.table = self.store.Table()
def tearDown(self):
"""Call self.session.Destroy() and reset self.session to None"""
@@ -113,73 +122,75 @@
self.session = None
def test_Dependencies(self):
- """Test dependencies, which is always ()"""
- self.assertEquals(self.table.Dependencies(), ())
+ """Test dependencies, which is always ()"""
+ self.assertEquals(self.table.Dependencies(), ())
def test_NumColumns(self):
- """Test number of columns"""
- self.assertEquals(self.table.NumColumns(), 9)
+ """Test number of columns"""
+ self.assertEquals(self.table.NumColumns(), 9)
def test_Columns(self):
- """Test columns, which are instances of OGRColumn"""
- self.assertEquals(len(self.table.Columns()), 9)
+ """Test columns, which are instances of OGRColumn"""
+ self.assertEquals(len(self.table.Columns()), 9)
self.assertEquals(self.table.Columns()[0].name, "FNODE_")
self.assertEquals(self.table.Columns()[0].type, FIELDTYPE_INT)
self.assertEquals(self.table.Columns()[0].index, 0)
def test_Column(self):
- """Test column, which is instance of OGRColumn"""
- self.assertEquals(self.table.Column(0).name, "FNODE_")
- self.assertEquals(self.table.Column(0).type, FIELDTYPE_INT)
- self.assertEquals(self.table.Column(0).index, 0)
- self.assertEquals(self.table.Column("FNODE_").type, FIELDTYPE_INT)
- self.assertEquals(self.table.Column("FNODE_").index, 0)
+ """Test column, which is instance of OGRColumn"""
+ self.assertEquals(self.table.Column(0).name, "FNODE_")
+ self.assertEquals(self.table.Column(0).type, FIELDTYPE_INT)
+ self.assertEquals(self.table.Column(0).index, 0)
+ self.assertEquals(self.table.Column("FNODE_").type, FIELDTYPE_INT)
+ self.assertEquals(self.table.Column("FNODE_").index, 0)
def test_HasColumn(self):
- """Test HasColumn(), which can be called either with an integer or a string"""
- self.assert_(self.table.HasColumn(0))
- self.assert_(self.table.HasColumn("FNODE_"))
+ """Test HasColumn(), which can be called either with an integer or
+ a string"""
+ self.assert_(self.table.HasColumn(0))
+ self.assert_(self.table.HasColumn("FNODE_"))
def test_NumRows(self):
- """Test number of rows, which equals the number of features"""
- self.assertEquals(self.table.NumRows(), 839)
+ """Test number of rows, which equals the number of features"""
+ self.assertEquals(self.table.NumRows(), 839)
def test_RowIdToOrdinal(self):
- self.assertEqual(self.table.RowIdToOrdinal(5),5)
+ self.assertEqual(self.table.RowIdToOrdinal(5),5)
def test_RowOrdinalToId(self):
- self.assertEqual(self.table.RowOrdinalToId(5),5)
+ self.assertEqual(self.table.RowOrdinalToId(5),5)
def test_ReadRowAsDict(self):
- """Test ReadRowAsDict()"""
- self.assertEquals(len(self.table.ReadRowAsDict(0)), 9)
- self.assertEquals(self.table.ReadRowAsDict(0, row_is_ordinal = 1),
- {"FNODE_": 3,
- "TNODE_": 1,
- "LPOLY_": 146,
- "RPOLY_": 146,
- "LENGTH": 0.156,
- "RDLINE_": 1,
- "RDLINE_ID": 879,
- "RDLNTYPE": 3,
- "RDLNSTAT": 1})
+ """Test ReadRowAsDict()"""
+ self.assertEquals(len(self.table.ReadRowAsDict(0)), 9)
+ self.assertEquals(self.table.ReadRowAsDict(0, row_is_ordinal = 1),
+ {"FNODE_": 3,
+ "TNODE_": 1,
+ "LPOLY_": 146,
+ "RPOLY_": 146,
+ "LENGTH": 0.156,
+ "RDLINE_": 1,
+ "RDLINE_ID": 879,
+ "RDLNTYPE": 3,
+ "RDLNSTAT": 1})
def test_ReadValue(self):
- """Test ReadValue()"""
- self.assertEquals(self.table.ReadValue(0,0,0), 3)
- self.assertEquals(self.table.ReadValue(0,"FNODE_",0),3)
+ """Test ReadValue()"""
+ self.assertEquals(self.table.ReadValue(0,0,0), 3)
+ self.assertEquals(self.table.ReadValue(0,"FNODE_",0),3)
def test_ValueRange(self):
- """Test ValueRange()"""
- self.assertEquals(self.table.ValueRange("FNODE_"), (1, 733))
+ """Test ValueRange()"""
+ self.assertEquals(self.table.ValueRange("FNODE_"), (1, 733))
def test_UniqueValues(self):
- """Test UniqueValues()"""
- self.assertFloatSeqEqual(self.table.UniqueValues("RDLNTYPE"), [2,3,8])
+ """Test UniqueValues()"""
+ self.assertFloatSeqEqual(self.table.UniqueValues("RDLNTYPE"), [2,3,8])
def test_SimpleQuery(self):
- """Test SimpleQuery()"""
- self.assertEquals(self.table.SimpleQuery(self.table.Column("LENGTH"), "==", 0.156),[0, 24, 317])
+ """Test SimpleQuery()"""
+ self.assertEquals(self.table.SimpleQuery(self.table.Column("LENGTH"),
+ "==", 0.156),[0, 24, 317])
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)