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

Add from_abstract_repr to Device and VirtualDevice #727

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

a-corni
Copy link
Collaborator

@a-corni a-corni commented Aug 29, 2024

from_abstract_repr uses deserialize_device and checks the type of the returned device for it to match the class that generated it:

@a-corni a-corni requested a review from HGSilveri August 29, 2024 11:57
@a-corni
Copy link
Collaborator Author

a-corni commented Aug 29, 2024

@nataliejpg does this close your issue ?

Comment on lines +840 to +841
if isinstance(device, Device):
return device.to_virtual()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not a bad idea. Let's just add a Warning: section in the docstring to document this behaviour

Comment on lines 232 to 251
obj_str: str,
original_err: Type[Exception],
err_msg: str = "",
check_from_abstract_repr=False,
) -> Exception:
with pytest.raises(DeserializeDeviceError) as exc_info:
deserialize_device(obj_str)

cause = exc_info.value.__cause__
assert isinstance(cause, original_err)
assert re.search(re.escape(err_msg), str(cause)) is not None
func_to_test = [deserialize_device]
err_raised = []
if check_from_abstract_repr:
func_to_test += [
Device.from_abstract_repr,
VirtualDevice.from_abstract_repr,
]
for func in func_to_test:
with pytest.raises(DeserializeDeviceError) as exc_info:
func(obj_str)
err_raised.append(exc_info)
for exc_info in err_raised:
cause = exc_info.value.__cause__
assert isinstance(cause, original_err)
assert re.search(re.escape(err_msg), str(cause)) is not None
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is looking unnecessarily convoluted. Why not just make the function to test an argument to the function (potentially with the default being deserialize_device) and then do the test for the from_abstract_repr() outside of the function?

@a-corni
Copy link
Collaborator Author

a-corni commented Sep 13, 2024

@MatthieuMoreau0 that's of interest for you as well :)

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.

Have a method from_abstract_repr in Device to deserialize an abstract Device
2 participants