Compare commits

...

4 Commits

Author SHA1 Message Date
Jonathon Broughton a704aded80 Refactor parameter value checks to use float conversion (#49)
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
- Updated methods to convert parameter values to float.
- Removed type checks and exceptions for non-numeric types.
- Simplified return logic for invalid conversions.
2025-02-20 12:23:43 +00:00
Jonathon Broughton 90c5051fc6 Update test_user_entry.py (#44) 2025-02-18 20:37:06 +00:00
Jonathon Broughton ec6bdf3485 Update requirements.txt (#43)
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2025-02-18 19:15:21 +00:00
Jonathon Broughton ceaa75d40a Update requirements.txt (#41) 2025-02-18 19:12:26 +00:00
4 changed files with 22 additions and 15 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ dependencies = [
"pydantic==2.10.6",
"python-dotenv>=1.0.1",
"python-levenshtein>=0.26.1",
"specklepy>=2.21.2",
"specklepy>=2.21.3",
]
+4 -4
View File
@@ -1,7 +1,7 @@
annotated-types==0.7.0
anyio==4.8.0
appdirs==1.4.4
attrs==25.1.0
attrs==23.2.0
backoff==2.2.1
black==25.1.0
certifi==2025.1.31
@@ -13,7 +13,7 @@ gql==3.5.0
graphql-core==3.2.6
h11==0.14.0
httpcore==1.0.7
httpx==0.28.1
httpx==0.25.2
idna==3.10
iniconfig==2.0.0
levenshtein==0.26.1
@@ -29,7 +29,7 @@ platformdirs==4.3.6
pluggy==1.5.0
propcache==0.2.1
pydantic==2.10.6
pydantic-core==2.29.0
pydantic-core==2.27.2
pydantic-settings==2.7.1
pytest==8.3.4
pytest-assertcount==1.0.0
@@ -49,6 +49,6 @@ typing-extensions==4.12.2
tzdata==2025.1
ujson==5.10.0
urllib3==2.3.0
websockets==15.0
websockets==11.0.3
wrapt==1.17.2
yarl==1.18.3
+15 -8
View File
@@ -253,9 +253,11 @@ class PropertyRules:
parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name)
if parameter_value is None:
return False
if not isinstance(parameter_value, int | float):
raise ValueError(f"Parameter value must be a number, got {type(parameter_value)}")
return parameter_value <= PropertyRules.parse_number_from_string(threshold)
try:
parameter_value = float(parameter_value)
except (ValueError, TypeError):
return False # Return False if the value cannot be converted to a number
return parameter_value > PropertyRules.parse_number_from_string(threshold)
@staticmethod
def is_parameter_value_less_than(speckle_object: Base, parameter_name: str, threshold: str) -> bool:
@@ -267,9 +269,12 @@ class PropertyRules:
parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name)
if parameter_value is None:
return False
if not isinstance(parameter_value, int | float):
raise ValueError(f"Parameter value must be a number, got {type(parameter_value)}")
return parameter_value >= PropertyRules.parse_number_from_string(threshold)
try:
parameter_value = float(parameter_value)
except (ValueError, TypeError):
return False # Return False if the value cannot be converted to a number
return parameter_value < PropertyRules.parse_number_from_string(threshold)
@staticmethod
def is_parameter_value_in_range(speckle_object: Base, parameter_name: str, value_range: str) -> bool:
@@ -285,8 +290,10 @@ class PropertyRules:
parameter_value = PropertyRules.get_parameter_value(speckle_object, parameter_name)
if parameter_value is None:
return False
if not isinstance(parameter_value, int | float):
raise ValueError(f"Parameter value must be a number, got {type(parameter_value)}")
try:
parameter_value = float(parameter_value)
except (ValueError, TypeError):
return False # Return False if the value cannot be converted to a number
return min_value <= parameter_value <= max_value
+2 -2
View File
@@ -16,8 +16,8 @@ from src.rule_processor import SeverityLevel, get_severity
("ERROR", SeverityLevel.ERROR),
("error", SeverityLevel.ERROR),
("Error", SeverityLevel.ERROR),
("WARN", SeverityLevel.WARNING), # Invalid → Defaults to ERROR
("warn", SeverityLevel.WARNING), # Invalid → Defaults to ERROR
("WARN", SeverityLevel.WARNING),
("warn", SeverityLevel.WARNING),
("Critical", SeverityLevel.ERROR), # Invalid → Defaults to ERROR
("Severe", SeverityLevel.ERROR), # Invalid → Defaults to ERROR
("", SeverityLevel.ERROR), # Empty string → Defaults to ERROR