Skip to content

Commit 19e7762

Browse files
committed
Refactor unconnected_port check and minor changes in other checks; Incorporate some of existing validations from schema_PoC.json into schema_PoC_optimizer.json
1 parent fec6208 commit 19e7762

7 files changed

Lines changed: 311 additions & 47 deletions

File tree

esdlvalidator/validation/functions/check_has_pair.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ def execute(self):
4141
if keyword in p:
4242
p_paired = p.replace(keyword, "")
4343
if p_paired not in properties:
44-
msg = f"{self.value.id} ({self.value.name}) does not have a paired entity with '{property}' = '{p_paired}'"
44+
msg = f"{self.value.name} (id: {self.value.id}) does not have a paired entity with [{property}] = '{p_paired}'"
4545
else:
4646
has_paired = any(
4747
keyword in item and item.replace(keyword, "") == p
4848
for item in properties
4949
)
5050
if not has_paired:
51-
msg = f"{self.value.id} ({self.value.name}) does not have a paired entity with '{property}' property containing: '{p}' and '{keyword}'"
51+
msg = f"{self.value.name} (id: {self.value.id}) does not have a paired entity with [{property}] containing: '{p}' and '{keyword}'"
5252

5353
if msg:
54-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
54+
if self.args.get("resultMsgJSON"):
5555
result = { "offending_asset": self.value.id, "message": msg }
5656
return CheckResult(False, result)
5757
else:

esdlvalidator/validation/functions/check_is_supported_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def execute(self):
3838
entity_type = type(self.value).__name__
3939
result = f"{self.value.id} is of type {entity_type}, which is not included in the supported types [{', '.join(types)}]."
4040

41-
if "resultMsgJSON" in self.args and self.args["resultMsgJSON"]:
41+
if self.args.get("resultMsgJSON"):
4242
msg = {"offending_asset": self.value.id, "message": result}
4343
return CheckResult(supported_type, msg)
4444

esdlvalidator/validation/functions/check_multi_cond_xor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def execute(self):
2424
msg = {"offending_asset": self.value.id}
2525
if "properties" not in self.args or "violations" not in self.args:
2626
result = "Bad Schema: Either properties or violations missing from schema for this check"
27-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
27+
if self.args.get("resultMsgJSON"):
2828
msg["message"] = result
2929
return CheckResult(False, msg)
3030
else:
3131
return CheckResult(False, result)
3232
if len(self.args["properties"]) != len(self.args["violations"]):
3333
result = "Bad Schema: Number of properties don't match number of violations"
34-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
34+
if self.args.get("resultMsgJSON"):
3535
msg["message"] = result
3636
return CheckResult(False, msg)
3737
else:
@@ -43,7 +43,7 @@ def execute(self):
4343
v = self.args["violations"][i]
4444
if not utils.has_attribute(self.value, p):
4545
result = "property {0} not found".format(p)
46-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
46+
if self.args.get("resultMsgJSON"):
4747
msg["message"] = result
4848
return CheckResult(False, msg)
4949
else:
@@ -56,9 +56,8 @@ def execute(self):
5656
fail = True
5757

5858
if fail:
59-
result = "Only one of {} must be defined for asset {} ({})".format(" or ".join(self.args['properties']),
60-
self.value.id, self.value.name)
61-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
59+
result = f"One of {' or '.join(self.args['properties'])} must be defined for {self.value.__class__.__name__} (id: {self.value.id}, name: {self.value.name})"
60+
if self.args.get("resultMsgJSON"):
6261
msg["message"] = result
6362
return CheckResult(False, msg)
6463
else:

esdlvalidator/validation/functions/check_property_uniqueness.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def execute(self):
3030
if p is not None:
3131
counts = properties.count(p)
3232
if counts > 1:
33-
msg = f"{self.value.id} has a non-unique '{property}' ({p}), it occurs {counts} times in this ESDL"
34-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
33+
msg = f"{self.value.id} has a non-unique [{property}] ({p}), it occurs {counts} times in this ESDL"
34+
if self.args.get("resultMsgJSON"):
3535
result = { "offending_asset": self.value.id, "message": msg }
3636
return CheckResult(False, result)
3737
else:

