/[thuban]/branches/WIP-pyshapelib-bramz/test/test_derivedshapestore.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/test/test_derivedshapestore.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1551 - (hide annotations)
Wed Aug 6 17:21:07 2003 UTC (21 years, 7 months ago) by bh
Original Path: trunk/thuban/test/test_derivedshapestore.py
File MIME type: text/x-python
File size: 4417 byte(s)
* Thuban/Model/data.py (ShapefileStore.Shape): For consistency, a
Shape object will always have the coordinates as a list of list of
coordinate pairs (tuples).
(Shape.compute_bbox): Adapt to new representation.

* Thuban/UI/viewport.py (ViewPort.find_shape_at)
(ViewPort.LabelShapeAt): Adapt to new coordinate representation in
Shape objects.

* test/test_shapefilestore.py
(ShapefileStoreTests.assertFloatTuplesEqual)
(ShapefileStoreTests.assertPointListEquals): Rename to
assertPointListEquals and change purpose to checking equality of
the lists returned by Shape.Points().
(TestShapefileStoreArc.test_shape)
(TestShapefileStorePolygon.test_shape)
(TestShapefileStorePoint.test_shape): Use the new
assertPointListEquals instead of assertFloatTuplesEqual

* test/test_layer.py (TestLayer.assertFloatTuplesEqual)
(TestLayer.assertPointListEquals): Rename to assertPointListEquals
and change purpose to checking equality of the lists returned by
Shape.Points().
(TestLayer.test_arc_layer, TestLayer.test_arc_layer)
(TestLayer.test_polygon_layer, TestLayer.test_point_layer)
(TestLayer.test_derived_store): Use the new assertPointListEquals
instead of assertFloatTuplesEqual

* test/test_derivedshapestore.py
(TestDerivedShapeStore.assertFloatTuplesEqual)
(TestDerivedShapeStore.assertPointListEquals): Rename to
assertPointListEquals and change purpose to checking equality of
the lists returned by Shape.Points().
(TestDerivedShapeStore.test_shape): Use the new
assertPointListEquals instead of assertFloatTuplesEqual

1 bh 1536 # Copyright (C) 2003 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with the software for details.
7    
8     """Tests for DerivedShapeStore"""
9    
10     __version__ = "$Revision$"
11     # $Source$
12     # $Id$
13    
14     import os
15    
16     import unittest
17    
18     import support
19     support.initthuban()
20    
21     from Thuban.Model.data import DerivedShapeStore, ShapefileStore, SHAPETYPE_ARC
22     from Thuban.Model.session import Session
23     from Thuban.Model.table import MemoryTable, \
24     FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING
25    
26    
27     class TestDerivedShapeStore(unittest.TestCase, support.FloatComparisonMixin):
28    
29     def setUp(self):
30     """Initialize self.session"""
31     self.session = Session("Test Session")
32     self.filename = os.path.join("..", "Data", "iceland",
33     "roads-line.shp")
34     self.store = ShapefileStore(self.session, self.filename)
35    
36     self.table = MemoryTable([("type", FIELDTYPE_STRING),
37     ("value", FIELDTYPE_DOUBLE),
38     ("code", FIELDTYPE_INT)],
39     [("UNKNOWN", 0.0, 0)] * 839)
40     self.derived = DerivedShapeStore(self.store, self.table)
41    
42     def tearDown(self):
43     """Call self.session.Destroy() and reset self.session to None"""
44     self.session.Destroy()
45     self.session = None
46    
47 bh 1551 def assertPointListEquals(self, test, value):
48     """Assert equality of two lists of lists of tuples of float"""
49 bh 1536 for i in range(len(test)):
50 bh 1551 self.assertEquals(len(test[i]), len(value[i]))
51     for j in range(len(test[i])):
52     self.assertFloatSeqEqual(test[i][j], value[i][j])
53 bh 1536
54     def test_dependencies(self):
55     """Test DerivedShapeStore dependencies"""
56     # The shapestore itself depends on nothing else
57     self.assertEquals(self.derived.Dependencies(),
58     (self.store, self.table))
59    
60     def test_orig_shapestore(self):
61     """Test DerivedShapeStore.OrigShapeStore()"""
62     self.assertEquals(self.derived.OrigShapeStore(), self.store)
63    
64     def test_shape_type(self):
65     """Test DerivedShapeStore.ShapeType() with arc shapes"""
66     self.assertEquals(self.derived.ShapeType(), SHAPETYPE_ARC)
67    
68     def test_boundingbox(self):
69     """Test DerivedShapeStore.BoundingBox() with arc shapes"""
70     self.assertFloatSeqEqual(self.derived.BoundingBox(),
71     [-24.450359344482422, 63.426830291748047,
72     -13.55668830871582, 66.520111083984375])
73    
74     def test_num_shapes(self):
75     """Test DerivedShapeStore.NumShapes() with arc shapes"""
76     self.assertEquals(self.derived.NumShapes(), 839)
77    
78     def test_shapes_in_region(self):
79     """Test DerivedShapeStore.ShapesInRegion() with arc shapes"""
80     self.assertEquals(self.derived.ShapesInRegion((-24.0, 64.0,
81     -23.75, 64.25)),
82     [613, 726, 838])
83    
84     def test_shape(self):
85     """Test DerivedShapeStore.Shape() with arc shapes"""
86 bh 1551 self.assertPointListEquals(self.derived.Shape(32).Points(),
87     [[(-15.082174301147461, 66.27738189697265),
88     (-15.026350021362305, 66.27339172363281)]])
89 bh 1536
90    
91    
92     class TestDerivedShapeStoreExceptions(unittest.TestCase):
93    
94     """Test DerivedShapeStore exceptions"""
95    
96     def test_table_with_wrong_size(self):
97     """Test DerivedShapeStore() with a table with the wrong number of lines
98     """
99     filename = os.path.join("..", "Data", "iceland", "roads-line.shp")
100     session = Session("TestDerivedShapeStore Session")
101     store = session.OpenShapefile(filename)
102    
103     table = MemoryTable([("type", FIELDTYPE_STRING),
104     ("value", FIELDTYPE_DOUBLE),
105     ("code", FIELDTYPE_INT)],
106     [("UNKNOWN", 0.0, 0),
107     ("Foo", 0.5, -1),
108     ("Foo", 0.25, 100),
109     ("bar", 1e10, 17)])
110    
111     # Trying to create a DerivedShapeStore where the number of lines
112     # in the table is not the same as the number of shapes in the
113     # shapefile raises a ValueError
114     self.assertRaises(ValueError, DerivedShapeStore, store, table)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26