diff options
| author | Hasan <hasan.r67@gmail.com> | 2016-01-17 14:56:39 +0330 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-29 12:32:18 -0500 |
| commit | 3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5 (patch) | |
| tree | 0d1074cc65a72096e44a4165611fddfc5b7ef7fb /tests/gis_tests/layermap | |
| parent | 575706331bec4bf58ce36a9540c4c61fca49025b (diff) | |
Refs #26022 -- Used context manager version of assertRaises in tests.
Diffstat (limited to 'tests/gis_tests/layermap')
| -rw-r--r-- | tests/gis_tests/layermap/tests.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/tests/gis_tests/layermap/tests.py b/tests/gis_tests/layermap/tests.py index 3ebbf4292e..7713706704 100644 --- a/tests/gis_tests/layermap/tests.py +++ b/tests/gis_tests/layermap/tests.py @@ -156,11 +156,13 @@ class LayerMapTest(TestCase): # Testing invalid params for the `unique` keyword. for e, arg in ((TypeError, 5.0), (ValueError, 'foobar'), (ValueError, ('name', 'mpolygon'))): - self.assertRaises(e, LayerMapping, County, co_shp, co_mapping, transform=False, unique=arg) + with self.assertRaises(e): + LayerMapping(County, co_shp, co_mapping, transform=False, unique=arg) # No source reference system defined in the shapefile, should raise an error. if connection.features.supports_transform: - self.assertRaises(LayerMapError, LayerMapping, County, co_shp, co_mapping) + with self.assertRaises(LayerMapError): + LayerMapping(County, co_shp, co_mapping) # Passing in invalid ForeignKey mapping parameters -- must be a dictionary # mapping for the model the ForeignKey points to. @@ -168,14 +170,17 @@ class LayerMapTest(TestCase): bad_fk_map1['state'] = 'name' bad_fk_map2 = copy(co_mapping) bad_fk_map2['state'] = {'nombre': 'State'} - self.assertRaises(TypeError, LayerMapping, County, co_shp, bad_fk_map1, transform=False) - self.assertRaises(LayerMapError, LayerMapping, County, co_shp, bad_fk_map2, transform=False) + with self.assertRaises(TypeError): + LayerMapping(County, co_shp, bad_fk_map1, transform=False) + with self.assertRaises(LayerMapError): + LayerMapping(County, co_shp, bad_fk_map2, transform=False) # There exist no State models for the ForeignKey mapping to work -- should raise # a MissingForeignKey exception (this error would be ignored if the `strict` # keyword is not set). lm = LayerMapping(County, co_shp, co_mapping, transform=False, unique='name') - self.assertRaises(MissingForeignKey, lm.save, silent=True, strict=True) + with self.assertRaises(MissingForeignKey): + lm.save(silent=True, strict=True) # Now creating the state models so the ForeignKey mapping may work. State.objects.bulk_create([ @@ -222,11 +227,13 @@ class LayerMapTest(TestCase): # Bad feature id ranges should raise a type error. bad_ranges = (5.0, 'foo', co_shp) for bad in bad_ranges: - self.assertRaises(TypeError, lm.save, fid_range=bad) + with self.assertRaises(TypeError): + lm.save(fid_range=bad) # Step keyword should not be allowed w/`fid_range`. fr = (3, 5) # layer[3:5] - self.assertRaises(LayerMapError, lm.save, fid_range=fr, step=10) + with self.assertRaises(LayerMapError): + lm.save(fid_range=fr, step=10) lm.save(fid_range=fr) # Features IDs 3 & 4 are for Galveston County, Texas -- only |
