Fixed #28617 -- Made ogrinspect output pep8 compliant.
This commit is contained in:
parent
df41b5a05d
commit
52eb5b289e
|
@ -124,10 +124,10 @@ class Command(BaseCommand):
|
|||
# This extra legwork is so that the dictionary definition comes
|
||||
# out in the same order as the fields in the model definition.
|
||||
rev_mapping = {v: k for k, v in mapping_dict.items()}
|
||||
output.extend(['', '# Auto-generated `LayerMapping` dictionary for %s model' % model_name,
|
||||
output.extend(['', '', '# Auto-generated `LayerMapping` dictionary for %s model' % model_name,
|
||||
'%s_mapping = {' % model_name.lower()])
|
||||
output.extend(" '%s' : '%s'," % (
|
||||
output.extend(" '%s': '%s'," % (
|
||||
rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields
|
||||
)
|
||||
output.extend([" '%s' : '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}'])
|
||||
output.extend([" '%s': '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}'])
|
||||
return '\n'.join(output) + '\n'
|
||||
|
|
|
@ -169,6 +169,7 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non
|
|||
yield '# This is an auto-generated Django model module created by ogrinspect.'
|
||||
yield 'from django.contrib.gis.db import models'
|
||||
yield ''
|
||||
yield ''
|
||||
|
||||
yield 'class %s(models.Model):' % model_name
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ class OGRInspectTest(TestCase):
|
|||
'# This is an auto-generated Django model module created by ogrinspect.',
|
||||
'from django.contrib.gis.db import models',
|
||||
'',
|
||||
'',
|
||||
'class MyModel(models.Model):',
|
||||
' float = models.FloatField()',
|
||||
' int = models.{}()'.format('BigIntegerField' if GDAL_VERSION >= (2, 0) else 'FloatField'),
|
||||
|
@ -96,6 +97,7 @@ class OGRInspectTest(TestCase):
|
|||
'# This is an auto-generated Django model module created by ogrinspect.',
|
||||
'from django.contrib.gis.db import models',
|
||||
'',
|
||||
'',
|
||||
'class City(models.Model):',
|
||||
' name = models.CharField(max_length=80)',
|
||||
' population = models.{}()'.format('BigIntegerField' if GDAL_VERSION >= (2, 0) else 'FloatField'),
|
||||
|
@ -126,6 +128,7 @@ class OGRInspectTest(TestCase):
|
|||
'# This is an auto-generated Django model module created by ogrinspect.\n'
|
||||
'from django.contrib.gis.db import models\n'
|
||||
'\n'
|
||||
'\n'
|
||||
'class Measurement(models.Model):\n'
|
||||
))
|
||||
|
||||
|
@ -148,6 +151,24 @@ class OGRInspectTest(TestCase):
|
|||
output = out.getvalue()
|
||||
self.assertIn('class City(models.Model):', output)
|
||||
|
||||
def test_mapping_option(self):
|
||||
expected = (
|
||||
" geom = models.PointField(srid=-1)\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"# Auto-generated `LayerMapping` dictionary for City model\n"
|
||||
"city_mapping = {\n"
|
||||
" 'name': 'Name',\n"
|
||||
" 'population': 'Population',\n"
|
||||
" 'density': 'Density',\n"
|
||||
" 'created': 'Created',\n"
|
||||
" 'geom': 'POINT',\n"
|
||||
"}\n")
|
||||
shp_file = os.path.join(TEST_DATA, 'cities', 'cities.shp')
|
||||
out = StringIO()
|
||||
call_command('ogrinspect', shp_file, '--mapping', 'City', stdout=out)
|
||||
self.assertIn(expected, out.getvalue())
|
||||
|
||||
|
||||
def get_ogr_db_string():
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue