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 pytest for union of empty type #693

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ types:
alias:
type: StringAliasExample
docs: docs for alias field
EmptyObjectExample:
fields: {}
UnionTypeExample:
docs: A type which can either be a StringExample, a set of strings, or an integer.
union:
Expand All @@ -134,8 +136,7 @@ types:
new: integer
interface: integer
property: integer
EmptyObjectExample:
fields: {}
empty: EmptyObjectExample
AliasAsMapKeyExample:
fields:
strings: map<StringAliasExample, ManyFieldExample>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions conjure-python-verifier/python/test/client/test_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ def _options(self, value):
# test for backwards compatibility
assert OptionsUnion(options="options").accept(TestOptionsUnionVisitor()) == "options"
assert OptionsUnion(options="options", type_of_union="options").accept(TestOptionsUnionVisitor()) == "options"


def test_union_visitor_for_empty_type():
from generated_integration.product import UnionTypeExample, UnionTypeExampleVisitor, EmptyObjectExample

class TestUnionTypeExampleVisitor(UnionTypeExampleVisitor):
def _empty(self, value):
return value

# test for backwards compatibility
emptyExample = EmptyObjectExample()
assert UnionTypeExample(empty=emptyExample).accept(TestUnionTypeExampleVisitor()) == emptyExample
assert UnionTypeExample(empty=emptyExample, type_of_union="empty").accept(TestUnionTypeExampleVisitor()) == emptyExample