def simulation_compiled(model, domain, job_restart, tmpdir): sim_dir = pathlib.Path(tmpdir).joinpath('sim_compiled_dir') sim = Simulation() sim.add(model) sim.add(domain) sim.add(job_restart) os.mkdir(sim_dir) os.chdir(sim_dir) sim.compose() return sim
def test_simulation_run_no_scheduler(model, domain, job, tmpdir, capfd): sim = Simulation() sim.add(model) sim.add(domain) sim.add(job) compose_dir = pathlib.Path(tmpdir).joinpath('sim_run_no_sched') os.mkdir(str(compose_dir)) os.chdir(str(compose_dir)) sim.compose() sim.run() assert sim.jobs[0].exit_status == 0, \ "The job did not exit successfully."
def test_simulation_compose(model, domain, job, capfd, tmpdir): sim = Simulation() sim.add(model) sim.add(domain) sim.add(job) # copy before compose sim_opts = copy.deepcopy(sim) sim_tbls = copy.deepcopy(sim) compose_dir = pathlib.Path(tmpdir).joinpath('sim_compose') os.mkdir(str(compose_dir)) os.chdir(str(compose_dir)) sim.compose() # Doing this thrice kinda asks for function... # This compose exercises the options to compose. Gives the same result. compose_dir_opts = pathlib.Path(tmpdir).joinpath('sim_compose_opts') os.mkdir(str(compose_dir_opts)) os.chdir(str(compose_dir_opts)) sim_opts.compose(symlink_domain=False, force=True, check_nlst_warn=True) actual_files = list(compose_dir.rglob('./*')) domain_files = domain.domain_top_dir.rglob('*') expected_files = [ 'namelist.hrldas', 'hydro.namelist', 'job_test_job_1', '.uid', 'NWM', 'WrfHydroModel.pkl', 'FORCING', 'DUMMY.TBL', 'wrf_hydro.exe' ] for file in domain_files: expected_files.append(file.name) for file in actual_files: assert file.name in expected_files assert sim.model.table_files == sim_opts.model.table_files assert [str(ff.name) for ff in sim.model.table_files] == ['DUMMY.TBL'] # These composes result in alternative, user selected table files. # Do it before and after model.compile() sim_tbls_postcompile = copy.deepcopy(sim_tbls) dummy_user_tbl = pathlib.Path(tmpdir).joinpath('DUMMY_USER.TBL') with dummy_user_tbl.open('w') as f: f.write('# dummy TBL \n') compose_dir_tbls = pathlib.Path(tmpdir).joinpath('sim_compose_tbls') os.mkdir(str(compose_dir_tbls)) os.chdir(str(compose_dir_tbls)) # before compile sim_tbls.model.table_files = [dummy_user_tbl] sim_tbls.compose() compose_dir_tbls_postcompile = pathlib.Path(tmpdir).joinpath( 'sim_compose_tbls_postcompile') compile_dir_tbls_postcompile = pathlib.Path(tmpdir).joinpath( 'sim_compile_tbls_postcompile') os.mkdir(str(compose_dir_tbls_postcompile)) os.chdir(str(compose_dir_tbls_postcompile)) sim_tbls_postcompile.model.compile(compile_dir_tbls_postcompile) sim_tbls_postcompile.model.table_files = [dummy_user_tbl] sim_tbls_postcompile.compose() assert sim_tbls.model.table_files == sim_tbls_postcompile.model.table_files assert sim_tbls.model.table_files == [dummy_user_tbl] actual_files = list(compose_dir_tbls.rglob('./*')) domain_files = domain.domain_top_dir.rglob('*') expected_files = [ 'namelist.hrldas', 'hydro.namelist', 'job_test_job_1', '.uid', 'NWM', 'WrfHydroModel.pkl', 'FORCING', 'DUMMY_USER.TBL', 'wrf_hydro.exe' ] for file in domain_files: expected_files.append(file.name) for file in actual_files: assert file.name in expected_files