-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
feat(type-coverage-generation): Model type coverage batch generation #390
Conversation
Please see the suggested sourcery refactorings, it cant merge into forks for some reason: |
done |
@sam-or is this ready for review or are you still working on it? |
There a still a couple of tests failing that I won’t get to look at until mid next week. But other than fixing those there’s hopefully not too much else that needs doing, so it should be good for review. |
tests seem to be passing now, should be good for review |
Could you merge from main and run |
@sam-or Sorry for the delay. I'll take a look this weekend :) |
I did review the code and I think it's great, but I'll be honest, I'm not sure I'm seeing the benefit of this feature too much. The reason for that is because once #397 is done, then @dataclass
class Bar:
bar_val: int | str | bool
@dataclass
class Foo:
foo_val: int | str
bar: Bar
FooFactory = DataclassFactory.create_factory(Foo)
coverage = list(FooFactory.coverage())
print(len(coverage)) # current output = 3 Currently, the output is |
Thank you very much for your review. I realise I have probably not explained the intention very well. The reason for wanting this feature over something like hypothesis (which I am currently using) is that I wanted something that would always generate examples of a model with every option of what that type could be, every single time that a batch is generated. The other goal is to achieve this with the minimum number of examples in a batch. With hypothesis this is not guaranteed, nor is it guaranteed with other methods based on randomness. Tools like hypothesis are amazing but I don't wish to rely on a statistical approach to this "coverage", which is why I wanted to move away from fuzzing to a more targeted method to generating the kind of test data that is best for my use case. Please let me know what your thoughts are on this, perhaps this feature is a bit niche so I understand your reservations. So to answer your question about expected output, we would be expecting 3 examples because the highest variation of any model in your example is Foo(foo_val=123, bar_var=Bar(bar_val=321)) # foo_val: int, bar_val: int
Foo(foo_val="abc", bar_var=Bar(bar_val="def")) # foo_val: str, bar_val: str
Foo(foo_val=456, bar_var=Bar(bar_val=True)) # foo_val: int (wraps around), bar_val: bool As you can see it covers every value in the union types of |
Aah okay now I get what you were trying to do. I do think it's helpful, but also like you said it might be a bit too niche of a feature for us to merge and then maintain. Thoughts, @litestar-org/members? |
Perhaps to try to sell it a bit more I'll try to explain the benefits I see in this feature;
I do hope that others might find it as useful as I will. I'm also more than happy to continue to spend time on this in the future, to help maintain and improve it |
@sam-or is this ready? If so, could you add documentation for this as well?? |
Yes it is, I'll add documentation now |
@sam-or sorry for the delay! I wanted to take another look into this properly and I'll definitely do it in a few days :) |
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.
@sam-or first of all, sorry for the delay! I have left a few comments and once those are resolved, I think this is good to merge :)
- Add missing docstrings - Move error handling around CoverageContainerCallable to inside - Formatting issue in documentation
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.
Thanks for this! Just one small comment regarding adding docstrings. Also, it'd be great if you could just tag me or request another review once you've made the changes. If not, I might not know whether the PR is ready without manually looking to see if it's ready for another review.
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/390 |
Ah yep no worries, will do. I've added that docstring to |
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.
@sam-or sorry for the delay and thank you for the work you've done :)
Pull Request Checklist
Description
A very simple example:
Close Issue(s)