def test_run_export_pathfile(monkeypatch): with ErtPluginContext(): run_path_file = Path("output/run_path_file/.some_new_name") config_file = "snake_oil.ert" with open(config_file, encoding="utf-8", mode="a") as fout: fout.write(f"RUNPATH_FILE {run_path_file}\n") rc = ResConfig(user_config_file=config_file) ert = EnKFMain(rc) notifier = ErtCliNotifier(ert, config_file) with ERT.adapt(notifier): run_mock = MagicMock() run_mock.hasFailed.return_value = False export_mock = MagicMock() export_mock.hasFailed.return_value = False monkeypatch.setattr( ERT.enkf_facade, "get_workflow_job", MagicMock(side_effect=[export_mock, run_mock]), ) ex = Exporter() parameters = { "output_file": "export.csv", "time_index": "raw", "column_keys": "FOPR", } ex.run_export(parameters) expected_call = call( arguments=[ f"{run_path_file.absolute()}", "export.csv", "raw", "FOPR" ], ert=ERT.ert, verbose=True, ) assert export_mock.run.call_args == expected_call
def main(): with open(LOGGING_CONFIG, encoding="utf-8") as conf_file: logging.config.dictConfig(yaml.safe_load(conf_file)) set_abort_handler(_log_util_abort) import locale locale.setlocale(locale.LC_NUMERIC, "C") args = ert_parser(None, sys.argv[1:]) logger = logging.getLogger(__name__) if args.verbose: logger.setLevel("DEBUG") FeatureToggling.update_from_args(args) try: with start_ert_server(args.mode), ErtPluginContext() as context: context.plugin_manager.add_logging_handle_to_root( logging.getLogger()) logger.info("Running ert with {}".format(str(args))) args.func(args) except ErtCliError as err: logger.exception(str(err)) sys.exit(str(err)) except BaseException as err: logger.exception(f'ERT crashed unexpectedly with "{err}"') logfiles = set() # Use set to avoid duplicates... for handler in logging.getLogger().handlers: if isinstance(handler, logging.FileHandler): logfiles.add(handler.baseFilename) msg = f'ERT crashed unexpectedly with "{err}".\nSee logfile(s) for details:' msg += "\n " + "\n ".join(logfiles) sys.exit(msg)
def test_exporter_is_valid(): with ErtPluginContext(): config_file = "snake_oil.ert" rc = ResConfig(user_config_file=config_file) rc.convertToCReference(None) ert = EnKFMain(rc) ex = Exporter(ert) assert ex.is_valid(), "Missing CSV_EXPORT2 or EXPORT_RUNPATH jobs"
def main(): args = ert_parser(None, sys.argv[1:]) if args.verbose: logger = logging.getLogger() logger.setLevel("DEBUG") with ErtPluginContext(): args.func(args) clear_global_state()
def main(): import ert_logging # Only use ert logger config when running ERT args = ert_parser(None, sys.argv[1:]) if args.verbose: logger = logging.getLogger() logger.setLevel("DEBUG") FeatureToggling.update_from_args(args) with ErtPluginContext(): args.func(args) clear_global_state()
def test_console_script_integration(setup_tmpdir, forward_model, configuration, expected_error): config = default_config.format(forward_model, configuration) with open("config.ert", "w") as fh: fh.write(config) with ErtPluginContext(plugins=[ semeio.hook_implementations.jobs, ert_shared.hook_implementations ]): subprocess.run(["ert", "test_run", "config.ert", "--verbose"], check=False) with open(f"simulations/realization0/{forward_model}.stderr.0") as fin: error = fin.read() assert expected_error in error
def main(): import ert_logging # Only use ert logger config when running ERT import locale locale.setlocale(locale.LC_NUMERIC, "C") args = ert_parser(None, sys.argv[1:]) if args.verbose: logger = logging.getLogger() logger.setLevel("DEBUG") FeatureToggling.update_from_args(args) initialize_databases() with start_ert_server(), ErtPluginContext(): args.func(args) clear_global_state()
def test_nosim(setup_tmpdir, nosim_command, data_input, data_expected): shutil.copy(os.path.join(os.path.dirname(__file__), "data", "nosim.ert"), ".") with open("nosim.ert", "a") as fh: fh.writelines(["FORWARD_MODEL {}".format(nosim_command)]) with open("TEST.DATA", "w") as fh: fh.write(data_input) with ErtPluginContext( plugins=[semeio.hook_implementations.jobs, ert_shared.hook_implementations] ): subprocess.check_call( ["ert", "test_run", "nosim.ert", "--verbose"], ) with open("nosim/real_0/iter_0/TEST.DATA") as fh: assert fh.read() == data_expected
def test_run_export(): with ErtPluginContext(): config_file = "snake_oil.ert" rc = ResConfig(user_config_file=config_file) rc.convertToCReference(None) ert = EnKFMain(rc) ex = Exporter(ert) parameters = { "output_file": "export.csv", "time_index": "raw", "column_keys": "FOPR", } ex.run_export(parameters) shutil.rmtree("storage") with pytest.raises(UserWarning) as warn: ex.run_export(parameters) assert ex._export_job in str(warn)