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

Tickets/dm 42402 #124

Merged
merged 3 commits into from
Jan 24, 2024
Merged

Tickets/dm 42402 #124

merged 3 commits into from
Jan 24, 2024

Conversation

dsanmartim
Copy link
Contributor

Hello. Here is the first try of this ticket. I hope it is not too bad :)

@dsanmartim dsanmartim requested a review from tribeiro January 22, 2024 17:09
Copy link
Member

@tribeiro tribeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good... The only thing is that the tests are not following the overall idea of the testing on this module. Please, take a look at my inline comments and let me know if you need any help.

True to enable, False to disable the specified force component
controlled by the slew controller.
"""
setting_key = self._map_m1m3_slew_setting_to_name(slew_setting)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this method. You can get the "name" of the enumeration by using:

slew_setting.name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the map method here, but I needed to create a different version of it to deal with mock methods.

for key, attr in expected_attributes.items():
if not hasattr(settings_event, attr):
raise RuntimeError(
f"Expected attribute '{attr}' not found in slew controller settings event."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe print what are the valid ones? something like.

f"Expected attribute '{attr}' not found in slew controller settings event. "
f"Must be one of {expected_attributes.keys()}."

desired_setting: MTM1M3.SetSlewControllerSettings,
desired_value: bool,
) -> None:
# Prepare initial settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving these things to the MTCSAsyncMock class. and actually implementing a mock to the internals of get_m1m3_slew_controller_settings, instead of mocking the entire thing.

Basically, in setup_types you should set an attribute

self._evt_slew_controller_settings = types.SimpleNamespace(
            useAccelerationForces=False,
            useBalanceForces=False,
            triggerBoosterValves=False,
            useVelocityForces=False,
)

then define a method to retrieve the value, mtm1m3_evt_slew_controller_settings:

async def mtm1m3_evt_slew_controller_settings(
        self, *args: typing.Any, **kwargs: typing.Any
    ) -> types.SimpleNamespace:
        await asyncio.sleep(self.heartbeat_time / 4.0)
        return self._evt_slew_controller_settings

and set it up in the setup_mtm1m3 method:

m1m3_mocks = {
          ...,
          "evt_slewControllerSettings.aget.side_effect": mtm1m3_evt_slew_controller_settings,
          ...
}

Then do a similar thing on the command side to mock the behavior of setting the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have it working, but not happy with everything. Please take a look and tell me if you see anything wrong or if you see things to be improved.

Copy link
Member

@tribeiro tribeiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, looks good! I left a few additional comments I hope you will consider before merging.

Thanks!


setting_key = slew_setting.name

if setting_key is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't thing setting_key can even be None.

True to enable, False to disable the specified force component
controlled by the slew controller.
"""
if not isinstance(slew_setting, MTM1M3.SetSlewControllerSettings):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this check here. Maybe replace the type hint of slew_setting to MTM1M3.SetSlewControllerSettings?

Copy link
Contributor Author

@dsanmartim dsanmartim Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove this check, the test_set_m1m3_slew_controller_settings_with_invalid_setting fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

enable_slew_management = kwargs.get("enableSlewManagement")

if slew_setting_value is None or enable_slew_management is None:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use RuntimeError instead.


# Validate and convert the integer to the corresponding enumeration
# member name
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this try/except here is not really necessary. If you call MTM1M3.SetSlewControllerSettings(slew_setting_value) with an invalid slew_setting_value it is already going to raise a ValueError exception with enough information. So I think it is kind of duplicated effort to catch and re-raise the same exception with a different error message.

I suggest you just call

setting_enum = MTM1M3.SetSlewControllerSettings(slew_setting_value)

here

setting_attr = self.mtcs.map_slew_setting_to_attribute(setting_enum)

if setting_attr is None:
raise ValueError(f"Invalid slew setting value: {slew_setting_value}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use RuntimeError

self._evt_slew_controller_settings, setting_attr, enable_slew_management
)
else:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use RuntimeError

@dsanmartim dsanmartim force-pushed the tickets/DM-42402 branch 2 times, most recently from 362a516 to dae4691 Compare January 23, 2024 22:28
@dsanmartim dsanmartim merged commit 66c8fb0 into develop Jan 24, 2024
5 checks passed
@dsanmartim dsanmartim deleted the tickets/DM-42402 branch January 24, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants