def test_write_coll(self): def _test_key_case_(path, upper=True): with fiona.open(path, 'r') as source: for row in source: keys = row['properties'].keys() for key in keys: if upper: self.assertTrue(key.isupper(), key) else: self.assertFalse(key.isupper(), key) field = self.get_field(crs=WGS84()) coll = field.as_spatial_collection() conv = ShpConverter([coll], outdir=self.current_dir_output, prefix='foo') f = conv._build_(coll) conv._write_coll_(f, coll) conv._finalize_(f) _test_key_case_(conv.path, upper=True) field = self.get_field(crs=WGS84()) coll = field.as_spatial_collection() conv = ShpConverter([coll], outdir=self.current_dir_output, prefix='foo2', melted=True) f = conv._build_(coll) conv._write_coll_(f, coll) conv._finalize_(f) _test_key_case_(conv.path, upper=True)
def test_build(self): field = self.get_field() coll = field.as_spatial_collection() conv = ShpConverter([coll], outdir=self.current_dir_output, prefix='foo') # no coordinate system... with self.assertRaises(ValueError): conv._build_(coll) field = self.get_field(crs=WGS84()) coll = field.as_spatial_collection() conv = ShpConverter([coll], outdir=self.current_dir_output, prefix='foo') self.assertTrue(conv._use_upper_keys) ret = conv._build_(coll) schema_keys = ret['fobject'].meta['schema']['properties'].keys() for key in schema_keys: self.assertFalse(key.islower()) self.assertNotIn('VALUE', ret['schema']['properties']) field = self.get_field(crs=WGS84()) coll = field.as_spatial_collection() conv = ShpConverter([coll], outdir=self.current_dir_output, prefix='foo2', melted=True) ret = conv._build_(coll) self.assertIn('VALUE', ret['schema']['properties'])