def test_parse_wuid_from_xml_cannot_find_wuid(self): string = self.xml.format("W1234567") res = parse_wuid_from_xml(string) self.assertIsNone(res)
def test_parse_wuid_from_xml_returns_with_extra_dash_wuid(self): expected = 'W12345678-123456-5' string = self.xml.format(expected) res = parse_wuid_from_xml(string) self.assertEqual(expected, res)
def test_parse_wuid_from_xml_returns_intended(self): expected = 'W20180702-085912' string = self.xml.format(expected) res = parse_wuid_from_xml(string) self.assertEqual(expected, res)
def test_parse_wuid_from_xml_with_bracketed_wuid(self): expected = 'W12345678-123456(2)' string = self.xml.format(expected) res = parse_wuid_from_xml(string) self.assertEqual(expected, res)
def run_ecl_script(self, script, syntax_check, delete_workunit, stored): """ Run an ECL script and return the stdout and stderr. Run the ECL script `script` on the HPCC instance at `server`:`port`, using the credentials `username` and `password`. If `syntax_check`, run a syntax check before execution. Attributes `legacy` and `repo` are also used. Parameters ---------- script: str path to ECL script. syntax_check: bool If a syntax check should be ran before the script is executed. delete_workunit: bool Delete workunit once completed. stored : dict or None Key value pairs to replace stored variables within the script. Values should be str, int or bool. Returns ------- result: namedtuple NamedTuple in the form (stdout, stderr). Raises ------ subprocess.CalledProcessError: If script fails syntax check. See Also -------- syntax_check run_ecl_string """ base_cmd = [ 'ecl', 'run', '-v', '--server={}'.format(self.server), '--port={}'.format(self.port), '--username={}'.format(self.username), '--password={}'.format(self.password) ] base_cmd += self._legacy_arg base_cmd += ['thor', script] base_cmd += self._repo_arg stored = stored or {} for key, value in stored.items(): string = '-X{}={}'.format(key, value) base_cmd.append(string) if syntax_check: self.check_syntax(script) try: result = self._run_command(base_cmd) except subprocess.SubprocessError as e: msg = "Failed to run ecl command" raise subprocess.SubprocessError(msg) from e if delete_workunit: wuid = parse_wuid_from_xml(result.stdout) delete.delete_workunit(self, wuid) return result