esdlvalidator/validation/functions/check_reference_count_in_range.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from esdlvalidator.validation.functions.function import FunctionFactory, FunctionCheck, FunctionDefinition, \
44
ArgDefinition, FunctionType, CheckResult
55

6-
76
@FunctionFactory.register(FunctionType.CHECK, "reference_count_in_range")
87
class ReferenceCountInRange(FunctionCheck):
98

@@ -39,12 +38,12 @@ def execute(self):
3938

4039
msg = None
4140
if len(r) > max:
42-
msg = f"{self.value.id} ({self.value.name}) has {len(r)} {referenceType}, more than the allowed maximum ({max})"
41+
msg = f"{self.value.name} (id: {self.value.id}) has ({len(r)}) [{referenceType}], more than the allowed maximum ({max})"
4342
elif len(r) < min:
44-
msg = f"{self.value.id} ({self.value.name}) has {len(r)} {referenceType}, less than the allowed minimum ({min})"
43+
msg = f"{self.value.name} (id: {self.value.id}) has ({len(r)}) [{referenceType}], less than the allowed minimum ({min})"
4544

4645
if msg:
47-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
46+
if self.args.get("resultMsgJSON"):
4847
result = { "offending_asset": self.value.id, "message": msg }
4948
return CheckResult(False, result)
5049
else:
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import json
2-
3-
from esdlvalidator.validation.functions.function import FunctionFactory, FunctionCheck, FunctionDefinition, \
4-
ArgDefinition, FunctionType, CheckResult
1+
from esdlvalidator.validation.functions.function import (
2+
FunctionFactory,
3+
FunctionCheck,
4+
FunctionDefinition,
5+
ArgDefinition,
6+
FunctionType,
7+
CheckResult,
8+
)
59

610

711
@FunctionFactory.register(FunctionType.CHECK, "unconnected_port")
@@ -10,31 +14,30 @@ class ContainsNotConnectedTo(FunctionCheck):
1014
def get_function_definition(self):
1115
return FunctionDefinition(
1216
"unconnected_port",
13-
"Check if a port in any asset is left unconnected",
17+
"Check if ports in any asset are left unconnected",
1418
[
1519
ArgDefinition("resultMsgJSON", "Display output in JSON format", False)
16-
]
20+
],
1721
)
1822

1923
def before_execute(self):
2024
pass
2125

2226
def execute(self):
23-
msg = {"offending_asset": self.value.id}
27+
results = []
28+
2429
if len(self.value.port) == 0:
25-
result = "{} has no ports".format(self.value.id)
26-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
27-
msg["message"] = result
30+
results.append(f"{self.value.id} has no ports.")
31+
else:
32+
for port in self.value.port:
33+
if len(port.connectedTo) == 0:
34+
results.append(f"{port.__class__.__name__} (name: {port.name}) is unconnected.")
35+
36+
if len(results) > 0:
37+
if self.args.get("resultMsgJSON"):
38+
msg = {"offending_asset": self.value.id, "message": results}
2839
return CheckResult(False, msg)
2940
else:
30-
return CheckResult(False, result)
31-
for port in self.value.port:
32-
if len(port.connectedTo) == 0:
33-
result = "{}'s {} is unconnected".format(self.value.id, port.__class__.__name__)
34-
if 'resultMsgJSON' in self.args and self.args['resultMsgJSON']:
35-
msg["message"] = result
36-
return CheckResult(False, msg)
37-
else:
38-
return CheckResult(False, result)
39-
40-
return CheckResult(True)
41+
return CheckResult(False, results)
42+
else:
43+
return CheckResult(True)

0 commit comments

Comments
 (0)