|
35 | 35 | import os |
36 | 36 | import re |
37 | 37 | import signal |
| 38 | +import string |
38 | 39 | import stat |
39 | 40 | import subprocess |
40 | 41 | import sys |
|
52 | 53 | from easybuild.tools.config import update_build_option |
53 | 54 | from easybuild.tools.filetools import adjust_permissions, change_dir, mkdir, read_file, write_file |
54 | 55 | from easybuild.tools.run import RunShellCmdResult, RunShellCmdError, check_async_cmd, check_log_for_errors |
55 | | -from easybuild.tools.run import complete_cmd, get_output_from_process, parse_log_for_error |
| 56 | +from easybuild.tools.run import complete_cmd, fileprefix_from_cmd, get_output_from_process, parse_log_for_error |
56 | 57 | from easybuild.tools.run import run_cmd, run_cmd_qa, run_shell_cmd, subprocess_terminate |
57 | 58 | from easybuild.tools.config import ERROR, IGNORE, WARN |
58 | 59 |
|
@@ -194,6 +195,26 @@ def test_run_shell_cmd_basic(self): |
194 | 195 | self.assertTrue(isinstance(res.output, str)) |
195 | 196 | self.assertTrue(res.work_dir and isinstance(res.work_dir, str)) |
196 | 197 |
|
| 198 | + def test_fileprefix_from_cmd(self): |
| 199 | + """test simplifications from fileprefix_from_cmd.""" |
| 200 | + cmds = { |
| 201 | + 'abd123': 'abd123', |
| 202 | + 'ab"a': 'aba', |
| 203 | + 'a{:$:S@"a': 'aSa', |
| 204 | + 'cmd-with-dash': 'cmd-with-dash', |
| 205 | + 'cmd_with_underscore': 'cmd_with_underscore', |
| 206 | + } |
| 207 | + for cmd, expected_simplification in cmds.items(): |
| 208 | + self.assertEqual(fileprefix_from_cmd(cmd), expected_simplification) |
| 209 | + |
| 210 | + cmds = { |
| 211 | + 'abd123': 'abd', |
| 212 | + 'ab"a': 'aba', |
| 213 | + '0a{:$:2@"a': 'aa', |
| 214 | + } |
| 215 | + for cmd, expected_simplification in cmds.items(): |
| 216 | + self.assertEqual(fileprefix_from_cmd(cmd, allowed_chars=string.ascii_letters), expected_simplification) |
| 217 | + |
197 | 218 | def test_run_cmd_log(self): |
198 | 219 | """Test logging of executed commands.""" |
199 | 220 | fd, logfile = tempfile.mkstemp(suffix='.log', prefix='eb-test-') |
|
0 commit comments