/[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 1564 - (hide annotations)
Thu Aug 7 19:19:56 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: 4619 byte(s)
* Thuban/Model/data.py (DerivedShapeStore.RawShapeFormat): New.
Simply delegates to the original shapestore.

* test/test_derivedshapestore.py
(TestDerivedShapeStore.test_raw_format): New. Test case for
DerivedShapeStore.RawShapeFormat

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 bh 1564 from Thuban.Model.data import DerivedShapeStore, ShapefileStore, \
22     SHAPETYPE_ARC, RAW_SHAPEFILE
23    
24 bh 1536 from Thuban.Model.session import Session
25     from Thuban.Model.table import MemoryTable, \
26     FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING
27    
28    
29     class TestDerivedShapeStore(unittest.TestCase, support.FloatComparisonMixin):
30    
31     def setUp(self):
32     """Initialize self.session"""
33     self.session = Session("Test Session")
34     self.filename = os.path.join("..", "Data", "iceland",
35     "roads-line.shp")
36     self.store = ShapefileStore(self.session, self.filename)
37    
38     self.table = MemoryTable([("type", FIELDTYPE_STRING),
39     ("value", FIELDTYPE_DOUBLE),
40     ("code", FIELDTYPE_INT)],
41     [("UNKNOWN", 0.0, 0)] * 839)
42     self.derived = DerivedShapeStore(self.store, self.table)
43    
44     def tearDown(self):
45     """Call self.session.Destroy() and reset self.session to None"""
46     self.session.Destroy()
47     self.session = None
48    
49 bh 1551 def assertPointListEquals(self, test, value):
50     """Assert equality of two lists of lists of tuples of float"""
51 bh 1536 for i in range(len(test)):
52 bh 1551 self.assertEquals(len(test[i]), len(value[i]))
53     for j in range(len(test[i])):
54     self.assertFloatSeqEqual(test[i][j], value[i][j])
55 bh 1536
56     def test_dependencies(self):
57     """Test DerivedShapeStore dependencies"""
58     # The shapestore itself depends on nothing else
59     self.assertEquals(self.derived.Dependencies(),
60     (self.store, self.table))
61    
62     def test_orig_shapestore(self):
63     """Test DerivedShapeStore.OrigShapeStore()"""
64     self.assertEquals(self.derived.OrigShapeStore(), self.store)
65    
66     def test_shape_type(self):
67     """Test DerivedShapeStore.ShapeType() with arc shapes"""
68     self.assertEquals(self.derived.ShapeType(), SHAPETYPE_ARC)
69    
70 bh 1564 def test_raw_format(self):
71     """Test DerivedShapeStore.RawShapeFormat() with shapefiles"""
72     self.assertEquals(self.derived.RawShapeFormat(), RAW_SHAPEFILE)
73    
74 bh 1536 def test_boundingbox(self):
75     """Test DerivedShapeStore.BoundingBox() with arc shapes"""
76     self.assertFloatSeqEqual(self.derived.BoundingBox(),
77     [-24.450359344482422, 63.426830291748047,
78     -13.55668830871582, 66.520111083984375])
79    
80     def test_num_shapes(self):
81     """Test DerivedShapeStore.NumShapes() with arc shapes"""
82     self.assertEquals(self.derived.NumShapes(), 839)
83    
84     def test_shapes_in_region(self):
85     """Test DerivedShapeStore.ShapesInRegion() with arc shapes"""
86     self.assertEquals(self.derived.ShapesInRegion((-24.0, 64.0,
87     -23.75, 64.25)),
88     [613, 726, 838])
89    
90     def test_shape(self):
91     """Test DerivedShapeStore.Shape() with arc shapes"""
92 bh 1551 self.assertPointListEquals(self.derived.Shape(32).Points(),
93     [[(-15.082174301147461, 66.27738189697265),
94     (-15.026350021362305, 66.27339172363281)]])
95 bh 1536
96    
97    
98     class TestDerivedShapeStoreExceptions(unittest.TestCase):
99    
100     """Test DerivedShapeStore exceptions"""
101    
102     def test_table_with_wrong_size(self):
103     """Test DerivedShapeStore() with a table with the wrong number of lines
104     """
105     filename = os.path.join("..", "Data", "iceland", "roads-line.shp")
106     session = Session("TestDerivedShapeStore Session")
107     store = session.OpenShapefile(filename)
108    
109     table = MemoryTable([("type", FIELDTYPE_STRING),
110     ("value", FIELDTYPE_DOUBLE),
111     ("code", FIELDTYPE_INT)],
112     [("UNKNOWN", 0.0, 0),
113     ("Foo", 0.5, -1),
114     ("Foo", 0.25, 100),
115     ("bar", 1e10, 17)])
116    
117     # Trying to create a DerivedShapeStore where the number of lines
118     # in the table is not the same as the number of shapes in the
119     # shapefile raises a ValueError
120     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