|
50 | 50 | from easybuild.tools import LooseVersion, config |
51 | 51 | from easybuild.tools.build_log import EasyBuildError |
52 | 52 | from easybuild.tools.config import get_module_syntax, update_build_option |
| 53 | +from easybuild.tools.environment import modify_env |
53 | 54 | from easybuild.tools.filetools import change_dir, copy_dir, copy_file, mkdir, read_file, remove_dir, remove_file |
54 | 55 | from easybuild.tools.filetools import verify_checksum, write_file |
55 | 56 | from easybuild.tools.module_generator import module_generator |
@@ -1020,6 +1021,60 @@ def test_handle_iterate_opts(self): |
1020 | 1021 | self.assertEqual(eb.cfg.iterating, False) |
1021 | 1022 | self.assertEqual(eb.cfg['configopts'], ["--opt1 --anotheropt", "--opt2", "--opt3 --optbis"]) |
1022 | 1023 |
|
| 1024 | + def test_post_processing_step(self): |
| 1025 | + """Test post_processing_step and deprecated post_install_step.""" |
| 1026 | + init_config(build_options={'silent': True}) |
| 1027 | + |
| 1028 | + test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs', 'test_ecs') |
| 1029 | + toy_ec_fn = os.path.join(test_ecs_dir, 't', 'toy', 'toy-0.0.eb') |
| 1030 | + |
| 1031 | + # these imports only work here, since EB_toy is a test easyblock |
| 1032 | + from easybuild.easyblocks.toy import EB_toy |
| 1033 | + from easybuild.easyblocks.toy_deprecated import EB_toy_deprecated |
| 1034 | + |
| 1035 | + cwd = os.getcwd() |
| 1036 | + toy_ec = EasyConfig(toy_ec_fn) |
| 1037 | + eb = EB_toy_deprecated(toy_ec) |
| 1038 | + eb.silent = True |
| 1039 | + depr_msg = r"EasyBlock.post_install_step\(\) is deprecated, use EasyBlock.post_processing_step\(\) instead" |
| 1040 | + expected_error = r"DEPRECATED \(since v6.0\).*" + depr_msg |
| 1041 | + with self.mocked_stdout_stderr(): |
| 1042 | + self.assertErrorRegex(EasyBuildError, expected_error, eb.run_all_steps, True) |
| 1043 | + |
| 1044 | + change_dir(cwd) |
| 1045 | + toy_ec = EasyConfig(toy_ec_fn) |
| 1046 | + eb = EB_toy(toy_ec) |
| 1047 | + eb.silent = True |
| 1048 | + with self.mocked_stdout_stderr() as (_, stderr): |
| 1049 | + eb.run_all_steps(True) |
| 1050 | + # no deprecation warning |
| 1051 | + stderr = stderr.getvalue() |
| 1052 | + self.assertFalse(stderr) |
| 1053 | + |
| 1054 | + libtoy_post_a = os.path.join(eb.installdir, 'lib', 'libtoy_post.a') |
| 1055 | + self.assertExists(libtoy_post_a) |
| 1056 | + |
| 1057 | + # check again with toy easyblock that still uses post_install_step, |
| 1058 | + # to verify that the expected file is being created when deprecated functionality is allow |
| 1059 | + remove_file(libtoy_post_a) |
| 1060 | + modify_env(os.environ, self.orig_environ, verbose=False) |
| 1061 | + change_dir(cwd) |
| 1062 | + |
| 1063 | + self.allow_deprecated_behaviour() |
| 1064 | + toy_ec = EasyConfig(toy_ec_fn) |
| 1065 | + eb = EB_toy_deprecated(toy_ec) |
| 1066 | + eb.silent = True |
| 1067 | + with self.mocked_stdout_stderr() as (stdout, stderr): |
| 1068 | + eb.run_all_steps(True) |
| 1069 | + |
| 1070 | + regex = re.compile(depr_msg, re.M) |
| 1071 | + stdout = stdout.getvalue() |
| 1072 | + self.assertTrue("This step is deprecated.\n" in stdout) |
| 1073 | + stderr = stderr.getvalue() |
| 1074 | + self.assertTrue(regex.search(stderr), f"Pattern {regex.pattern} found in: {stderr}") |
| 1075 | + |
| 1076 | + self.assertExists(libtoy_post_a) |
| 1077 | + |
1023 | 1078 | def test_extensions_step(self): |
1024 | 1079 | """Test the extensions_step""" |
1025 | 1080 | init_config(build_options={'silent': True}) |
|
0 commit comments