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

Refactor clproto tests #75

Merged
merged 12 commits into from
Feb 10, 2023
Merged

Refactor clproto tests #75

merged 12 commits into from
Feb 10, 2023

Conversation

domire8
Copy link
Member

@domire8 domire8 commented Feb 9, 2023

Description

There is no real parent issue for this but it explains why the two issues above were opened in the first place. Let me try to explain:

  • The clproto tests in cpp have a lot of code duplication. This made me think about better ways to test all the combinations in both C++ and Python (hence the pytest issue)
  • In order to template the C++ test in one unified helper, I needed an empty constructor for the parameters (one of the points in the parameter issue)
  • Encoding and decoding parameters, setting them empty and encode/decode again - which is now doable in just two lines - did not work because the encoding of empty parameters as well as the ParameterContainer class in Python were not correct (hence the rest of the parameter issue)

There are a lot of changes, sorry for that. Review by commit

  1. I think the C++ tests are easier to understand and there, the deleted lines outweigh the added lines by far
  2. This is not quite the case for Python, I think there the changes are a bit harder to grasp. I added helpers to conftest.py that will be useful for all other test modules too. They compare the different types of state representation classes.

Review guidelines

Estimated Time of Review: 40 minutes

@domire8 domire8 linked an issue Feb 9, 2023 that may be closed by this pull request
clproto::test_encode_decode<Parameter<TypeParam>>(
param, clproto::PARAMETER_MESSAGE, test_parameter_equal<Parameter<TypeParam>>, std::get<1>(this->test_case_));
param.reset();
// FIXME(#50): Encoding of empty parameters is incorrect
Copy link
Member Author

Choose a reason for hiding this comment

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

In order to make this work, we'll need another PR. I already have the fix but I wanted to create the test first and then make it work

parameter = sr.Parameter(name, value, parameter_type)
assert_encode_decode(parameter, clproto.MessageType.PARAMETER_MESSAGE, helpers.assert_parameter_equal, message_type)
parameter.reset()
# FIXME: empty parameters that are encoded and decoded are not empty anymore!
Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment as above

eeberhard
eeberhard previously approved these changes Feb 10, 2023
Copy link
Member

@eeberhard eeberhard left a comment

Choose a reason for hiding this comment

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

This is great 🔥 Well done leveraging the typed test and parameterized test fixtures. I always appreciate when we can apply learnings from later projects back to our early code to keep things up to a high standard.

I also definitely agree with the FIXMEs deferred to a later issue.

I also wanted to say, I kept an eye on the clock for this one and your ETR was spot on ;)

python/test/conftest.py Outdated Show resolved Hide resolved
@domire8
Copy link
Member Author

domire8 commented Feb 10, 2023

I had to rebase and push again anyway, so I included your nitpicks

@@ -0,0 +1,41 @@
#pragma once
Copy link
Member

Choose a reason for hiding this comment

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

it's a nitpick on a nitpick but my written suggestion was to name the file after the function, test_encode_decode.hpp

@domire8 domire8 merged commit fb9d706 into develop Feb 10, 2023
@domire8 domire8 deleted the feature/clproto-tests branch February 10, 2023 20:18
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.

Move to pytest for Python bindings tests
2 participants