Skip to content

Commit 3fac7bc

Browse files
committed
Fixed bug in qc_tool.vector.attribute when reporting extra attributes.
See also Taskman issue #109474. Added unit tests to cover situations with extra attribute and with attribute of incorrect type.
1 parent 1eba56e commit 3fac7bc

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/qc_tool/test/test_vector_check.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,20 @@ def test_ignored_attribute_ok(self):
264264
run_check(self.params, status)
265265
self.assertEqual("ok", status.status)
266266

267+
def test_extra_attribute_fails(self):
268+
from qc_tool.vector.attribute import run_check
269+
del self.params["required"]["remark"]
270+
status = self.status_class()
271+
run_check(self.params, status)
272+
self.assertEqual("failed", status.status)
273+
274+
def test_bad_type_aborts(self):
275+
from qc_tool.vector.attribute import run_check
276+
self.params["required"]["code_12"] = "integer"
277+
status = self.status_class()
278+
run_check(self.params, status)
279+
self.assertEqual("aborted", status.status)
280+
267281
def test_missing_attribute_aborts(self):
268282
from qc_tool.vector.attribute import run_check
269283
self.params["required"].update({"missing_attribute": "string"})

src/qc_tool/vector/attribute.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def run_check(params, status):
4141
required_attrs = {attr_name.lower(): attr_type_name.lower()
4242
for attr_name, attr_type_name in params["required"].items()}
4343
ignored_attrs = params["ignored"].copy()
44-
extra_attrs = []
45-
bad_type_attrs = []
44+
extra_attrs = {}
45+
bad_type_attrs = {}
4646
for field_defn in layer.schema:
4747
field_name = field_defn.name.lower()
4848
field_type = field_defn.GetType()
@@ -53,17 +53,17 @@ def run_check(params, status):
5353
# Required attribute.
5454
if field_type not in OGR_TYPES:
5555
# Attribute type is unknown.
56-
bad_type_attrs.append(field_name, "unknown-type")
56+
bad_type_attrs.update({field_name: "unknown-type"})
5757
elif field_type not in ALLOWED_TYPES:
5858
# Attribute type is not allowed.
59-
bad_type_attrs.append(field_name, OGR_TYPES[field_type])
59+
bad_type_attrs.update({field_name: OGR_TYPES[field_type]})
6060
elif ALLOWED_TYPES[field_type] != required_attrs[field_name]:
6161
# Attribute type does not match the type in product definition.
62-
bad_type_attrs.append(field_name, ALLOWED_TYPES[field_type])
62+
bad_type_attrs.update({field_name: ALLOWED_TYPES[field_type]})
6363
del required_attrs[field_name]
6464
else:
6565
# Extra attribute.
66-
extra_attrs.append(field_name, OGR_TYPES[field_type])
66+
extra_attrs.update({field_name: OGR_TYPES[field_type]})
6767

6868
# The attributes remaining in required_attrs are missing.
6969
if len(required_attrs) > 0:

0 commit comments

Comments
 (0)