|
36 | 36 | TEST_DATA_DIR = unitTestDataPath()
|
37 | 37 |
|
38 | 38 |
|
39 |
| -def die(error_message): |
40 |
| - raise Exception(error_message) |
41 |
| - |
42 |
| - |
43 | 39 | class TestQgsSpatialiteProvider(unittest.TestCase, ProviderTestCase):
|
44 | 40 |
|
45 | 41 | @classmethod
|
@@ -144,73 +140,69 @@ def partiallyCompiledFilters(self):
|
144 | 140 | def test_SplitFeature(self):
|
145 | 141 | """Create spatialite database"""
|
146 | 142 | layer = QgsVectorLayer("dbname=%s table=test_pg (geometry)" % self.dbname, "test_pg", "spatialite")
|
147 |
| - assert(layer.isValid()) |
148 |
| - assert(layer.hasGeometryType()) |
| 143 | + self.assertTrue(layer.isValid()) |
| 144 | + self.assertTrue(layer.hasGeometryType()) |
149 | 145 | layer.startEditing()
|
150 |
| - layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0) == 0 or die("error in split") |
151 |
| - layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0) == 0 or die("error in split") |
152 |
| - if not layer.commitChanges(): |
153 |
| - die("this commit should work") |
154 |
| - layer.featureCount() == 4 or die("we should have 4 features after 2 split") |
| 146 | + self.assertEqual(layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0), 0) |
| 147 | + self.assertEqual(layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0), 0) |
| 148 | + self.assertTrue(layer.commitChanges()) |
| 149 | + self.assertEqual(layer.featureCount(), 4) |
155 | 150 |
|
156 | 151 | def xtest_SplitFeatureWithFailedCommit(self):
|
157 | 152 | """Create spatialite database"""
|
158 | 153 | layer = QgsVectorLayer("dbname=%s table=test_pg_mk (geometry)" % self.dbname, "test_pg_mk", "spatialite")
|
159 |
| - assert(layer.isValid()) |
160 |
| - assert(layer.hasGeometryType()) |
| 154 | + self.assertTrue(layer.isValid()) |
| 155 | + self.assertTrue(layer.hasGeometryType()) |
161 | 156 | layer.startEditing()
|
162 |
| - layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0) == 0 or die("error in split") |
163 |
| - layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0) == 0 or die("error in split") |
164 |
| - if layer.commitChanges(): |
165 |
| - die("this commit should fail") |
| 157 | + self.asserEqual(layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0), 0) |
| 158 | + self.asserEqual(layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0), 0) |
| 159 | + self.assertFalse(layer.commitChanges()) |
166 | 160 | layer.rollBack()
|
167 |
| - feat = QgsFeature() |
168 |
| - it = layer.getFeatures() |
169 |
| - it.nextFeature(feat) |
| 161 | + feat = next(layer.getFeatures()) |
170 | 162 | ref = [[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]]
|
171 | 163 | res = feat.geometry().asPolygon()
|
172 | 164 | for ring1, ring2 in zip(ref, res):
|
173 | 165 | for p1, p2 in zip(ring1, ring2):
|
174 | 166 | for c1, c2 in zip(p1, p2):
|
175 |
| - c1 == c2 or die("polygon has been altered by failed edition") |
| 167 | + self.asserEqual(c1, c2) |
176 | 168 |
|
177 | 169 | def test_queries(self):
|
178 | 170 | """Test loading of query-based layers"""
|
179 | 171 |
|
180 | 172 | # a query with a geometry, but no unique id
|
181 | 173 | # the id will be autoincremented
|
182 | 174 | l = QgsVectorLayer("dbname=%s table='(select * from test_q)' (geometry)" % self.dbname, "test_pg_query1", "spatialite")
|
183 |
| - assert(l.isValid()) |
| 175 | + self.assertTrue(l.isValid()) |
184 | 176 | # the id() is autoincremented
|
185 | 177 | sum_id1 = sum(f.id() for f in l.getFeatures())
|
186 | 178 | # the attribute 'id' works
|
187 | 179 | sum_id2 = sum(f.attributes()[0] for f in l.getFeatures())
|
188 |
| - assert(sum_id1 == 3) # 1+2 |
189 |
| - assert(sum_id2 == 32) # 11 + 21 |
| 180 | + self.assertEqual(sum_id1, 3) # 1+2 |
| 181 | + self.assertEqual(sum_id2, 32) # 11 + 21 |
190 | 182 |
|
191 | 183 | # and now with an id declared
|
192 | 184 | l = QgsVectorLayer("dbname=%s table='(select * from test_q)' (geometry) key='id'" % self.dbname, "test_pg_query1", "spatialite")
|
193 |
| - assert(l.isValid()) |
| 185 | + self.assertTrue(l.isValid()) |
194 | 186 | sum_id1 = sum(f.id() for f in l.getFeatures())
|
195 | 187 | sum_id2 = sum(f.attributes()[0] for f in l.getFeatures())
|
196 |
| - assert(sum_id1 == 32) |
197 |
| - assert(sum_id2 == 32) |
| 188 | + self.assertEqual(sum_id1, 32) |
| 189 | + self.assertEqual(sum_id2, 32) |
198 | 190 |
|
199 | 191 | # a query, but no geometry
|
200 | 192 | l = QgsVectorLayer("dbname=%s table='(select id,name from test_q)' key='id'" % self.dbname, "test_pg_query1", "spatialite")
|
201 |
| - assert(l.isValid()) |
| 193 | + self.assertTrue(l.isValid()) |
202 | 194 | sum_id1 = sum(f.id() for f in l.getFeatures())
|
203 | 195 | sum_id2 = sum(f.attributes()[0] for f in l.getFeatures())
|
204 |
| - assert(sum_id1 == 32) |
205 |
| - assert(sum_id2 == 32) |
| 196 | + self.assertEqual(sum_id1, 32) |
| 197 | + self.assertEqual(sum_id2, 32) |
206 | 198 |
|
207 | 199 | def test_case(self):
|
208 | 200 | """Test case sensitivity issues"""
|
209 | 201 | l = QgsVectorLayer("dbname=%s table='test_n' (geometry) key='id'" % self.dbname, "test_n1", "spatialite")
|
210 |
| - assert(l.isValid()) |
211 |
| - assert(l.dataProvider().fields().count() == 2) |
| 202 | + self.assertTrue(l.isValid()) |
| 203 | + self.assertEqual(l.dataProvider().fields().count(), 2) |
212 | 204 | fields = [f.name() for f in l.dataProvider().fields()]
|
213 |
| - assert('Geometry' not in fields) |
| 205 | + self.assertTrue('Geometry' not in fields) |
214 | 206 |
|
215 | 207 | def test_invalid_iterator(self):
|
216 | 208 | """ Test invalid iterator """
|
|
0 commit comments