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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/lsst/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

from .raDecStr import *
from .demangle import *
from .utils import *
Expand Down
7 changes: 6 additions & 1 deletion tests/testGetPackageDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def testBasics(self):
utilsPath = getPackageDir("utils")
self.assertTrue(os.path.isfile(os.path.join(utilsPath, "tests", "testGetPackageDir.py")))

self.assertRaises(Exception, getPackageDir, "nameOfNonexistendPackage2234q?#!")
# NOTE: one goal of this test is to confirm that the correct exception
# is raised even if we haven't explicitly imported pex.exceptions.
# Hence the odd structure of this assert block.
with self.assertRaises(Exception) as cm:
getPackageDir("nameOfNonexistendPackage2234q?#!")
self.assertIsInstance(cm.exception, lsst.pex.exceptions.NotFoundError)

def testUnicodeBasics(self):
utilsPath = getPackageDir(u"utils")
Expand Down