def test_init(self): self.set_up_simple() with TestAreaContext("res_config_init_test") as work_area: cwd = os.getcwd() work_area.copy_directory(self.case_directory) config_file = "simple_config/minimum_config" res_config = ResConfig(user_config_file=config_file) self.assertEqual(res_config.model_config.data_root(), os.path.join(cwd, "simple_config")) self.assertEqual(clib_getenv("DATA_ROOT"), os.path.join(cwd, "simple_config")) # This fails with an not-understandable Python error: #----------------------------------------------------------------- # res_config.model_config.set_data_root( "NEW" ) # self.assertEqual( res_config.model_config.data_root( ) , "NEW") # self.assertEqual( clib_getenv("DATA_ROOT") , "NEW") self.assertIsNotNone(res_config) self.assert_same_config_file(config_file, res_config.user_config_file, os.getcwd()) self.assertIsNotNone(res_config.site_config) self.assertTrue(isinstance(res_config.site_config, SiteConfig)) self.assertIsNotNone(res_config.analysis_config) self.assertTrue( isinstance(res_config.analysis_config, AnalysisConfig)) self.assertEqual(res_config.config_path, os.path.join(cwd, "simple_config")) config_file = os.path.join(cwd, "simple_config/minimum_config") res_config = ResConfig(user_config_file=config_file) self.assertEqual(res_config.config_path, os.path.join(cwd, "simple_config")) os.chdir("simple_config") config_file = "minimum_config" res_config = ResConfig(user_config_file=config_file) self.assertEqual(res_config.config_path, os.path.join(cwd, "simple_config")) subst_config = res_config.subst_config for t in subst_config: print t self.assertEqual(subst_config["<CONFIG_PATH>"], os.path.join(cwd, "simple_config"))
def test_large_config(self): case_directory = self.createTestPath("local/snake_oil_structure") config_file = "snake_oil_structure/ert/model/user_config.ert" with TestAreaContext("res_config_prog_test") as work_area: work_area.copy_directory(case_directory) loaded_res_config = ResConfig(user_config_file=config_file) prog_res_config = ResConfig(config=self.large_config) self.assert_equal_model_config( loaded_res_config.model_config, prog_res_config.model_config ) self.assert_equal_site_config( loaded_res_config.site_config, prog_res_config.site_config ) self.assert_equal_ecl_config( loaded_res_config.ecl_config, prog_res_config.ecl_config ) self.assert_equal_analysis_config( loaded_res_config.analysis_config, prog_res_config.analysis_config ) self.assert_equal_hook_manager( loaded_res_config.hook_manager, prog_res_config.hook_manager ) self.assert_equal_log_config( loaded_res_config.log_config, prog_res_config.log_config ) self.assert_equal_ensemble_config( loaded_res_config.ensemble_config, prog_res_config.ensemble_config ) self.assert_equal_ert_templates( loaded_res_config.ert_templates, prog_res_config.ert_templates ) self.assert_equal_ert_workflow( loaded_res_config.ert_workflow_list, prog_res_config.ert_workflow_list ) self.assertEqual( loaded_res_config.queue_config, prog_res_config.queue_config ) self.assertEqual(0, len(prog_res_config.failed_keys))
def test_errors(self): case_directory = self.createTestPath("local/simple_config") config_file = "simple_config/minimum_config" with TestAreaContext("res_config_prog_test") as work_area: work_area.copy_directory(case_directory) with self.assertRaises(ValueError): res_config = ResConfig(config=self.minimum_config_error) res_config = ResConfig(config=self.minimum_config_error, throw_on_error=False) self.assertTrue(len(res_config.errors) > 0) self.assertEqual(0, len(res_config.failed_keys))
def test_misfit_preprocessor_passing_scaling_parameters(monkeypatch): run_mock = Mock() scal_job = Mock(return_value=Mock(run=run_mock)) monkeypatch.setattr( misfit_preprocessor, "CorrelatedObservationsScalingJob", scal_job, ) test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) config = {"scaling": {"threshold": 0.5, "std_cutoff": 2, "alpha": 3}} config_file = "my_config_file.yaml" with open(config_file, "w") as f: yaml.dump(config, f) misfit_preprocessor.MisfitPreprocessorJob(ert).run(config_file) for scaling_config in run_mock.call_args[0][0]: assert 0.5 == scaling_config["CALCULATE_KEYS"]["threshold"] assert 2 == scaling_config["CALCULATE_KEYS"]["std_cutoff"] assert 3 == scaling_config["CALCULATE_KEYS"]["alpha"]
def _init_enkf_main(self, enkf_main): if enkf_main is None: raise ValueError("Expected enkf_main to be " "provided upon initialization of ErtRPCServer. " "Received enkf_main=%r" % enkf_main) if isinstance(enkf_main, EnKFMain): self._enkf_main = enkf_main self._res_config = enkf_main.resConfig self._config_file = enkf_main.getUserConfigFile() elif isinstance(enkf_main, basestring): if not os.path.exists(enkf_main): raise IOError("No such configuration file: %s" % enkf_main) warnings.warn( "Providing a configuration file as the argument " "to ErtRPCServer is deprecated. Please use the " "optional argument res_config to provide an " "configuration!", DeprecationWarning) self._config_file = enkf_main self._res_config = ResConfig(self._config_file) self._enkf_main = EnKFMain(self._res_config) else: raise TypeError("Expected enkf_main to be an instance of " "EnKFMain, received: %r" % enkf_main)
def test_repr(self): with TestAreaContext("enkf_test", store_area=True) as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) pfx = 'EnKFMain(ensemble_size' self.assertEqual(pfx, repr(main)[:len(pfx)])
def test_misfit_preprocessor_passing_scaling_parameters( monkeypatch, test_data_root): run_mock = Mock() scal_job = Mock(return_value=Mock(run=run_mock)) monkeypatch.setattr( misfit_preprocessor, "CorrelatedObservationsScalingJob", scal_job, ) test_data_dir = os.path.join(test_data_root, "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) config = { "workflow": { "type": "custom_scale", "pca": { "threshold": 0.5 }, }, } config_file = "my_config_file.yaml" with open(config_file, "w") as f: yaml.dump(config, f) misfit_preprocessor.MisfitPreprocessorJob(ert).run(config_file) for scaling_config in list(run_mock.call_args)[0][0]: assert 0.5 == scaling_config["CALCULATE_KEYS"]["threshold"]
def test_shell_script_jobs_names(self): config_file = self.createTestPath("local/simple_config/minimum_config") shell_job_names = [ "DELETE_FILE", "DELETE_DIRECTORY", "COPY_DIRECTORY", "MAKE_SYMLINK", "MOVE_FILE", "MAKE_DIRECTORY", "CAREFUL_COPY_FILE", "SYMLINK", "COPY_FILE", ] res_config = ResConfig(config_file) found_jobs = set() list_from_content = res_config.ert_workflow_list for wf_name in list_from_content.getJobNames(): exe = list_from_content.getJob(wf_name).executable() if exe and "shell_scripts" in exe: assert wf_name in shell_job_names found_jobs.add(wf_name) assert len(shell_job_names) == len(found_jobs)
def test_site_config_hook_workflow(self): site_config_filename = "test_site_config" test_config_filename = "test_config" site_config_content = """ LOAD_WORKFLOW_JOB ECHO_WORKFLOW_JOB LOAD_WORKFLOW ECHO_WORKFLOW HOOK_WORKFLOW ECHO_WORKFLOW PRE_SIMULATION """ with open(site_config_filename, "w") as fh: fh.write(site_config_content) with open(test_config_filename, "w") as fh: fh.write("NUM_REALIZATIONS 1\n") with open("ECHO_WORKFLOW_JOB", "w") as fh: fh.write( """INTERNAL False EXECUTABLE echo MIN_ARG 1 """ ) with open("ECHO_WORKFLOW", "w") as fh: fh.write("ECHO_WORKFLOW_JOB hello") self.monkeypatch.setenv("ERT_SITE_CONFIG", site_config_filename) res_config = ResConfig(user_config_file=test_config_filename) self.assertTrue(len(res_config.hook_manager) == 1) self.assertEqual(res_config.hook_manager[0].getWorkflow().src_file, os.path.join(os.getcwd(), "ECHO_WORKFLOW"))
def test_config( self ): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) self.assertIsInstance(main.ensembleConfig(), EnsembleConfig) self.assertIsInstance(main.analysisConfig(), AnalysisConfig) self.assertIsInstance(main.getModelConfig(), ModelConfig) #self.assertIsInstance(main.local_config(), LocalConfig) #warn: Should this be None? self.assertIsInstance(main.siteConfig(), SiteConfig) self.assertIsInstance(main.eclConfig(), EclConfig) self.assertIsInstance(main.plotConfig(), PlotSettings) # self.main.load_obs(obs_config_file) self.assertIsInstance(main.getObservations(), EnkfObs) self.assertIsInstance(main.get_templates(), ErtTemplates) self.assertIsInstance(main.getEnkfFsManager().getCurrentFileSystem(), EnkfFs) # self.assertIsInstance(main.iget_member_config(0), MemberConfig) self.assertIsInstance(main.getMemberRunningState(0), EnKFState) self.assertEqual( "Ensemble" , main.getMountPoint()) main.free()
def test_with_gen_kw(self): case_directory = self.createTestPath("local/snake_oil_no_data/") with TestAreaContext("test_enkf_runpath", store_area=True) as work_area: work_area.copy_directory(case_directory) res_config = ResConfig("snake_oil_no_data/snake_oil.ert") main = EnKFMain(res_config) iactive = BoolVector(initial_size=main.getEnsembleSize(), default_value=False) iactive[0] = True fs = main.getEnkfFsManager().getCurrentFileSystem() run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive) main.createRunpath(run_context) self.assertFileExists( "snake_oil_no_data/storage/snake_oil/runpath/realisation-0/iter-0/parameters.txt" ) self.assertEqual( len(os.listdir("snake_oil_no_data/storage/snake_oil/runpath")), 1) self.assertEqual( len( os.listdir( "snake_oil_no_data/storage/snake_oil/runpath/realisation-0" )), 1, ) rp = main.create_runpath_list() self.assertEqual(len(rp), 0) rp.load() self.assertEqual(len(rp), 1)
def setUp(self): self.work_area = TestArea("ert_templates_test_tmp") self.config_data = { ConfigKeys.CONFIG_DIRECTORY: self.work_area.get_cwd(), ConfigKeys.CONFIG_FILE_KEY: "config", ConfigKeys.RUN_TEMPLATE: [("namea", "filea", [("keyaa", "valaa"), ("keyab", "valab"), ("keyac", "valac")]), ("nameb", "fileb", [("keyba", "valba"), ("keybb", "valbb"), ("keybc", "valbc")]), ("namec", "filec", [("keyca", "valca"), ("keycb", "valcb"), ("keycc", "valcc")])] } self.filename = self.config_data[ConfigKeys.CONFIG_FILE_KEY] # write a config file in order to load ResConfig self.make_config_file(self.filename) self.make_empty_file("namea") self.make_empty_file("nameb") self.make_empty_file("namec") self.res_config = ResConfig(user_config_file=self.filename)
def test_with_enkf_fs(self): config_file = self.createTestPath("Statoil/config/with_data/config") with TestAreaContext("enkf/summary_key_set/enkf_fs", store_area=True) as context: context.copy_parent_content(config_file) fs = EnkfFs("storage/default") summary_key_set = fs.getSummaryKeySet() summary_key_set.addSummaryKey("FOPT") summary_key_set.addSummaryKey("WWCT") summary_key_set.addSummaryKey("WOPR") fs.umount() res_config = ResConfig("config") ert = EnKFMain(res_config) fs = ert.getEnkfFsManager().getCurrentFileSystem() summary_key_set = fs.getSummaryKeySet() self.assertTrue("FOPT" in summary_key_set) self.assertTrue("WWCT" in summary_key_set) self.assertTrue("WOPR" in summary_key_set) ensemble_config = ert.ensembleConfig() self.assertTrue("FOPT" in ensemble_config) self.assertTrue("WWCT" in ensemble_config) self.assertTrue("WOPR" in ensemble_config) self.assertFalse("TCPU" in ensemble_config)
def test_stop_sim(self): config_file = self.createTestPath("local/batch_sim/batch_sim.ert") with TestAreaContext("batch_sim_stop") as ta: ta.copy_parent_content( config_file ) res_config = ResConfig( user_config_file = os.path.basename( config_file )) rsim = BatchSimulator( res_config, {"WELL_ORDER" : ["W1", "W2", "W3"], "WELL_ON_OFF" : ["W1","W2", "W3"]}, ["ORDER", "ON_OFF"]) case_name = 'MyCaseName_123' # Starting a simulation which should actually run through. ctx = rsim.start(case_name, [(2, { "WELL_ORDER": [1, 2, 3], "WELL_ON_OFF": [4, 5, 6] }), (1, { "WELL_ORDER": [7, 8, 9], "WELL_ON_OFF": [10, 11, 12] })]) ctx.stop() status = ctx.status self.assertEqual(status.complete, 0) self.assertEqual(status.running, 0) runpath = 'storage/batch_sim/runpath/%s/realisation-0' % case_name self.assertTrue(os.path.exists(runpath))
def test_skip_clusters_yielding_empty_data_matrixes(monkeypatch, test_data_root): def raising_scaling_job(data): if data == { "CALCULATE_KEYS": { "keys": [{ "index": [88, 89], "key": "FOPR" }] } }: raise EmptyDatasetException("foo") scaling_mock = Mock(return_value=Mock( **{"run.side_effect": raising_scaling_job})) monkeypatch.setattr(sc, "CorrelatedObservationsScalingJob", scaling_mock) test_data_dir = os.path.join(test_data_root, "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) job = sc.SpearmanCorrelationJob(ert) try: job.run(*["-t", "1.0"]) except EmptyDatasetException: pytest.fail("EmptyDatasetException was not handled by SC job")
def _init_res_config(self, config): if isinstance(config, ResConfig): return config # The res_config argument can be None; the only reason to # allow that possibility is to be able to test that the # site-config loads correctly. if config is None or isinstance(config, basestring): user_config_file = None if isinstance(config, basestring): if not isfile(config): raise IOError('No such configuration file "%s".' % res_config) warnings.warn("Initializing enkf_main with a config_file is " "deprecated. Please use res_config to load the file " "instead", DeprecationWarning ) user_config_file = config res_config = ResConfig(user_config_file) res_config.convertToCReference(self) return res_config raise TypeError("Expected ResConfig, received: %r" % res_config)
def test_shell_script_jobs_names(self): config_file = self.createTestPath("local/simple_config/minimum_config") shell_job_names = [ "delete_file", "delete_directory", "copy_directory", "make_symlink", "move_file", "make_directory", "careful_copy_file", "symlink", "copy_file", ] res_config = ResConfig(config_file) found_jobs = set() list_from_content = res_config.ert_workflow_list for wf_name in list_from_content.getJobNames(): exe = list_from_content.getJob(wf_name).executable() if exe and "shell_scripts" in exe: assert wf_name in shell_job_names found_jobs.add(wf_name) assert len(shell_job_names) == len(found_jobs)
def test_run_context(self): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) fs_manager = main.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem( ) iactive = BoolVector(initial_size = 10 , default_value = True) iactive[0] = False iactive[1] = False run_context = main.getRunContextENSEMPLE_EXPERIMENT( fs , iactive ) self.assertEqual( len(run_context) , 8 ) with self.assertRaises(IndexError): run_context[8] with self.assertRaises(TypeError): run_context["String"] run_arg = run_context[0] self.assertTrue( isinstance( run_arg , RunArg )) with self.assertRaises(ValueError): run_context.iensGet(0) with self.assertRaises(ValueError): run_context.iensGet(1) arg0 = run_context[0] arg2 = run_context.iensGet( 2 )
def test_add_observation_vectors(test_data_root): valid_config_data = {"UPDATE_KEYS": {"keys": [{"key": "WOPR_OP1_108"}]}} schema = job_config._CORRELATED_OBSERVATIONS_SCHEMA config = configsuite.ConfigSuite(valid_config_data, schema, deduce_required=True) test_data_dir = os.path.join(test_data_root, "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) obs = ert.getObservations() new_events = create_active_lists(obs, config.snapshot.UPDATE_KEYS.keys) keys = [event.key for event in new_events] assert "WOPR_OP1_108" in keys assert "WOPR_OP1_144" not in keys
def test_bootstrap( self ): with TestAreaContext("enkf_test", store_area=True) as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) self.assertTrue(main, "Load failed") main.free()
def test_without_gen_kw(self): case_directory = self.createTestPath('local/snake_oil_no_data/') with TestAreaContext('test_enkf_runpath', store_area=True) as work_area: work_area.copy_directory(case_directory) res_config = ResConfig('snake_oil_no_data/snake_oil_no_gen_kw.ert') main = EnKFMain(res_config) iactive = BoolVector(initial_size=main.getEnsembleSize(), default_value=False) iactive[0] = True fs = main.getEnkfFsManager().getCurrentFileSystem() run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive) main.createRunpath(run_context) self.assertDirectoryExists( 'storage/snake_oil_no_gen_kw/runpath/realisation-0/iter-0') self.assertFileDoesNotExist( 'storage/snake_oil_no_gen_kw/runpath/realisation-0/iter-0/parameters.txt' ) self.assertEqual( len(os.listdir('storage/snake_oil_no_gen_kw/runpath')), 1) self.assertEqual( len( os.listdir( 'storage/snake_oil_no_gen_kw/runpath/realisation-0')), 1)
def test_invalid_parameter_count_3_res_config(self): with TestAreaContext("enkf_test") as work_area: with self.assertRaises(ValueError): work_area.copy_directory(self.case_directory) res_config = ResConfig(user_config_file="a", config="b", config_dict="c")
def run_gui(args): app = QApplication( []) # Early so that QT is initialized before other imports app.setWindowIcon(resourceIcon("application/window_icon_cutout")) res_config = ResConfig(args.config) # Create logger inside function to make sure all handlers have been added to # the root-logger. logger = logging.getLogger(__name__) logger.info( "Logging forward model jobs", extra={ "workflow_jobs": str(res_config.model_config.getForwardModel().joblist()) }, ) os.chdir(res_config.config_path) # Changing current working directory means we need to update the config file to # be the base name of the original config args.config = os.path.basename(args.config) ert = EnKFMain(res_config, strict=True, verbose=args.verbose) notifier = ErtNotifier(args.config) # window reference must be kept until app.exec returns: window = _start_window(ert, notifier, args) # noqa return app.exec_()
def test_multiple_configs(self): with pytest.raises( ValueError, match= "Attempting to create ResConfig object with multiple config objects", ): ResConfig(user_config_file="test", config="test")
def test_misfit_preprocessor_skip_clusters_yielding_empty_data_matrixes(monkeypatch): def raising_scaling_job(data): if data == {"CALCULATE_KEYS": {"keys": [{"index": [88, 89], "key": "FOPR"}]}}: raise EmptyDatasetException("foo") scaling_mock = Mock(return_value=Mock(**{"run.side_effect": raising_scaling_job})) monkeypatch.setattr( misfit_preprocessor, "CorrelatedObservationsScalingJob", scaling_mock ) test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) config = {"clustering": {"spearman_correlation": {"fcluster": {"t": 1.0}}}} config_file = "my_config_file.yaml" with open(config_file, "w") as f: yaml.dump(config, f) job = misfit_preprocessor.MisfitPreprocessorJob(ert) try: job.run(config_file) except EmptyDatasetException: pytest.fail("EmptyDatasetException was not handled by misfit preprocessor")
def test_run_context(self): with TestAreaContext("enkf_test") as work_area: work_area.copy_directory(self.case_directory) res_config = ResConfig("simple_config/minimum_config") main = EnKFMain(res_config) fs_manager = main.getEnkfFsManager() fs = fs_manager.getCurrentFileSystem() iactive = BoolVector(initial_size=10, default_value=True) iactive[0] = False iactive[1] = False run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive) self.assertEqual(len(run_context), 10) with self.assertRaises(IndexError): run_context[10] with self.assertRaises(TypeError): run_context["String"] self.assertIsNone(run_context[0]) run_arg = run_context[2] self.assertTrue(isinstance(run_arg, RunArg)) rng1 = main.rng() rng1.setState("ABCDEFGHIJ012345") d1 = rng1.getDouble() rng1.setState("ABCDEFGHIJ012345") rng2 = main.rng() d2 = rng2.getDouble() self.assertEqual(d1, d2)
def test_missing_config(self): with pytest.raises( ValueError, match= "Error trying to create ResConfig without any configuration", ): ResConfig()
def test_misfit_preprocessor_invalid_config(): test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) config = { "unknown_key": [], "clustering": {"spearman_correlation": {"fcluster": {"threshold": 1.0}}}, } config_file = "my_config_file.yaml" with open(config_file, "w") as f: yaml.dump(config, f) job = misfit_preprocessor.MisfitPreprocessorJob(ert) with pytest.raises(semeio.jobs.misfit_preprocessor.ValidationError) as ve: job.run(config_file) expected_err_msg = ( "Invalid configuration of misfit preprocessor\n" " - Unknown key: unknown_key (root level)\n" " - Unknown key: threshold (clustering.spearman_correlation.fcluster)\n" ) assert expected_err_msg == str(ve.value)
def test_extensive_config(self): self.set_up_snake_oil_structure() with TestAreaContext("enkf_test_other_area") as work_area: work_area.copy_directory(self.case_directory) # Move to another directory run_dir = "i/ll/camp/here" os.makedirs(run_dir) os.chdir(run_dir) inv_run_dir = "/".join([".."] * len(run_dir.split("/"))) rel_config_file = os.path.join(inv_run_dir, self.config_file) work_dir = os.path.split(rel_config_file)[0] res_config = ResConfig(rel_config_file) self.assert_model_config(res_config.model_config, config_data, work_dir) self.assert_analysis_config(res_config.analysis_config, config_data) self.assert_queue_config(res_config.queue_config, config_data) self.assert_site_config(res_config.site_config, config_data, work_dir) self.assert_ecl_config(res_config.ecl_config, config_data, work_dir) self.assert_ensemble_config(res_config.ensemble_config, config_data, work_dir) self.assert_hook_manager(res_config.hook_manager, config_data, work_dir) self.assert_ert_workflow_list(res_config.ert_workflow_list, config_data, work_dir) self.assert_rng_config(res_config.rng_config, config_data, work_dir) self.assert_ert_templates(res_config.ert_templates, config_data, work_dir)
def test_misfit_preprocessor_main_entry_point_gen_data(monkeypatch): run_mock = Mock() scal_job = Mock(return_value=Mock(run=run_mock)) monkeypatch.setattr( misfit_preprocessor, "CorrelatedObservationsScalingJob", scal_job, ) test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil") shutil.copytree(test_data_dir, "test_data") os.chdir(os.path.join("test_data")) res_config = ResConfig("snake_oil.ert") ert = EnKFMain(res_config) config = {"clustering": {"spearman_correlation": {"fcluster": {"t": 1.0}}}} config_file = "my_config_file.yaml" with open(config_file, "w") as f: yaml.dump(config, f) misfit_preprocessor.MisfitPreprocessorJob(ert).run(config_file) # call_args represents the clusters, we expect the snake_oil # observations to generate this amount of them # call_args is a call object, which itself is a tuple of args and kwargs. # In this case, we want args, and the first element of the arguments, which # again is a tuple containing the configuration which is a list of configs. assert len(run_mock.call_args[0][0]) == 47, "wrong number of clusters"