-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[Python] Changes to the templates for test code of python client. #4514
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please delete some of the existing model tests and have your template generate new examples. How about replacing the below tests:
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 will have no time for that.
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.
The request up above will take very little time.
To do it one would run:
That should take around a minute max.
These api_test and model_test updates will impact all of the tests that are auto generated when the users run the generator.
This pull request does not yet include any tests of this new functionality.
Tests will need to be added showing that both the new model tests and the api client tests produce code which runs and passes tests.
If these tests were omitted this update could breaking the tests produced in the python client. If this is too much work for this PR the model_test update and the api_test update can be broken up in to different PRs.
I am hearing that you are busy. We can wait until you have time to add this test verification. It is very important that new changes do not break the existing tests, so we can go at whatever speed works for you .
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.
Another thing that we can do is look at the content of model_test.mustache in other generators and see how they handle instantiating parameters that have model values. Maybe they have some cool tricks that we can use.
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.
Hi! I tried to remove and re-create all the existing
samples/client/petstore/python/test/*
, and the hardest tests to manage are exactly the ones with discriminators, since python and python-experimental produce different signatures. For example, for petstore/models/Cat.py:python:
def __init__(self, declawed=None, local_vars_configuration=None):
python-experimental:
def __init__(self, class_name, _check_type=True, _from_server=False, _path_to_item=(), _configuration=None, **kwargs):
The funny thing is that class_name (used in the discriminator) is NOT in the old generator, and it is required (it has no default) in the python-experimental generator.
The only solution I see is to develop a model_test.moustache for the old python, and a model_test_experimental.moustache for the python-experimental.
Any suggestions on alternative solutions?
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.
No, I mean when generating the code. For example:
What do you do, when generating the make_instance for Tiger? The options are to generate:
or
Ideally, you would generate the first when include_optional is True and the second then include_optional is False. Anyway, the code for the Cat is generated by toExampleValue, which does NOT know what include_optional is. Thus, internal properties are either generated ALWAYS with all optional parameters, or NEVER with optional parameters.
And now, here is the bomb:
It is a linked list, and it should have an empty nextTag sooner or later. Anyway, if we always comprise optional parameters in toExampleValue, we will have infinite recursion.
So, we should NEVER add optional parameters at toExampleValue level. Do you agree?
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.
So I see two solutions to these problems.
For the problem of needing to pick whether optional is required or not
Create a string property in CodegenProperty called exampleOptional. In it store the example where include_optional is true. In example store the example where include_optional is false
For the problem of a model with params or items of type model, you can include a list of Schemas or dataTypes that you are inspecting in your toExample function. Every time you call it recursively, add a schema. If we are going to add a schema that we have already added, add it then return, which will end our recursive calls.
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.
The first solution implies changing the data model, and I prefer to leave it to the next developer.
I have implement the second solution.
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 am hearing that you don't want to edit the CodegenProperty.java class.
For the first solution we can support deep include_optional=True without changing the data model.
This would work by storing the exampleOptional string value in a property that we are not using in CodegenProperty.
Why not store that value in the parameter.unescapedDescription property and add a comment describing what we are storing in it?
If this is something that you still don't want to do that's fine, just let me know. I just want you to know that there is another viable solution here.
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.
Yep, I would prefer to have this PR accepted, then do something for the api, then I could come back to this issue - after discussing it with you in a chat.