-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Change method to load module from source files to make sure it never loads code from other packages. Fixes #1483 Signed-off-by: SitiSchu <admin@sitischu.com> Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com> Co-authored-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
- Loading branch information
1 parent
1fd1c58
commit c4cdc7e
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright Contributors to the Rez Project | ||
|
||
|
||
""" | ||
unit tests for 'utils.py23' module | ||
""" | ||
import os | ||
import sys | ||
import tempfile | ||
|
||
from rez.tests.util import TestBase | ||
from rez.utils import py23 | ||
|
||
|
||
class TestLoadModuleFromFile(TestBase): | ||
def test_load_module(self): | ||
"""Ensure that the imported module does not show up in sys.modules""" | ||
# Random chars are used in the module name to ensure that the module name is unique | ||
# and the test won't fail because some other module with the same name | ||
# shows up in sys.modules | ||
module = 'utils_test_7cd3a335' | ||
|
||
filename = '{0}.py'.format(module) | ||
tmpdir = tempfile.mkdtemp(prefix="rez_selftest_") | ||
|
||
with open(os.path.join(tmpdir, filename), 'w') as fd: | ||
fd.write('') | ||
|
||
py23.load_module_from_file( | ||
module, | ||
os.path.join(tmpdir, filename) | ||
) | ||
self.assertEqual(sys.modules.get(module), None, msg='Module was found in sys.modules') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters