def test_load_hooks(self): """Test for load_hooks function.""" self.assertErrorRegex(EasyBuildError, "Specified path .* does not exist.*", load_hooks, '/no/such/hooks.py') hooks = load_hooks(self.test_hooks_pymod) self.assertEqual(len(hooks), 4) self.assertEqual(sorted(hooks.keys()), ['parse_hook', 'post_configure_hook', 'pre_install_hook', 'start_hook']) self.assertTrue(all(callable(h) for h in hooks.values())) # test caching of hooks remove_file(self.test_hooks_pymod) cached_hooks = load_hooks(self.test_hooks_pymod) self.assertTrue(cached_hooks is hooks) # hooks file can be empty empty_hooks_path = os.path.join(self.test_prefix, 'empty_hooks.py') write_file(empty_hooks_path, '') empty_hooks = load_hooks(empty_hooks_path) self.assertEqual(empty_hooks, {}) # loading another hooks file doesn't affect cached hooks prev_hooks = load_hooks(self.test_hooks_pymod) self.assertTrue(prev_hooks is hooks) # clearing cached hooks results in error because hooks file is not found easybuild.tools.hooks._cached_hooks = {} self.assertErrorRegex(EasyBuildError, "Specified path .* does not exist.*", load_hooks, self.test_hooks_pymod)