Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ID validation #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions development_utilities/gen_unit_test_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import json
from enum import Enum
import uuid
import inspect
import pprint
import random
Expand All @@ -14,7 +15,7 @@
Callable,
Sequence,
)
import uuid


import pydantic

Expand Down Expand Up @@ -172,7 +173,7 @@ def dump_test_data_as_constructor_field_for(test_data, field_type: Type) -> str:
offset: datetime.timedelta = test_data.tzinfo.utcoffset(None)
value = f"datetime(year={test_data.year}, month={test_data.month}, day={test_data.day}, hour={test_data.hour}, minute={test_data.minute}, second={test_data.second}, tzinfo=offset(offset=timedelta(seconds={offset.total_seconds()})))"
elif field_type is uuid.UUID:
value = f'uuid.UUID("{test_data}")'
value = f'"{test_data}"'
else:
raise RuntimeError(
f"Please implement dump test data for field type {field_type}"
Expand Down Expand Up @@ -260,7 +261,7 @@ def dump_test_data_as_json_for(test_data: dict, class_: Type) -> dict:
from datetime import timedelta, datetime, timezone as offset
import json
from unittest import TestCase
import uuid


from s2python.common import *
from s2python.frbc import *
Expand Down
12 changes: 9 additions & 3 deletions development_utilities/generate_s2_message_type_to_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
all_members.sort(key=lambda t: t[0])


print("""
print(
"""
from s2python.common import *
from s2python.frbc import *

TYPE_TO_MESSAGE_CLASS = {""")
TYPE_TO_MESSAGE_CLASS = {"""
)

for name, member in all_members:
if inspect.isclass(member) and hasattr(member, '__fields__') and ('message_type' in member.__fields__):
if (
inspect.isclass(member)
and hasattr(member, "__fields__")
and ("message_type" in member.__fields__)
):
print(f" '{member.__fields__['message_type'].default}': {name},")

print("}")
4 changes: 0 additions & 4 deletions src/s2python/common/handshake.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import Handshake as GenHandshake
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,5 +9,3 @@
class Handshake(GenHandshake, S2Message["Handshake"]):
class Config(GenHandshake.Config):
validate_assignment = True

message_id: uuid.UUID = GenHandshake.__fields__["message_id"].field_info # type: ignore[assignment]
4 changes: 0 additions & 4 deletions src/s2python/common/handshake_response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import HandshakeResponse as GenHandshakeResponse
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,5 +9,3 @@
class HandshakeResponse(GenHandshakeResponse, S2Message["HandshakeResponse"]):
class Config(GenHandshakeResponse.Config):
validate_assignment = True

message_id: uuid.UUID = GenHandshakeResponse.__fields__["message_id"].field_info # type: ignore[assignment]
7 changes: 0 additions & 7 deletions src/s2python/common/instruction_status_update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import (
InstructionStatusUpdate as GenInstructionStatusUpdate,
)
Expand All @@ -15,8 +13,3 @@ class InstructionStatusUpdate(
):
class Config(GenInstructionStatusUpdate.Config):
validate_assignment = True

message_id: uuid.UUID = GenInstructionStatusUpdate.__fields__["message_id"].field_info # type: ignore[assignment]
instruction_id: uuid.UUID = GenInstructionStatusUpdate.__fields__[
"instruction_id"
].field_info # type: ignore[assignment]
3 changes: 1 addition & 2 deletions src/s2python/common/power_forecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.common.power_forecast_element import PowerForecastElement
from s2python.generated.gen_s2 import PowerForecast as GenPowerForecast
Expand All @@ -14,7 +14,6 @@ class PowerForecast(GenPowerForecast, S2Message["PowerForecast"]):
class Config(GenPowerForecast.Config):
validate_assignment = True

message_id: uuid.UUID = GenPowerForecast.__fields__["message_id"].field_info # type: ignore[assignment]
elements: List[PowerForecastElement] = GenPowerForecast.__fields__[
"elements"
].field_info # type: ignore[assignment]
3 changes: 1 addition & 2 deletions src/s2python/common/power_measurement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.common.power_value import PowerValue
from s2python.generated.gen_s2 import PowerMeasurement as GenPowerMeasurement
Expand All @@ -14,5 +14,4 @@ class PowerMeasurement(GenPowerMeasurement, S2Message["PowerMeasurement"]):
class Config(GenPowerMeasurement.Config):
validate_assignment = True

message_id: uuid.UUID = GenPowerMeasurement.__fields__["message_id"].field_info # type: ignore[assignment]
values: List[PowerValue] = GenPowerMeasurement.__fields__["values"].field_info # type: ignore[assignment]
6 changes: 0 additions & 6 deletions src/s2python/common/reception_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import ReceptionStatus as GenReceptionStatus
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,7 +9,3 @@
class ReceptionStatus(GenReceptionStatus, S2Message["ReceptionStatus"]):
class Config(GenReceptionStatus.Config):
validate_assignment = True

subject_message_id: uuid.UUID = GenReceptionStatus.__fields__[
"subject_message_id"
].field_info # type: ignore[assignment]
5 changes: 2 additions & 3 deletions src/s2python/common/resource_manager_details.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.common.duration import Duration
from s2python.common.role import Role
Expand All @@ -22,6 +22,5 @@ class Config(GenResourceManagerDetails.Config):
instruction_processing_delay: Duration = GenResourceManagerDetails.__fields__[
"instruction_processing_delay"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenResourceManagerDetails.__fields__["message_id"].field_info # type: ignore[assignment]
resource_id: uuid.UUID = GenResourceManagerDetails.__fields__["resource_id"].field_info # type: ignore[assignment]

roles: List[Role] = GenResourceManagerDetails.__fields__["roles"].field_info # type: ignore[assignment]
5 changes: 0 additions & 5 deletions src/s2python/common/revoke_object.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import RevokeObject as GenRevokeObject
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,6 +9,3 @@
class RevokeObject(GenRevokeObject, S2Message["RevokeObject"]):
class Config(GenRevokeObject.Config):
validate_assignment = True

message_id: uuid.UUID = GenRevokeObject.__fields__["message_id"].field_info # type: ignore[assignment]
object_id: uuid.UUID = GenRevokeObject.__fields__["object_id"].field_info # type: ignore[assignment]
4 changes: 0 additions & 4 deletions src/s2python/common/select_control_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import SelectControlType as GenSelectControlType
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,5 +9,3 @@
class SelectControlType(GenSelectControlType, S2Message["SelectControlType"]):
class Config(GenSelectControlType.Config):
validate_assignment = True

message_id: uuid.UUID = GenSelectControlType.__fields__["message_id"].field_info # type: ignore[assignment]
4 changes: 0 additions & 4 deletions src/s2python/common/session_request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import SessionRequest as GenSessionRequest
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,5 +9,3 @@
class SessionRequest(GenSessionRequest, S2Message["SessionRequest"]):
class Config(GenSessionRequest.Config):
validate_assignment = True

message_id: uuid.UUID = GenSessionRequest.__fields__["message_id"].field_info # type: ignore[assignment]
3 changes: 0 additions & 3 deletions src/s2python/common/timer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.common.duration import Duration
from s2python.generated.gen_s2 import Timer as GenTimer
from s2python.validate_values_mixin import (
Expand All @@ -13,5 +11,4 @@ class Timer(GenTimer, S2Message["Timer"]):
class Config(GenTimer.Config):
validate_assignment = True

id: uuid.UUID = GenTimer.__fields__["id"].field_info # type: ignore[assignment]
duration: Duration = GenTimer.__fields__["duration"].field_info # type: ignore[assignment]
8 changes: 0 additions & 8 deletions src/s2python/common/transition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import uuid
from typing import Optional, List

from s2python.common.duration import Duration
Expand All @@ -14,13 +13,6 @@ class Transition(GenTransition, S2Message["Transition"]):
class Config(GenTransition.Config):
validate_assignment = True

id: uuid.UUID = GenTransition.__fields__["id"].field_info # type: ignore[assignment]
from_: uuid.UUID = GenTransition.__fields__["from_"].field_info # type: ignore[assignment]
to: uuid.UUID = GenTransition.__fields__["to"].field_info # type: ignore[assignment]
start_timers: List[uuid.UUID] = GenTransition.__fields__["start_timers"].field_info # type: ignore[assignment]
blocking_timers: List[uuid.UUID] = GenTransition.__fields__[
"blocking_timers"
].field_info # type: ignore[assignment]
transition_duration: Optional[Duration] = GenTransition.__fields__[
"transition_duration"
].field_info # type: ignore[assignment]
3 changes: 0 additions & 3 deletions src/s2python/frbc/frbc_actuator_description.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from typing import List, Any, Dict

from pydantic import root_validator
Expand All @@ -24,7 +22,6 @@ class FRBCActuatorDescription(
class Config(GenFRBCActuatorDescription.Config):
validate_assignment = True

id: uuid.UUID = GenFRBCActuatorDescription.__fields__["id"].field_info # type: ignore[assignment]
operation_modes: List[FRBCOperationMode] = GenFRBCActuatorDescription.__fields__[
"operation_modes"
].field_info # type: ignore[assignment]
Expand Down
11 changes: 1 addition & 10 deletions src/s2python/frbc/frbc_actuator_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Optional
import uuid


from s2python.generated.gen_s2 import FRBCActuatorStatus as GenFRBCActuatorStatus
from s2python.validate_values_mixin import (
Expand All @@ -12,12 +12,3 @@
class FRBCActuatorStatus(GenFRBCActuatorStatus, S2Message["FRBCActuatorStatus"]):
class Config(GenFRBCActuatorStatus.Config):
validate_assignment = True

active_operation_mode_id: uuid.UUID = GenFRBCActuatorStatus.__fields__[
"active_operation_mode_id"
].field_info # type: ignore[assignment]
actuator_id: uuid.UUID = GenFRBCActuatorStatus.__fields__["actuator_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCActuatorStatus.__fields__["message_id"].field_info # type: ignore[assignment]
previous_operation_mode_id: Optional[uuid.UUID] = GenFRBCActuatorStatus.__fields__[
"previous_operation_mode_id"
].field_info # type: ignore[assignment]
5 changes: 1 addition & 4 deletions src/s2python/frbc/frbc_fill_level_target_profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.frbc.frbc_fill_level_target_profile_element import (
FRBCFillLevelTargetProfileElement,
Expand All @@ -25,6 +25,3 @@ class Config(GenFRBCFillLevelTargetProfile.Config):
] = GenFRBCFillLevelTargetProfile.__fields__[
"elements"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCFillLevelTargetProfile.__fields__[
"message_id"
].field_info # type: ignore[assignment]
7 changes: 0 additions & 7 deletions src/s2python/frbc/frbc_instruction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import FRBCInstruction as GenFRBCInstruction
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,8 +9,3 @@
class FRBCInstruction(GenFRBCInstruction, S2Message["FRBCInstruction"]):
class Config(GenFRBCInstruction.Config):
validate_assignment = True

actuator_id: uuid.UUID = GenFRBCInstruction.__fields__["actuator_id"].field_info # type: ignore[assignment]
id: uuid.UUID = GenFRBCInstruction.__fields__["id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCInstruction.__fields__["message_id"].field_info # type: ignore[assignment]
operation_mode: uuid.UUID = GenFRBCInstruction.__fields__["operation_mode"].field_info # type: ignore[assignment]
3 changes: 1 addition & 2 deletions src/s2python/frbc/frbc_leakage_behaviour.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.frbc.frbc_leakage_behaviour_element import FRBCLeakageBehaviourElement
from s2python.generated.gen_s2 import FRBCLeakageBehaviour as GenFRBCLeakageBehaviour
Expand All @@ -17,4 +17,3 @@ class Config(GenFRBCLeakageBehaviour.Config):
elements: List[FRBCLeakageBehaviourElement] = GenFRBCLeakageBehaviour.__fields__[
"elements"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCLeakageBehaviour.__fields__["message_id"].field_info # type: ignore[assignment]
3 changes: 1 addition & 2 deletions src/s2python/frbc/frbc_operation_mode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from itertools import pairwise
import uuid

from typing import List, Dict, Any

from pydantic import root_validator
Expand All @@ -19,7 +19,6 @@ class FRBCOperationMode(GenFRBCOperationMode, S2Message["FRBCOperationMode"]):
class Config(GenFRBCOperationMode.Config):
validate_assignment = True

id: uuid.UUID = GenFRBCOperationMode.__fields__["id"].field_info # type: ignore[assignment]
elements: List[FRBCOperationModeElement] = GenFRBCOperationMode.__fields__[
"elements"
].field_info # type: ignore[assignment]
Expand Down
4 changes: 0 additions & 4 deletions src/s2python/frbc/frbc_storage_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import FRBCStorageStatus as GenFRBCStorageStatus
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,5 +9,3 @@
class FRBCStorageStatus(GenFRBCStorageStatus, S2Message["FRBCStorageStatus"]):
class Config(GenFRBCStorageStatus.Config):
validate_assignment = True

message_id: uuid.UUID = GenFRBCStorageStatus.__fields__["message_id"].field_info # type: ignore[assignment]
4 changes: 2 additions & 2 deletions src/s2python/frbc/frbc_system_description.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.generated.gen_s2 import FRBCSystemDescription as GenFRBCSystemDescription
from s2python.validate_values_mixin import (
Expand All @@ -20,7 +20,7 @@ class Config(GenFRBCSystemDescription.Config):
actuators: List[FRBCActuatorDescription] = GenFRBCSystemDescription.__fields__[
"actuators"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCSystemDescription.__fields__["message_id"].field_info # type: ignore[assignment]

storage: FRBCStorageDescription = GenFRBCSystemDescription.__fields__[
"storage"
].field_info # type: ignore[assignment]
6 changes: 0 additions & 6 deletions src/s2python/frbc/frbc_timer_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from s2python.generated.gen_s2 import FRBCTimerStatus as GenFRBCTimerStatus
from s2python.validate_values_mixin import (
catch_and_convert_exceptions,
Expand All @@ -11,7 +9,3 @@
class FRBCTimerStatus(GenFRBCTimerStatus, S2Message["FRBCTimerStatus"]):
class Config(GenFRBCTimerStatus.Config):
validate_assignment = True

actuator_id: uuid.UUID = GenFRBCTimerStatus.__fields__["actuator_id"].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCTimerStatus.__fields__["message_id"].field_info # type: ignore[assignment]
timer_id: uuid.UUID = GenFRBCTimerStatus.__fields__["timer_id"].field_info # type: ignore[assignment]
3 changes: 1 addition & 2 deletions src/s2python/frbc/frbc_usage_forecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List
import uuid


from s2python.generated.gen_s2 import FRBCUsageForecast as GenFRBCUsageForecast
from s2python.validate_values_mixin import (
Expand All @@ -17,4 +17,3 @@ class Config(GenFRBCUsageForecast.Config):
elements: List[FRBCUsageForecastElement] = GenFRBCUsageForecast.__fields__[
"elements"
].field_info # type: ignore[assignment]
message_id: uuid.UUID = GenFRBCUsageForecast.__fields__["message_id"].field_info # type: ignore[assignment]
5 changes: 1 addition & 4 deletions src/s2python/generated/gen_s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ class Config:
)


class ID(BaseModel):
__root__: constr(regex=r"[a-zA-Z0-9\-_:]{2,64}") = Field(
..., description="An identifier expressed as a UUID"
)
ID = constr(regex=r"[a-zA-Z0-9\-_:]{2,64}")


class InstructionStatus(Enum):
Expand Down
Loading
Loading