Skip to content
Permalink
Browse files

Update tests to check field types

  • Loading branch information...
geographika committed Mar 20, 2019
1 parent 3e69819 commit 8c2e5ec369c90d49e7a4b8777541ab7e0796ba96
Showing with 33 additions and 56 deletions.
  1. +15 −42 mapscript/python/tests/cases/layer_test.py
  2. +18 −14 mapscript/python/tests/cases/shape_test.py
@@ -68,63 +68,36 @@ def setUp(self):
def tearDown(self):
self.layer.close()

def testLayerGetItemDefinition(self):
def testLayerGetItemType(self):
"""test getting layer item information for the first item"""

gml_item = self.layer.getItemDefinition(0)
assert gml_item.name == "FID"
assert gml_item.type == "Integer"
assert gml_item.alias is None
assert gml_item.encode == 1
assert gml_item.minOccurs == 0
assert gml_item.outputByDefault == 1
assert gml_item.precision == 0
assert gml_item.template is None
assert gml_item.visible == 0
assert gml_item.width == 10
item_type = self.layer.getItemType(0)
assert item_type == "Integer"

def testLayerGetItemDefinition2(self):
"""test getting layer item information for the second item"""

gml_item = self.layer.getItemDefinition(1)
assert gml_item.name == "FNAME"
assert gml_item.type == "Character"
assert gml_item.alias is None
assert gml_item.encode == 1
assert gml_item.minOccurs == 0
assert gml_item.outputByDefault == 1
assert gml_item.precision == 0
assert gml_item.template is None
assert gml_item.visible == 0
assert gml_item.width == 10

def testLayerGetMissingItemDefinition(self):
item_type = self.layer.getItemType(1)
assert item_type == "Character"

def testLayerGetMissingItemType(self):
"""test getting item information for a non-existent index"""
gml_item = self.layer.getItemDefinition(100)
assert gml_item is None
item_type = self.layer.getItemType(100)
assert item_type is None

def testLayerGetItemDefinitionClosedLayer(self):
def testLayerGetItemTypeClosedLayer(self):
"""item definition will be None for a closed layer"""
self.layer.close()
gml_item = self.layer.getItemDefinition(0)
assert gml_item is None
item_type = self.layer.getItemType(0)
assert item_type is None

def testLayerGetNonDefinedItemDefinition(self):
def testLayerGetNonDefinedItemType(self):
"""test getting layer item information for a layer with gml_types auto"""

layer = self.map.getLayerByName('POLYGON')
layer.open()
gml_item = layer.getItemDefinition(0)
assert gml_item.name == "FID"
assert gml_item.type is None
assert gml_item.alias is None
assert gml_item.encode == 1
assert gml_item.minOccurs == 0
assert gml_item.outputByDefault == 1
assert gml_item.precision == 0
assert gml_item.template is None
assert gml_item.visible == 0
assert gml_item.width == 0
item_type = layer.getItemType(0)
assert item_type == ""
layer.close()


@@ -88,12 +88,12 @@ def testGetNumFeatures(self):

def testShapeGeoInterface(self):
"""return the shape using the __geo_interface__ protocol with no attribute names"""
inline_layer = self.map.getLayerByName('POLYGON')
inline_layer.open()
inline_layer.template = "FAKE"
inline_layer.queryByIndex(self.map, -1, 0)
res = inline_layer.getResult(0)
s = inline_layer.getShape(res)
layer = self.map.getLayerByName('POLYGON')
layer.open()
layer.template = "FAKE"
layer.queryByIndex(self.map, -1, 0)
res = layer.getResult(0)
s = layer.getShape(res)
assert s.__geo_interface__ == {
'geometry': {
'type': 'Polygon',
@@ -105,15 +105,17 @@ def testShapeGeoInterface(self):
'properties': {'1': 'A Polygon', '0': '1'}
}

layer.close()

def testShapeGeoInterfaceWithFields(self):
"""return the shape using the __geo_interface__ protocol with attribute names"""
inline_layer = self.map.getLayerByName('POLYGON')
inline_layer.open()
inline_layer.template = "FAKE"
inline_layer.queryByIndex(self.map, -1, 0)
res = inline_layer.getResult(0)
s = inline_layer.getShape(res)
s.attributes = inline_layer.getAttributes()
layer = self.map.getLayerByName('POINT')
layer.open()
layer.template = "FAKE"
layer.queryByIndex(self.map, -1, 0)
res = layer.getResult(0)
s = layer.getShape(res)
s.itemdefinitions = layer.getItemDefinitions()
assert s.__geo_interface__ == {
'geometry': {
'type': 'Polygon',
@@ -122,9 +124,11 @@ def testShapeGeoInterfaceWithFields(self):
},
'type': 'Feature',
'bbox': (-0.25, 51.227222, 0.25, 51.727222),
'properties': {'FNAME': 'A Polygon', 'FID': '1'}
'properties': {'FNAME': 'A Point', 'FID': 1}
}

layer.close()


class ShapeValuesTestCase(unittest.TestCase):

0 comments on commit 8c2e5ec

Please sign in to comment.
You can’t perform that action at this time.