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

make test_find_eb_script more robust in case $EB_SCRIPT_PATH is already set #3320

Merged
merged 2 commits into from
May 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2027,19 +2027,35 @@ def makedirs_in_test(*paths):

def test_find_eb_script(self):
"""Test find_eb_script function."""

# make sure $EB_SCRIPT_PATH is not set already (used as fallback mechanism in find_eb_script)
if 'EB_SCRIPT_PATH' in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to reset this to the original value at the end of this test?

Copy link
Member Author

Choose a reason for hiding this comment

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

The environment is already automatically reset to the original at the end of each test (see tearDown in test/framework/utilities.py).

del os.environ['EB_SCRIPT_PATH']

self.assertTrue(os.path.exists(ft.find_eb_script('rpath_args.py')))
self.assertTrue(os.path.exists(ft.find_eb_script('rpath_wrapper_template.sh.in')))
self.assertErrorRegex(EasyBuildError, "Script 'no_such_script' not found", ft.find_eb_script, 'no_such_script')

# put test script in place relative to location of 'eb'
ft.write_file(os.path.join(self.test_prefix, 'bin', 'eb'), '#!/bin/bash\necho "fake eb"')
ft.adjust_permissions(os.path.join(self.test_prefix, 'bin', 'eb'), stat.S_IXUSR)
os.environ['PATH'] = '%s:%s' % (os.path.join(self.test_prefix, 'bin'), os.getenv('PATH', ''))
fake_eb = os.path.join(self.test_prefix, 'bin', 'eb')
ft.write_file(fake_eb, '#!/bin/bash\necho "fake eb"')
ft.adjust_permissions(fake_eb, stat.S_IXUSR)
os.environ['PATH'] = '%s:%s' % (os.path.dirname(fake_eb), os.getenv('PATH', ''))

justatest = os.path.join(self.test_prefix, 'easybuild', 'scripts', 'justatest.sh')
justatest = os.path.join(self.test_prefix, 'easybuild', 'scripts', 'thisisjustatestscript.sh')
ft.write_file(justatest, '#!/bin/bash')

self.assertTrue(os.path.samefile(ft.find_eb_script('justatest.sh'), justatest))
self.assertTrue(os.path.samefile(ft.find_eb_script('thisisjustatestscript.sh'), justatest))

# $EB_SCRIPT_PATH can also be used (overrules 'eb' found via $PATH)
ft.remove_file(fake_eb)
os.environ['EB_SCRIPT_PATH'] = os.path.join(self.test_prefix, 'easybuild', 'scripts')
self.assertTrue(os.path.samefile(ft.find_eb_script('thisisjustatestscript.sh'), justatest))

# if script can't be found via either $EB_SCRIPT_PATH or location of 'eb', we get a clean error
del os.environ['EB_SCRIPT_PATH']
error_pattern = "Script 'thisisjustatestscript.sh' not found at expected location"
self.assertErrorRegex(EasyBuildError, error_pattern, ft.find_eb_script, 'thisisjustatestscript.sh')

def test_move_file(self):
"""Test move_file function"""
Expand Down