Skip to content

Commit 150d911

Browse files
update include_easyblocks tests
1 parent 60f71a3 commit 150d911

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

test/framework/include.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,22 @@ def test_include_easyblocks(self):
102102
myfoo_pyc_path = easybuild.easyblocks.myfoo.__file__
103103
myfoo_real_py_path = os.path.realpath(os.path.join(os.path.dirname(myfoo_pyc_path), 'myfoo.py'))
104104
self.assertTrue(os.path.samefile(up(myfoo_real_py_path, 1), myeasyblocks))
105+
del sys.modules['easybuild.easyblocks.myfoo']
105106

106107
import easybuild.easyblocks.generic.mybar
107108
mybar_pyc_path = easybuild.easyblocks.generic.mybar.__file__
108109
mybar_real_py_path = os.path.realpath(os.path.join(os.path.dirname(mybar_pyc_path), 'mybar.py'))
109110
self.assertTrue(os.path.samefile(up(mybar_real_py_path, 2), myeasyblocks))
111+
del sys.modules['easybuild.easyblocks.generic.mybar']
110112

111113
# existing (test) easyblocks are unaffected
112114
import easybuild.easyblocks.foofoo
113115
foofoo_path = os.path.dirname(os.path.dirname(easybuild.easyblocks.foofoo.__file__))
114116
self.assertTrue(os.path.samefile(foofoo_path, test_easyblocks))
117+
del sys.modules['easybuild.easyblocks.foofoo']
115118

116119
def test_include_easyblocks_priority(self):
117-
"""Test whether easyblocks included via include_easyblocks() get prioroity over others."""
120+
"""Test whether easyblocks included via include_easyblocks() get priority over others."""
118121
test_easyblocks = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sandbox', 'easybuild', 'easyblocks')
119122

120123
# make sure that test 'foo' easyblock is there
@@ -138,15 +141,23 @@ def test_include_easyblocks_priority(self):
138141
" pass",
139142
])
140143
write_file(os.path.join(myeasyblocks, 'foo.py'), foo_easyblock_txt)
144+
145+
# check that the sandboxed easyblock is imported before include_easyblocks is run
146+
foo_pyc_path = easybuild.easyblocks.foo.__file__
147+
foo_real_py_path = os.path.realpath(os.path.join(os.path.dirname(foo_pyc_path), 'foo.py'))
148+
self.assertTrue(os.path.samefile(os.path.dirname(os.path.dirname(foo_pyc_path)), test_easyblocks))
149+
self.assertFalse(os.path.samefile(foo_real_py_path, os.path.join(myeasyblocks, 'foo.py')))
150+
141151
include_easyblocks(self.test_prefix, [os.path.join(myeasyblocks, 'foo.py')])
142152

153+
# check that the included easyblock is imported after include_easyblocks is run
143154
foo_pyc_path = easybuild.easyblocks.foo.__file__
144155
foo_real_py_path = os.path.realpath(os.path.join(os.path.dirname(foo_pyc_path), 'foo.py'))
145-
self.assertFalse(os.path.samefile(os.path.dirname(foo_pyc_path), test_easyblocks))
156+
self.assertFalse(os.path.samefile(os.path.dirname(os.path.dirname(foo_pyc_path)), test_easyblocks))
146157
self.assertTrue(os.path.samefile(foo_real_py_path, os.path.join(myeasyblocks, 'foo.py')))
147158

148-
# 'undo' import of foo easyblock
149-
del sys.modules['easybuild.easyblocks.foo']
159+
# check that the included easyblock is not loaded
160+
self.assertFalse('easybuild.easyblocks.foo' in sys.modules)
150161

151162
def test_include_mns(self):
152163
"""Test include_module_naming_schemes()."""

test/framework/options.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,19 +2917,36 @@ def test_xxx_include_easyblocks_from_pr(self):
29172917
])
29182918
write_file(os.path.join(self.test_prefix, 'cmakemake.py'), cmm_txt)
29192919

2920-
# including the same easyblock twice should fail
2920+
# including the same easyblock twice should work and give priority to the one from the PR
29212921
args = [
29222922
'--include-easyblocks=%s/*.py' % self.test_prefix,
29232923
'--include-easyblocks-from-pr=1915',
29242924
'--list-easyblocks=detailed',
29252925
'--unittest-file=%s' % self.logfile,
29262926
'--github-user=%s' % GITHUB_TEST_ACCOUNT,
29272927
]
2928-
self.assertErrorRegex(EasyBuildError,
2929-
"Multiple inclusion of cmakemake.py, check your --include-easyblocks options",
2930-
self.eb_main, args, raise_error=True)
2928+
self.eb_main(args, logfile=dummylogfn, raise_error=True)
2929+
logtxt = read_file(self.logfile)
2930+
2931+
# easyblock included from pr is found
2932+
path_pattern = os.path.join(self.test_prefix, '.*', 'included-easyblocks-.*', 'easybuild', 'easyblocks')
2933+
cmm_pattern = os.path.join(path_pattern, 'generic', 'cmakemake.py')
2934+
cmm_regex = re.compile(r"\|-- CMakeMake \(easybuild.easyblocks.generic.cmakemake @ %s\)" % cmm_pattern, re.M)
2935+
self.assertTrue(cmm_regex.search(logtxt), "Pattern '%s' found in: %s" % (cmm_regex.pattern, logtxt))
2936+
2937+
# easyblock is found via get_easyblock_class
2938+
klass = get_easyblock_class('CMakeMake')
2939+
self.assertTrue(issubclass(klass, EasyBlock), "%s is an EasyBlock derivative class" % klass)
29312940

2941+
# 'undo' import of easyblocks
2942+
del sys.modules['easybuild.easyblocks.foo']
2943+
del sys.modules['easybuild.easyblocks.generic.cmakemake']
29322944
os.remove(os.path.join(self.test_prefix, 'cmakemake.py'))
2945+
sys.path = orig_local_sys_path
2946+
import easybuild.easyblocks
2947+
reload(easybuild.easyblocks)
2948+
import easybuild.easyblocks.generic
2949+
reload(easybuild.easyblocks.generic)
29332950

29342951
# clear log
29352952
write_file(self.logfile, '')

0 commit comments

Comments
 (0)