diff --git a/src/plopm/core/plopm.py b/src/plopm/core/plopm.py index 38128cf..3a3cee0 100644 --- a/src/plopm/core/plopm.py +++ b/src/plopm/core/plopm.py @@ -9,6 +9,7 @@ import shlex import shutil import subprocess +from typing import NoReturn from plopm.utils.initialization import ( ini_cfg, @@ -21,7 +22,7 @@ from plopm.utils.write_vtk import make_vtks -def main(argv=None) -> None: +def main(argv: list[str] | None = None) -> None: """Main function for the plopm executable""" cmdargs = load_parser(argv) check_cmdargs(cmdargs) @@ -29,7 +30,7 @@ def main(argv=None) -> None: print("\nExecuting plopm, please wait.") if cfg.vtk: make_vtks( - cmdargs["path"], + cmdargs.path, cfg.names, cfg.output, cfg.save, @@ -67,7 +68,7 @@ def main(argv=None) -> None: ) -def load_parser(argv: list[str] | None) -> dict: +def load_parser(argv: list[str] | None = None) -> argparse.Namespace: """CLI arguments""" parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, @@ -384,6 +385,7 @@ def load_parser(argv: list[str] | None) -> dict: parser.add_argument( "-global", "--global", + dest="global_", type=str.strip, choices=["0", "1"], default="0", @@ -594,10 +596,10 @@ def load_parser(argv: list[str] | None) -> dict: default="0", help="Use ax.step instead of ax.plot", ) - return vars(parser.parse_known_args(argv)[0]) + return parser.parse_args(argv) -def check_cmdargs(cmdargs: dict[str, str]) -> None: +def check_cmdargs(cmdargs: argparse.Namespace) -> None: """Validate command-line arguments and incompatible operations. Parameters @@ -611,7 +613,7 @@ def check_cmdargs(cmdargs: dict[str, str]) -> None: If an argument is invalid or an incompatible combination is requested. """ - def fail(message: str) -> None: + def fail(message: str) -> NoReturn: print(message) raise SystemExit(1) @@ -642,18 +644,18 @@ def parse_number_list( ) return numbers - mode = cmdargs["mode"] + mode = cmdargs.mode vtk_mode = mode == "vtk" gif_mode = mode == "gif" number = r"[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?" positive_integer = r"[1-9]\d*" non_negative_integer = r"\d+" - if not cmdargs["input"]: + if not cmdargs.input: fail("Invalid value for '-i', the input cannot be empty.") - if not cmdargs["output"]: + if not cmdargs.output: fail("Invalid value for '-o', the output folder cannot be empty.") - if not cmdargs["variable"]: + if not cmdargs.variable: fail("Invalid value for '-v', the variable cannot be empty.") positive_number_options = [ @@ -665,11 +667,11 @@ def parse_number_list( ("-interval", "interval"), ] for option, name in positive_number_options: - value = parse_number(option, cmdargs[name]) + raw_value = getattr(cmdargs, name) + value = parse_number(option, raw_value) if value <= 0: fail( - f"Invalid value '{option} {cmdargs[name]}', expected a positive " - "number." + f"Invalid value '{option} {raw_value}', expected a positive " "number." ) number_options = [ @@ -677,29 +679,27 @@ def parse_number_list( ("-rotate", "rotate"), ] for option, name in number_options: - parse_number(option, cmdargs[name]) - parse_number_list("-a", cmdargs["adjust"]) + parse_number(option, getattr(cmdargs, name)) + + parse_number_list("-a", cmdargs.adjust) optional_number_options = [ ("-vmin", "vmin"), ("-vmax", "vmax"), ] for option, name in optional_number_options: - if cmdargs[name]: - parse_number(option, cmdargs[name]) + value = getattr(cmdargs, name) + if value: + parse_number(option, value) - if ( - cmdargs["vmin"] - and cmdargs["vmax"] - and float(cmdargs["vmin"]) > float(cmdargs["vmax"]) - ): + if cmdargs.vmin and cmdargs.vmax and float(cmdargs.vmin) > float(cmdargs.vmax): fail( - f"Invalid values '-vmin {cmdargs['vmin']}' and " - f"'-vmax {cmdargs['vmax']}', the minimum threshold must not " + f"Invalid values '-vmin {cmdargs.vmin}' and " + f"'-vmax {cmdargs.vmax}', the minimum threshold must not " "be greater than the maximum threshold." ) - colorbar_tick_numbers = cmdargs["cnum"] + colorbar_tick_numbers = cmdargs.cnum if colorbar_tick_numbers: cnum_entries = colorbar_tick_numbers.split(",") if any(not re.fullmatch(positive_integer, entry) for entry in cnum_entries): @@ -716,25 +716,26 @@ def parse_number_list( ("-loop", "loop"), ] for option, name in boolean_options: - values = cmdargs[name].split(",") + raw_value = getattr(cmdargs, name) + values = raw_value.split(",") if any(value not in ["0", "1"] for value in values): fail( - f"Invalid value '{option} {cmdargs[name]}', expected values " + f"Invalid value '{option} {raw_value}', expected values " "containing only 0 or 1, separated by commas." ) dimensions = parse_number_list( "-d", - cmdargs["dimensions"], + cmdargs.dimensions, 2, ) if any(value <= 0 for value in dimensions): fail( - f"Invalid value '-d {cmdargs['dimensions']}', figure dimensions " + f"Invalid value '-d {cmdargs.dimensions}', figure dimensions " "must be positive." ) - translation = cmdargs["translate"] + translation = cmdargs.translate if not re.fullmatch( rf"\[\s*{number}\s*,\s*{number}\s*\]", translation, @@ -750,17 +751,17 @@ def parse_number_list( ("-x", "xlim"), ("-y", "ylim"), ]: - valu = cmdargs[name] - if not valu: + value = getattr(cmdargs, name) + if not value: continue - for interval_value in valu.split(): + for interval_value in value.split(): if not interval_pattern.fullmatch(interval_value): fail( f"Invalid value '{option} {interval_value}', expected two " "numeric bounds enclosed by brackets, e.g., '[0,10]'." ) - aggregation_methods = cmdargs["how"] + aggregation_methods = cmdargs.how if aggregation_methods: valid_aggregation_methods = [ "min", @@ -780,7 +781,7 @@ def parse_number_list( f"{', '.join(valid_aggregation_methods)}." ) - slide = cmdargs["slide"] + slide = cmdargs.slide slides = slide.split() slide_entry_pattern = re.compile( rf"(?:{positive_integer}|" rf"{positive_integer}:{positive_integer}|:)?" @@ -788,7 +789,7 @@ def parse_number_list( if not slides: fail("Invalid value for '-s', the slide selection cannot be empty.") - slide_entries = [] + slide_entries: list[list[str]] = [] for selection in slides: entries = selection.split(",") if len(entries) != 3 or any( @@ -822,7 +823,7 @@ def parse_number_list( ) slide_entries.append(entries) - restart = cmdargs["restart"] + restart = cmdargs.restart restart_pattern = re.compile( rf"(?:-1|" rf"{non_negative_integer}(?:,{non_negative_integer})*|" @@ -848,17 +849,17 @@ def parse_number_list( ("-e", "linestyle"), ] for option, name in list_options: - valu = cmdargs[name] - if valu and any(not entry for entry in valu.split(",")): - fail(f"Invalid value '{option} {valu}', entries cannot be empty.") + value = getattr(cmdargs, name) + if value and any(not entry for entry in value.split(",")): + fail(f"Invalid value '{option} {value}', entries cannot be empty.") - line_widths = cmdargs["lw"] + line_widths = cmdargs.lw if line_widths: width_values = parse_number_list("-lw", line_widths) if any(width <= 0 for width in width_values): fail(f"Invalid value '-lw {line_widths}', line widths must be " "positive.") - remove = cmdargs["remove"] + remove = cmdargs.remove remove_entries = remove.split(",") if len(remove_entries) != 4 or any( entry not in ["0", "1"] for entry in remove_entries @@ -868,7 +869,7 @@ def parse_number_list( "containing only 0 or 1." ) - subfigs = cmdargs["subfigs"] + subfigs = cmdargs.subfigs if subfigs: subfig_entries = subfigs.split(",") if len(subfig_entries) != 2 or any( @@ -879,7 +880,7 @@ def parse_number_list( "integers separated by a comma, e.g., '-subfigs 2,2'." ) - colorbar_axis = cmdargs["cbsfax"] + colorbar_axis = cmdargs.cbsfax if colorbar_axis != "empty": colorbar_axis_values = parse_number_list( "-cbsfax", @@ -897,7 +898,7 @@ def parse_number_list( "must be positive." ) - grid = cmdargs["grid"] + grid = cmdargs.grid if grid: grid_entries = grid.split(",") if len(grid_entries) != 2 or not grid_entries[0] or not grid_entries[1]: @@ -908,7 +909,7 @@ def parse_number_list( if parse_number("-grid", grid_entries[1]) < 0: fail(f"Invalid value '-grid {grid}', the line width cannot be " "negative.") - csv_columns = cmdargs["csv"] + csv_columns = cmdargs.csv if csv_columns: csv_specifications = csv_columns.split(";") for specification in csv_specifications: @@ -929,7 +930,7 @@ def parse_number_list( "each specification must be different." ) - histogram = cmdargs["histogram"] + histogram = cmdargs.histogram if histogram: histogram_specifications = histogram.split() for specification in histogram_specifications: @@ -956,7 +957,7 @@ def parse_number_list( "distributions are 'norm' and 'lognorm'." ) - band_properties = cmdargs["bandprop"] + band_properties = cmdargs.bandprop if band_properties: band_entries = band_properties.split(",") if len(band_entries) % 2 != 0 or any(not color for color in band_entries[::2]): @@ -973,34 +974,29 @@ def parse_number_list( f"Invalid value '-bandprop {band_properties}', alpha values " "must be between 0 and 1." ) - if cmdargs["ensemble"] not in ["1", "3"]: + if cmdargs.ensemble not in ["1", "3"]: fail( "Invalid combination, '-bandprop' can only be used with " "'-ensemble 1' or '-ensemble 3'." ) - log_values = cmdargs["log"].split(",") - if any(value not in ["0", "1"] for value in log_values): - fail( - f"Invalid value '-log {cmdargs['log']}', expected values containing " - "only 0 or 1, separated by commas." - ) + log_values = cmdargs.log.split(",") - if cmdargs["clogthks"] and "1" not in log_values: + if cmdargs.clogthks and "1" not in log_values: fail( "Invalid combination, '-clogthks' requires at least one logarithmic " "color scale enabled with '-log'." ) - if cmdargs["maskthr"] != "1e-3" and not cmdargs["mask"]: + if cmdargs.maskthr != "1e-3" and not cmdargs.mask: fail( "Invalid combination, '-maskthr' can only be changed when '-mask' " "is used." ) if ( - cmdargs["distance"] - and "sensor" in cmdargs["distance"] + cmdargs.distance + and "sensor" in cmdargs.distance and any( any(not re.fullmatch(positive_integer, entry) for entry in entries) for entries in slide_entries @@ -1011,7 +1007,7 @@ def parse_number_list( "provided with '-s' to contain three positive indices." ) - vtk_names = cmdargs["vtknames"] + vtk_names = cmdargs.vtknames if vtk_names: vtk_name_entries = vtk_names.split(",") if any(not name for name in vtk_name_entries): @@ -1033,10 +1029,10 @@ def parse_number_list( "Int8", "UInt8", ] - vtk_formats = cmdargs["vtkformat"].split(",") + vtk_formats = cmdargs.vtkformat.split(",") if any(vtk_format not in valid_vtk_formats for vtk_format in vtk_formats): fail( - f"Invalid value '-vtkformat {cmdargs['vtkformat']}', valid " + f"Invalid value '-vtkformat {cmdargs.vtkformat}', valid " f"formats are {', '.join(valid_vtk_formats)}." ) @@ -1049,7 +1045,7 @@ def parse_number_list( invalid_options = [ option for option, (name, default) in vtk_options.items() - if cmdargs[name] != default + if getattr(cmdargs, name) != default ] if invalid_options: fail( @@ -1058,12 +1054,12 @@ def parse_number_list( ) else: try: - flow_arguments = shlex.split(cmdargs["path"]) + flow_arguments = shlex.split(cmdargs.path) except ValueError: flow_arguments = [] if not flow_arguments: - fail(f"Invalid OPM Flow command '-p {cmdargs['path']}'.") + fail(f"Invalid OPM Flow command '-p {cmdargs.path}'.") try: flow_result = subprocess.run( @@ -1077,7 +1073,7 @@ def parse_number_list( if flow_result is None or flow_result.returncode != 0: fail( - f"The OPM Flow executable '-p {cmdargs['path']}' is not " + f"The OPM Flow executable '-p {cmdargs.path}' is not " "available or not working." ) @@ -1089,7 +1085,7 @@ def parse_number_list( invalid_options = [ option for option, (name, default) in gif_options.items() - if cmdargs[name] != default + if getattr(cmdargs, name) != default ] if invalid_options: fail( diff --git a/src/plopm/utils/initialization.py b/src/plopm/utils/initialization.py index 211d578..a31b9f1 100644 --- a/src/plopm/utils/initialization.py +++ b/src/plopm/utils/initialization.py @@ -4,6 +4,7 @@ """Utility functions to set the requiried input values by plopm""" +import argparse import copy import os import shutil @@ -18,10 +19,10 @@ from plopm.config.config import ConfigPlopm -def ini_cfg(cmdargs: dict) -> ConfigPlopm: - """Initialize the configuration dataclass""" +def ini_cfg(cmdargs: argparse.Namespace) -> ConfigPlopm: + """Initialize the configuration dataclass.""" - def find_all_cases(folder: str, suffix: str) -> list[str]: + def find_all_cases(folder: str, suffix: str) -> list: folder_path = folder if folder_path[0] != ".": folder_path = "./" + folder_path @@ -43,14 +44,17 @@ def find_first_case(folder: str, suffix: str) -> str: return folder cfg = ConfigPlopm() - cfg.output = os.path.abspath(cmdargs["output"]) - names = cmdargs["input"].split(" ") + cfg.output = os.path.abspath(cmdargs.output) + names = cmdargs.input.split(" ") names = [var.split(" ") for var in names] cfg.namens = names + for name in ["gif", "csv", "png", "vtk"]: - setattr(cfg, name, cmdargs["mode"] == name) - cfg.diff = cmdargs["diff"] - cfg.ensemble = int(cmdargs["ensemble"]) + setattr(cfg, name, cmdargs.mode == name) + + cfg.diff = cmdargs.diff + cfg.ensemble = int(cmdargs.ensemble) + if cfg.diff: if cfg.diff[-1] in [".", "/"]: cfg.diff = find_first_case(cfg.diff, ".EGRID") @@ -66,27 +70,43 @@ def find_first_case(folder: str, suffix: str) -> str: names[-1] = find_all_cases(folder, ".DATA") else: names[-1] = find_all_cases(folder, ".SMSPEC") + cfg.names = names cfg.name = names[0][0] - cfg.vrs = cmdargs["variable"].lower().split(",") + cfg.vrs = cmdargs.variable.lower().split(",") handle_blocks(cfg) - cfg.stress = float(cmdargs["stress"]) + cfg.stress = float(cmdargs.stress) + for name in ["vtknames", "save"]: - setattr(cfg, name, cmdargs[name].split(" ")) + setattr(cfg, name, getattr(cmdargs, name).split(" ")) + cfg.mass = ["gasm", "dism", "liqm", "vapm", "co2m", "h2om"] cfg.xmass = ["xco2l", "xh2ov", "xco2v", "xh2ol"] cfg.caprock = ["limipres", "overpres", "objepres"] + for name in ["filter", "restart", "adjust", "vtkformat"]: - setattr(cfg, name, cmdargs[name].split(",")) + setattr(cfg, name, getattr(cmdargs, name).split(",")) + if cfg.restart[0] == "-1": cfg.restart = [-1] elif ":" in cfg.restart[0]: cfg.rst_range = True vals = cfg.restart[0].split(":") if len(vals) == 3: - cfg.restart = list(range(int(vals[0]), int(vals[1]) + 1, int(vals[2]))) + cfg.restart = list( + range( + int(vals[0]), + int(vals[1]) + 1, + int(vals[2]), + ) + ) else: - cfg.restart = list(range(int(vals[0]), int(vals[1]) + 1)) + cfg.restart = list( + range( + int(vals[0]), + int(vals[1]) + 1, + ) + ) if cfg.save[0]: width = len(str(cfg.restart[-1])) cfg.save = [ @@ -94,7 +114,7 @@ def find_first_case(folder: str, suffix: str) -> str: for restart_value in cfg.restart ] else: - if "," in cmdargs["restart"] and (cfg.png or cfg.csv): + if "," in cmdargs.restart and (cfg.png or cfg.csv): cfg.rst_range = True width = len(str(cfg.restart[-1])) cfg.save = [ @@ -102,52 +122,66 @@ def find_first_case(folder: str, suffix: str) -> str: for restart_value in cfg.restart ] cfg.restart = [int(restart_value) for restart_value in cfg.restart] + for name in ["vtkformat", "adjust", "vtknames"]: if len(getattr(cfg, name)) < len(cfg.vrs): - setattr(cfg, name, [getattr(cfg, name)[0]] * len(cfg.vrs)) + setattr( + cfg, + name, + [getattr(cfg, name)[0]] * len(cfg.vrs), + ) + if not os.path.exists(cfg.output): os.makedirs(cfg.output, exist_ok=True) + if cfg.vtk: return cfg - cfg.csvs = cmdargs["csv"].split(";") + + cfg.csvs = cmdargs.csv.split(";") cfg.csvs = [[int(val) if val else "" for val in var.split(",")] for var in cfg.csvs] + allcsvs = True for val in cfg.csvs: if not val[0]: allcsvs = False - else: - if len(val) == 2: - cfg.csvsummary = True + elif len(val) == 2: + cfg.csvsummary = True + if allcsvs: cfg.vrs = ["csv"] + max_count = max(len(cfg.names[0]), len(cfg.vrs)) if len(cfg.csvs) == 1 and not cfg.csvs[0][0]: cfg.csvs = [cfg.csvs[0]] * (max_count + 1) + for name in ["mask", "lw", "linestyle", "ncolor"]: - setattr(cfg, name, cmdargs[name].lower()) + setattr(cfg, name, getattr(cmdargs, name).lower()) + for name in ["size", "maskthr", "interval"]: - setattr(cfg, name, float(cmdargs[name])) + setattr(cfg, name, float(getattr(cmdargs, name))) + for name in ["cticks", "title"]: - setattr(cfg, name, cmdargs[name].split(" ")) + setattr(cfg, name, getattr(cmdargs, name).split(" ")) + for name in ["bounds", "translate", "histogram"]: - setattr(cfg, name, cmdargs[name].split(" ")) - for name in [ - "suptitle", - "bandprop", - "clabel", - ]: - setattr(cfg, name, cmdargs[name]) + setattr(cfg, name, getattr(cmdargs, name).split(" ")) + + for name in ["suptitle", "bandprop", "clabel"]: + setattr(cfg, name, getattr(cmdargs, name)) + cfg.bounds = [var.split(",") for var in cfg.bounds] cfg.translate = [var.split(",") for var in cfg.translate] - cfg.colors_raw = cmdargs["colors"] - cfg.cf = cmdargs["cformat"] - cfg.fc = cmdargs["facecolor"] - cfg.labels = cmdargs["labels"].split(" ") + cfg.colors_raw = cmdargs.colors + cfg.cf = cmdargs.cformat + cfg.fc = cmdargs.facecolor + cfg.labels = cmdargs.labels.split(" ") cfg.labels = [var.split(" ") for var in cfg.labels] - cfg.rm = [int(val) for val in cmdargs["remove"].split(",")] - cfg.global_ = int(cmdargs["global"]) == 1 + cfg.rm = [int(val) for val in cmdargs.remove.split(",")] + cfg.global_ = int(cmdargs.global_) == 1 + for name in ["scale", "delax", "loop", "printv", "step"]: - setattr(cfg, name, int(cmdargs[name]) == 1) + setattr(cfg, name, int(getattr(cmdargs, name)) == 1) + for name in [ "dimensions", "distance", @@ -157,34 +191,64 @@ def find_first_case(folder: str, suffix: str) -> str: "loc", "axgrid", ]: - setattr(cfg, name, cmdargs[name].split(",")) + setattr(cfg, name, getattr(cmdargs, name).split(",")) + for name in ["dpi", "tunits", "cnum", "grid"]: - setattr(cfg, name, cmdargs[name].split(",")) + setattr(cfg, name, getattr(cmdargs, name).split(",")) + for name in ["dual", "subfigs", "vmin", "vmax"]: - setattr(cfg, name, cmdargs[name].split(",")) + setattr(cfg, name, getattr(cmdargs, name).split(",")) + for axis_name in ["x", "y"]: - setattr(cfg, f"{axis_name}units", cmdargs[f"{axis_name}units"]) - setattr(cfg, f"{axis_name}label", cmdargs[f"{axis_name}label"].split(" ")) - setattr(cfg, f"{axis_name}format", cmdargs[f"{axis_name}format"].split(",")) - setattr(cfg, f"{axis_name}lnum", cmdargs[f"{axis_name}lnum"].split(",")) - setattr(cfg, f"{axis_name}log", cmdargs[f"{axis_name}log"].split(",")) - setattr(cfg, f"{axis_name}lim", cmdargs[f"{axis_name}lim"].split(" ")) + setattr( + cfg, + f"{axis_name}units", + getattr(cmdargs, f"{axis_name}units"), + ) + setattr( + cfg, + f"{axis_name}label", + getattr(cmdargs, f"{axis_name}label").split(" "), + ) + setattr( + cfg, + f"{axis_name}format", + getattr(cmdargs, f"{axis_name}format").split(","), + ) + setattr( + cfg, + f"{axis_name}lnum", + getattr(cmdargs, f"{axis_name}lnum").split(","), + ) + setattr( + cfg, + f"{axis_name}log", + getattr(cmdargs, f"{axis_name}log").split(","), + ) + setattr( + cfg, + f"{axis_name}lim", + getattr(cmdargs, f"{axis_name}lim").split(" "), + ) setattr( cfg, f"{axis_name}lim", [var.split(",") for var in getattr(cfg, f"{axis_name}lim")], ) - if cmdargs["clogthks"]: - cfg.clogthks = [float(val) for val in cmdargs["clogthks"][1:-1].split(",")] + + if cmdargs.clogthks: + cfg.clogthks = [float(val) for val in cmdargs.clogthks[1:-1].split(",")] + if cfg.cticks[0]: for index, values in enumerate(cfg.cticks): cfg.cticks[index] = [val.strip() for val in values[1:-1].split(",")] - if cmdargs["cbsfax"] != "empty": + if cmdargs.cbsfax != "empty": cfg.cbsfax = cast( tuple[float, float, float, float], - tuple(map(float, cmdargs["cbsfax"].split(","))), + tuple(map(float, cmdargs.cbsfax.split(","))), ) - cfg.slide = cmdargs["slide"].split(" ") + + cfg.slide = cmdargs.slide.split(" ") cfg.slide = [ [val if val else [-2, -2] for val in var.split(",")] for var in cfg.slide ] @@ -325,7 +389,7 @@ def find_first_case(folder: str, suffix: str) -> str: setattr(cfg, val, [getattr(cfg, val)[0]] * len(cfg.restart)) if len(cfg.restart) > 1 and cfg.subfigs[0]: - cfg.save = [cmdargs["save"]] + cfg.save = [cmdargs.save] if cfg.diff: cfg.how = [cfg.how[0]] * 2 diff --git a/tests/scripts/docs_check_outputs.sh b/tests/scripts/docs_check_outputs.sh index ebe5505..8589dfa 100644 --- a/tests/scripts/docs_check_outputs.sh +++ b/tests/scripts/docs_check_outputs.sh @@ -1,70 +1,77 @@ -files=( - "test_outputs/docs_caprock_integrity/norne_atw2013_overpres_i,j,1:22_t241.png" - "test_outputs/docs_caprock_integrity/norne_atw2013_objepres_i,j,1:22_t241.csv" - "test_outputs/docs_colormaps/spe11b_disperc_i,1,k_t5.png" - "test_outputs/docs_projections_subfigures/norne_atw2013_poro_i,j,1:22_t241.png" - "test_outputs/docs_graphical_abstract/SPE11C-0000.vtu" - "test_outputs/docs_graphical_abstract/SPE11C-GRID.vtu" - "test_outputs/docs_graphical_abstract/SPE11C-0005.vtu" - "test_outputs/docs_graphical_abstract/norne_atw2013_permx_i,j,1_t241.png" - "test_outputs/docs_graphical_abstract/SPE11C.pvd" - "test_outputs/docs_graphical_abstract/spe11b_base_fgmip*1e-6.png" - "test_outputs/docs_different_files_and_ensembles/example3_formated.png" - "test_outputs/docs_different_files_and_ensembles/example0.png" - "test_outputs/docs_different_files_and_ensembles/comparison.png" - "test_outputs/docs_different_files_and_ensembles/spe11b_larger_inj_sgas_i,1,k_t3.png" - "test_outputs/docs_different_files_and_ensembles/formated.png" - "test_outputs/docs_histograms/norne_atw2013_permx.png" - "test_outputs/docs_reading_csvs/spe11b_time_series_bwpr-256,1,5.png" - "test_outputs/docs_reading_csvs/spe11b_spatial_map_500y_xco2l__t100.png" - "test_outputs/docs_reading_csvs/spe11b_spatial_map_250y_csv__t-1.png" - "test_outputs/docs_reading_csvs/spe11b_time_series_csv.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_permz_i,j,1_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_poro_i,j,1_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_permx_i,j,1_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_wells_global.png" - "test_outputs/docs_rotation_translation_zoom/norne_wells.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_faults_i,j,1:22_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_satnum_i,j,1_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_fipnum_i,j,1_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_porv_i,j,1_t241.png" - "test_outputs/docs_rotation_translation_zoom/norne_atw2013_faults_i,j,1_t241.png" - "test_outputs/docs_convert_to_vtk/SPE11B-0000.vtu" - "test_outputs/docs_convert_to_vtk/SPE11B-GRID.vtu" - "test_outputs/docs_convert_to_vtk/SPE11B-0005.vtu" - "test_outputs/docs_convert_to_vtk/SPE11B.pvd" - "test_outputs/docs_gif_mask/xco2l.gif" - "test_outputs/docs_gif_mask/spe11b_base_sgas.gif" - "test_outputs/docs_hello_world/spe11b_satnum_i,1,k_t5.png" - "test_outputs/docs_hello_world/spe11b_permz_i,1,k_t5.png" - "test_outputs/docs_hello_world/spe11b_porv_i,1,k_t5.png" - "test_outputs/docs_hello_world/spe11b_poro_i,1,k_t5.png" - "test_outputs/docs_hello_world/spe11b_pressure-0pressure.png" - "test_outputs/docs_hello_world/spe11b_fgip.png" - "test_outputs/docs_hello_world/spe11b_permx_i,1,k_t5.png" - "test_outputs/docs_hello_world/spe11b_fipnum_i,1,k_t5.png" - "test_outputs/docs_hello_world/spe11b_sgas_i,1,k_t4.png" - "test_outputs/docs_filters/spe11b_fipnum_i,1,k_t5.png" - "test_outputs/docs_generic_deck/spe10_model2_grid_i,j,1_t0.png" - "test_outputs/docs_generic_deck/spe10_model2_wells_i,j,1_t0.png" - "test_outputs/docs_generic_deck/spe10_model2_permz_i,4,k_t0.png" -) +files=" +test_outputs/docs_caprock_integrity/norne_atw2013_overpres_i,j,1:22_t241.png +test_outputs/docs_caprock_integrity/norne_atw2013_objepres_i,j,1:22_t241.csv +test_outputs/docs_colormaps/spe11b_disperc_i,1,k_t5.png +test_outputs/docs_projections_subfigures/norne_atw2013_poro_i,j,1:22_t241.png +test_outputs/docs_graphical_abstract/SPE11C-0000.vtu +test_outputs/docs_graphical_abstract/SPE11C-GRID.vtu +test_outputs/docs_graphical_abstract/SPE11C-0005.vtu +test_outputs/docs_graphical_abstract/norne_atw2013_permx_i,j,1_t241.png +test_outputs/docs_graphical_abstract/SPE11C.pvd +test_outputs/docs_graphical_abstract/spe11b_base_fgmip*1e-6.png +test_outputs/docs_different_files_and_ensembles/example3_formated.png +test_outputs/docs_different_files_and_ensembles/example0.png +test_outputs/docs_different_files_and_ensembles/comparison.png +test_outputs/docs_different_files_and_ensembles/spe11b_larger_inj_sgas_i,1,k_t3.png +test_outputs/docs_different_files_and_ensembles/formated.png +test_outputs/docs_histograms/norne_atw2013_permx.png +test_outputs/docs_reading_csvs/spe11b_time_series_bwpr-256,1,5.png +test_outputs/docs_reading_csvs/spe11b_spatial_map_500y_xco2l__t100.png +test_outputs/docs_reading_csvs/spe11b_spatial_map_250y_csv__t-1.png +test_outputs/docs_reading_csvs/spe11b_time_series_csv.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_permz_i,j,1_t241.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_poro_i,j,1_t241.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_permx_i,j,1_t241.png +test_outputs/docs_rotation_translation_zoom/norne_wells_global.png +test_outputs/docs_rotation_translation_zoom/norne_wells.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_faults_i,j,1:22_t241.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_satnum_i,j,1_t241.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_fipnum_i,j,1_t241.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_porv_i,j,1_t241.png +test_outputs/docs_rotation_translation_zoom/norne_atw2013_faults_i,j,1_t241.png +test_outputs/docs_convert_to_vtk/SPE11B-0000.vtu +test_outputs/docs_convert_to_vtk/SPE11B-GRID.vtu +test_outputs/docs_convert_to_vtk/SPE11B-0005.vtu +test_outputs/docs_convert_to_vtk/SPE11B.pvd +test_outputs/docs_gif_mask/xco2l.gif +test_outputs/docs_gif_mask/spe11b_base_sgas.gif +test_outputs/docs_hello_world/spe11b_satnum_i,1,k_t5.png +test_outputs/docs_hello_world/spe11b_permz_i,1,k_t5.png +test_outputs/docs_hello_world/spe11b_porv_i,1,k_t5.png +test_outputs/docs_hello_world/spe11b_poro_i,1,k_t5.png +test_outputs/docs_hello_world/spe11b_pressure-0pressure.png +test_outputs/docs_hello_world/spe11b_fgip.png +test_outputs/docs_hello_world/spe11b_permx_i,1,k_t5.png +test_outputs/docs_hello_world/spe11b_fipnum_i,1,k_t5.png +test_outputs/docs_hello_world/spe11b_sgas_i,1,k_t4.png +test_outputs/docs_filters/spe11b_fipnum_i,1,k_t5.png +test_outputs/docs_generic_deck/spe10_model2_grid_i,j,1_t0.png +test_outputs/docs_generic_deck/spe10_model2_wells_i,j,1_t0.png +test_outputs/docs_generic_deck/spe10_model2_permz_i,4,k_t0.png +" missing_file="test_outputs/missing_docs_files.txt" -missing=0 rm -f "$missing_file" -for f in "${files[@]}"; do - if [[ ! -f "$f" ]]; then +printf '%s\n' "$files" | while IFS= read -r f; do + [ -z "$f" ] && continue + if [ ! -f "$f" ]; then echo "$f" >> "$missing_file" - ((missing++)) fi done -if (( missing == 0 )); then +if [ -f "$missing_file" ]; then + missing=$(wc -l < "$missing_file") +else + missing=0 +fi + +if [ "$missing" -eq 0 ]; then echo "All figures and files exist." + return 0 else echo "$missing figure(s) or file(s) missing." echo "See $missing_file" + return 1 fi diff --git a/tests/scripts/docs_filters.sh b/tests/scripts/docs_filters.sh index bd1ff4d..9504139 100644 --- a/tests/scripts/docs_filters.sh +++ b/tests/scripts/docs_filters.sh @@ -1,4 +1,4 @@ WHR="examples/SPE11B" OUT="test_outputs/docs_filters" . tests/scripts/initialize_output_folders.sh $OUT -plopm -i "$WHR $WHR $WHR" -o $OUT -filter ',fipnum >= 2 & fipnum != 4,satnum == 5' -v fipnum -subfigs 3,1 -delax 1 -cformat .0f -d 7,4 -u resdata -cbsfax 0.15,0.97,0.7,0.02 -t "No filter fipnum >= 2 and fipnum != 4 satnum == 5" -suptitle 0 +plopm -i "$WHR $WHR $WHR" -o $OUT -filter ',fipnum >= 2 & fipnum != 4,satnum == 5' -v fipnum -subfigs 3,1 -delax 1 -cformat .0f -d 7,4 -cbsfax 0.15,0.97,0.7,0.02 -t "No filter fipnum >= 2 and fipnum != 4 satnum == 5" -suptitle 0 diff --git a/tests/test_metrics.py b/tests/test_metrics.py index d5671e1..9a631e2 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -57,7 +57,6 @@ def test_metrics(tmp_path): str(mainpth / "examples" / "SPE11B"), "-m", "csv", - "SPE11B", "-o", str(tmp_path), "-v", diff --git a/tests/test_static.py b/tests/test_static.py index 40f20a4..0860d69 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -22,7 +22,7 @@ def test_static(tmp_path, monkeypatch): (tmp_path / "SPE11B.UNRST").write_bytes( (mainpth / "examples" / "SPE11B.UNRST").read_bytes() ) - main() + main([]) for name in ["porv", "poro", "permx", "permz", "satnum", "fipnum"]: assert (tmp_path / f"spe11b_{name}_i,1,k_t5.png").exists() main( diff --git a/tests/test_summary.py b/tests/test_summary.py index af32cfd..92319f0 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -104,8 +104,6 @@ def test_summary(tmp_path): "11", "-tunits", "y", - "-u", - "opm", "-o", str(tmp_path), ] @@ -131,8 +129,6 @@ def test_summary(tmp_path): "11", "-tunits", "y", - "-u", - "opm", "-o", str(tmp_path), "-save", @@ -173,8 +169,6 @@ def test_summary(tmp_path): "11", "-xunits", "km", - "-u", - "opm", "-o", str(tmp_path), "-save",