-
-
Notifications
You must be signed in to change notification settings - Fork 200
fix: intersect OneOf and Equal choices in field2choices #1069
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,7 +198,62 @@ def test_field_with_choices_multiple(spec_fixture): | |
| ] | ||
| ) | ||
| res = spec_fixture.openapi.field2property(field) | ||
| assert set(res["enum"]) == {"brian", "john"} | ||
| assert res["enum"] == ["brian", "john"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the use of set here was intentional as we don't want to ensure the order.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — reverted to set() comparison. |
||
|
|
||
|
|
||
| def test_field_with_choices_multiple_non_intersecting(spec_fixture): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd write oneof instead of choices in the test name.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||
| field = fields.Str( | ||
| validate=[ | ||
| validate.OneOf(["freddie", "brian"]), | ||
| validate.OneOf(["john", "roger"]), | ||
| ] | ||
| ) | ||
| res = spec_fixture.openapi.field2property(field) | ||
| assert res["enum"] == [] | ||
|
|
||
|
|
||
| def test_field_with_choices_and_equal(spec_fixture): | ||
| field = fields.Str( | ||
| validate=[ | ||
| validate.OneOf(["freddie", "brian", "john"]), | ||
| validate.Equal("brian"), | ||
| ] | ||
| ) | ||
| res = spec_fixture.openapi.field2property(field) | ||
| assert res["enum"] == ["brian"] | ||
|
|
||
|
|
||
| def test_field_with_choices_and_equal_non_intersecting(spec_fixture): | ||
| field = fields.Str( | ||
| validate=[ | ||
| validate.OneOf(["freddie", "brian"]), | ||
| validate.Equal("john"), | ||
| ] | ||
| ) | ||
| res = spec_fixture.openapi.field2property(field) | ||
| assert res["enum"] == [] | ||
|
|
||
|
|
||
| def test_field_with_multiple_equal_matching(spec_fixture): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the whole thing could be factorized in three tests:
using parametrization to pass inputs and expected output.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Factorized into three parametrized tests: multiple_oneof, multiple_equal, oneof_and_equal. |
||
| field = fields.Str( | ||
| validate=[ | ||
| validate.Equal("brian"), | ||
| validate.Equal("brian"), | ||
| ] | ||
| ) | ||
| res = spec_fixture.openapi.field2property(field) | ||
| assert res["enum"] == ["brian"] | ||
|
|
||
|
|
||
| def test_field_with_multiple_equal_conflicting(spec_fixture): | ||
| field = fields.Str( | ||
| validate=[ | ||
| validate.Equal("freddie"), | ||
| validate.Equal("brian"), | ||
| ] | ||
| ) | ||
| res = spec_fixture.openapi.field2property(field) | ||
| assert res["enum"] == [] | ||
|
|
||
|
|
||
| def test_field_with_additional_metadata(spec_fixture): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been wondering why we don't use a set here and update it in the loop.
This is probably due to a slight performance advantage doing it this way.