def test_env(self): self.init_eclrun_config() with open("eclrun", "w") as f, open("DUMMY.DATA", "w"): f.write("""#!/usr/bin/env python import os import json with open("env.json", "w") as f: json.dump(dict(os.environ), f) """) os.chmod("eclrun", os.stat("eclrun").st_mode | stat.S_IEXEC) ecl_config = Ecl100Config() eclrun_config = EclrunConfig(ecl_config, "2019.3") ecl_run = EclRun("DUMMY", None, check_status=False) with mock.patch.object(ecl_run, "_get_run_command", mock.MagicMock(return_value="./eclrun")): ecl_run.runEclipse(eclrun_config=eclrun_config) with open("env.json") as f: run_env = json.load(f) eclrun_env = self._eclrun_conf()["eclrun_env"] for k, v in eclrun_env.items(): if v is None: assert k not in run_env continue if k == "PATH": assert run_env[k].startswith(v) else: assert v == run_env[k]
def test_failed_run(self): self.init_eclrun_config() shutil.copy( os.path.join(self.SOURCE_ROOT, "test-data/local/eclipse/SPE1_ERROR.DATA"), "SPE1_ERROR.DATA", ) ecl_config = Ecl100Config() eclrun_config = EclrunConfig(ecl_config, "2019.3") ecl_run = EclRun("SPE1_ERROR", None) with self.assertRaises(Exception) as error_context: ecl_run.runEclipse(eclrun_config=eclrun_config) self.assertIn("ERROR", str(error_context.exception))
def test_summary_block(self): self.init_eclrun_config() shutil.copy( os.path.join(self.SOURCE_ROOT, "test-data/local/eclipse/SPE1.DATA"), "SPE1.DATA", ) ecl_config = Ecl100Config() ecl_run = EclRun("SPE1.DATA", None) ret_value = ecl_run.summary_block() self.assertTrue(ret_value is None) ecl_run.runEclipse(eclrun_config=EclrunConfig(ecl_config, "2019.3")) ecl_sum = ecl_run.summary_block() self.assertTrue(isinstance(ecl_sum, EclSum))
def test_run(self): self.init_eclrun_config() shutil.copy( os.path.join(self.SOURCE_ROOT, "test-data/local/eclipse/SPE1.DATA"), "SPE1.DATA", ) ecl_config = Ecl100Config() ecl_run = EclRun("SPE1.DATA", None) ecl_run.runEclipse(eclrun_config=EclrunConfig(ecl_config, "2019.3")) ok_path = os.path.join(ecl_run.runPath(), "{}.OK".format(ecl_run.baseName())) log_path = os.path.join(ecl_run.runPath(), "{}.LOG".format(ecl_run.baseName())) self.assertTrue(os.path.isfile(ok_path)) self.assertTrue(os.path.isfile(log_path)) self.assertTrue(os.path.getsize(log_path) > 0) errors = ecl_run.parseErrors() self.assertEqual(0, len(errors))