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

DM-23174: Consolidate daf_butler test code #229

Merged
merged 17 commits into from Feb 6, 2020
Merged

Conversation

kfindeisen
Copy link
Member

This PR moves the test utilities previously located in the tests/ directory to a new lsst.daf.butler.tests package (which is not included in lsst.daf.butler). It also adds some extra utilities designed for test code in other packages, such as functions for creating and configuring mock repositories (see lsst/pipe_base#114 for an example of where this would be useful).

Developer guide says to use spans for consecutive years.
@kfindeisen kfindeisen requested a review from timj February 4, 2020 21:51
Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this clean up. I have a few questions before I do a final sign off. In particular I'd like @TallJimbo to comment on a couple of the test routines.

COPYRIGHT Outdated Show resolved Hide resolved
python/lsst/daf/butler/tests/_examplePythonTypes.py Outdated Show resolved Hide resolved
python/lsst/daf/butler/tests/_examplePythonTypes.py Outdated Show resolved Hide resolved
python/lsst/daf/butler/tests/_testRepo.py Outdated Show resolved Hide resolved
python/lsst/daf/butler/tests/_testRepo.py Outdated Show resolved Hide resolved
@classmethod
def setUpClass(cls):
# Repository should be re-created for each test case, but
# this has a prohibitive run-time cost at present
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to work this out. tests/test_butler.py creates huge numbers of temp directories with their own butlers and this test class should not be any different. For example:

python tests/test_butler.py
.........................................................x......
----------------------------------------------------------------------
Ran 64 tests in 15.860s

and most of those 64 tests are calling makeRepo in their own temp directory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test on this branch is really fast for me:

$ time python tests/test_testRepo.py 
........
----------------------------------------------------------------------
Ran 8 tests in 0.386s

OK

real	0m1.711s
user	0m1.070s
sys	0m0.604s

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use https://pypi.org/project/pytest-profiling/ and compare timings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose splitting that into another ticket, possibly a high-priority one for February. While I am worried about what's going on, the pipeline test framework is something we need ASAP, and this ticket has already dragged on for two weeks for various reasons (e.g., the Butler API changing due to concurrent development). There is no guarantee that we can track down the cause of the slowdown (which, as far as we know, affects only my computer) in any particular amount of time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Create a new ticket. It is concerning that you see such a problem. I guess it's a good thing that you have demonstrated that you can run all tests with a shared butler and changing collections for each test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as DM-23357.

tests/test_testRepo.py Outdated Show resolved Hide resolved
# outfile has the most obvious effects of any Butler.makeRepo keyword
with tempfile.TemporaryDirectory() as temp:
path = os.path.join(temp, 'oddConfig.py')
makeTestRepo(self.root, {}, outfile=path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think why this works fine given that self.root won't include a butler.yaml file so the Butler created inside makeTestRepo should fail because it won't know about the config written to path. I think at least that the Butler returned will have a different config to the one in path.

tests/test_testRepo.py Outdated Show resolved Hide resolved
The code has been cleaned up, and tests added.
It's hard to explicitly provide correct keys without understanding how
the Butler dimensions system works in detail. Moving key constraints
to automated (if simple-minded) code greatly reduces the burden
on callers.
Each test should have its own collection for isolation, but creating a
completely new repository each time is impractical.
This change lets tests avoid using Numpy arrays, whose nonstandard
__eq__ behavior makes them poor test objects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants