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-10401 Make utils.getPackageDir raise correct exception #32

Merged
merged 1 commit into from May 4, 2017

Conversation

parejkoj
Copy link
Contributor

@parejkoj parejkoj commented May 1, 2017

No description provided.

@@ -22,6 +22,8 @@
#
from __future__ import absolute_import

import lsst.pex.exceptions

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the correct place for this import to affect all the parts of the code base? I am not sure, I just want you to verify, and I trust if you say it is so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the correct place to make it affect all parts of utils anyway. I'm not sure there's a place we can put it that will affect "everything".

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work to put it in a python/lsst/__init__.py in pex_exceptions? Otherwise somewhere low in the hierarchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's enough, since one would still have to import lsst.pex.exceptions to see it. See DM-10415 for the broader problem:

https://jira.lsstcorp.org/browse/DM-10415

# Hence the odd structure of this assert block.
with self.assertRaises(Exception) as cm:
getPackageDir("nameOfNonexistendPackage2234q?#!")
import lsst.pex.exceptions
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this import here in the middle of a test function? Are you trying to trigger one kind of behavior above and below this import? As I see it the only thing you are doing below is checking existing variables.

Copy link
Contributor

@natelust natelust May 2, 2017

Choose a reason for hiding this comment

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

I jumped right here without reading all the comments on the ticket, so I am sorry. I see this was talked about on the ticket, but I must confess I still do not understand why it is necessary to be placed here. If I remove the import completely the test still seems to pass. You seem to be explicitly importing exceptions in the __init__ file now, which to me seems to ensure it will be imported...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woah... I don't understand how the test can pass if lsst.pex.exceptions is not imported (but I just tested it, and it does pass). I put the import here because I thought it was necessary to put lsst.pex.exceptions in the unittest's namespace. The fact that it isn't confuses me.

Copy link
Member

Choose a reason for hiding this comment

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

It's the magic we put in the lsst/__init__.py files: that makes it so all symbols in lsst/* are pulled into that package namespace whenever they're imported, even if that import happens in C++ with a py::module::import("lsst.pex.exceptions").

Copy link
Member

@kfindeisen kfindeisen May 2, 2017

Choose a reason for hiding this comment

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

@natelust, I think the point is to test whether the import in __init__ (or something with an equivalent effect) happens. So the code can't assume it.

@parejkoj if you remove the test import, does the test still work in the failure mode it's testing (i.e., no special handling of pex.exceptions in __init__ or the pybind11 files)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kfindeisen Interesting question: removing the import from __init__.py and the unittest results in a different failure,

AttributeError: module 'lsst' has no attribute 'pex'

instead of the expected:

AssertionError: RuntimeError('Package nameOfNonexistendPackage2234q?#! not found',) is not an instance of <class 'lsst.pex.exceptions.wrappers.NotFoundError'>

So, it's a failure, but not exactly the failure I'd hope for. Although I think the different error makes sense given what @TallJimbo says above about our lsst/__init__.py magic.

@parejkoj parejkoj force-pushed the tickets/DM-10401 branch 2 times, most recently from 729f023 to 9f54f34 Compare May 4, 2017 19:32
assertRaises with isInstance test of correct exception, and note about why
it looks strange.
@parejkoj parejkoj merged commit 317e7a3 into master May 4, 2017
@ktlim ktlim deleted the tickets/DM-10401 branch August 25, 2018 05:57
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

5 participants