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

Improvements to import_file() and run_file() #70

Merged
merged 7 commits into from
Dec 13, 2019
Merged

Conversation

jsiirola
Copy link
Contributor

@jsiirola jsiirola commented Dec 13, 2019

Fixes: N/A

Summary/Motivation:

This improves the robustness of import_file() and run_file() so that the sys.path is not left in an altered state in the event that the import raises an exception. This also switches to using tools from sys.path for performing path manipulations (instead of hard-coded / and \ characters).

Changes proposed in this PR:

  • Ensure restoration of sys.path when imports raise exceptions
  • Remove use of hard-coded / and \ path separator characters.

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@jsiirola jsiirola changed the title Import fixes Improvements to import_file() and run_file() Dec 13, 2019
@whart222
Copy link
Contributor

@jsiirola Given the nature of these changes, I think it's important to add a few tests to confirm that these changes capture the behavior that motivated the PR.

@jsiirola
Copy link
Contributor Author

@whart222: absolutely. Tests added.

@coveralls
Copy link

coveralls commented Dec 13, 2019

Coverage Status

Coverage increased (+0.04%) to 62.046% when pulling d04eace on import-fixes into 12fddaf on master.

@blnicho blnicho merged commit 5e8ec7d into master Dec 13, 2019
@blnicho blnicho deleted the import-fixes branch December 13, 2019 16:28
@ghackebeil
Copy link
Member

ghackebeil commented Dec 13, 2019 via email

@whart222
Copy link
Contributor

@ghackebeil I'm not sure what you're referring to. Where do you think there's an error?

def test_import_exception(self):
orig_path = list(sys.path)
with self.assertRaisesRegexp(RuntimeError, "raised during import"):
pyutilib.misc.run_file(
Copy link
Member

Choose a reason for hiding this comment

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

Should this be calling pyutilib.misc.import_file instead of pytuilib.misc.run_file? The test is on the TestImportFile class.

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