Set up Hypothesis and add property-based tests for Time precision#10373
Conversation
| yield | ||
|
|
||
|
|
||
| def assert_almost_equal(a, b, *, rtol=None, atol=None, label=''): |
There was a problem hiding this comment.
This looks like it gotta move upstream to testing utils or something.
Disclaimer: I did not follow original discussions in the other PR.
There was a problem hiding this comment.
HypothesisWorks/hypothesis#2393 summarises Hypothesis' position concisely: target()ing the loss of precision enables a guided search mode, and reporting the highest score makes serious problems obvious even after shrinking to a minimal example.
This specific function leverages that upstream functionality, and also integrates with Astropy's time and units functionality tightly enough that I'm not sure I could make it generic without introducing precision errors. I'm happy to move it elsewhere in Astropy if you have a suggestion, though personally I'd be inclined to leave it as-is until an equivalent helper is needed elsewhere ("YAGNI").
|
Thanks for reviving this, @Zac-HD ! p.s. Looks like tests are failing with |
Ah, bad interaction with function-scoped fixtures. Just adding Edit: no, wait - we're injecting a context manager, why not just use that directly? One moment... Edit 2: oh, because it's an expensive operation. Back to module-scoped fixture, plus a comment explaining this time... |
e14767e to
e7a7776
Compare
|
Oh, looks like a real failure now. Maybe @taldcroft or @mhvk can make sense of it. |
30f1f84 to
f5d1d8f
Compare
|
OK, I've marked that one test as My preference would be to merge this PR as-is if it's otherwise acceptable, and have someone with more astro background than me investigate it in a follow-up issue - 'has an xfail test' seems to me like an improvement on the no-property-tests status quo 😜 |
|
Seems a little heavy-handed to xfail the whole test when only one of the inputs failed, but then again this has dragged on long enough, so I can see pros/cons on both sides. 🤔 Please be patient with us while we wait for the subpackage maintainers to review this thoroughly. Thanks again! |
That's the thing - many inputs failed, but Hypothesis reports a single minimal reproducing example. It makes debugging much easier, though it can also make errors look less serious than they really are. |
|
@Zac-HD - the failure is almost certainly due to |
This comment has been minimized.
This comment has been minimized.
2c62cf1 to
160fdec
Compare
|
Hello @Zac-HD 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2020-05-25 01:21:54 UTC |
dad8c9e to
240d919
Compare
|
OK, I've done all the investigation I can and the tests are all passing now 😁 @mhvk, I think we're ready to merge! Happy to help out with the Hypothesis parts going forward, but further work really needs more Astropy expertise than I have at the moment. |
It's already installed via pytest-astropy, so this is pretty simple.
ca37a06 to
215fc11
Compare
|
OK, I tried to directly fix the failing test for numpy 1.16 instead. If that fails, one can go back to the |
And add a bit more clarification for the two places where this can happen.
|
And of course I did it wrong at least twice, but I think I now found that the failing test was just a case already found before, of a UTC JD close to 0, and had nothing to do with the numpy version (that is the risk of hypothesis, I guess, that the different travis runs do not necessarily try the same tests - good in many ways, but tricky here). |
|
Thanks @mhvk! This is definitely getting into territory where the limit is my knowledge of Time code, not Hypothesis 🙂 |
|
You're welcome! I've updated the list of suggested tests in #9017 - the next set should be faster now that we've sorted out all the dependency and config issues, and upgraded Hypothesis a bit 😁 |
Set up Hypothesis and add property-based tests for `Time` precision
Set up Hypothesis and add property-based tests for `Time` precision
|
@bsipocz - I think I did the milestone wrong here. This is really a new type of testing that I think might be better done in 4.2. Is it too late to change it? If you have already included it in 4.1 or 4.0.2, then probably not quite worth reverting either. |
|
Re: milestone -- cc @astrofrog and @eteq |
|
I think this is already in 4.1rc1, no harm in including it and certainly not much point removing it I think. It's also already backported to v4.0.x. |
This pull request follows issue #9017. The major contribution is by @aarchiba (not me!), who wrote the excellent tests for
Timeprecision in #9532 and found bugs #9533 and #9579.I have rebased on master and clarified a few Hypothesis idioms, added a section to the testing guide, and simplified the install and CI configuration (as
pytest-astropynow depends on Hypothesis 🎉).Reviewers please note that I am not an astrophysicist - I'm a Hypothesis core developer and want to support trustworthy and open scientific computing, but you'll have to bring the domain expertise 😁
EDIT: Close #9532