diff --git a/src/subscript/fmuobs/fmuobs.py b/src/subscript/fmuobs/fmuobs.py index 5216a76cb..b570dc1b8 100644 --- a/src/subscript/fmuobs/fmuobs.py +++ b/src/subscript/fmuobs/fmuobs.py @@ -363,7 +363,7 @@ def fmuobs( "Please verify the output file" ) logger.debug("After all the hard work, what is returned is this %s", dframe) - dump_results(dframe, csv, yml, resinsight, ertobs, Path(inputfile).parent) + dump_results(dframe, csv, yml, resinsight, ertobs, PosixPath(inputfile).parent) def dump_results( @@ -372,7 +372,7 @@ def dump_results( yamlfile: Optional[str] = None, resinsightfile: Optional[str] = None, ertfile: Optional[str] = None, - parent_dir: Optional[PosixPath] = Path("."), + parent_dir: PosixPath = PosixPath("."), ) -> None: """Dump dataframe with ERT observations to CSV and/or YML format to disk. Writes to stdout if filenames are "-". Skips diff --git a/src/subscript/fmuobs/gen_obs_writers.py b/src/subscript/fmuobs/gen_obs_writers.py index c167415e6..d0f532c2c 100644 --- a/src/subscript/fmuobs/gen_obs_writers.py +++ b/src/subscript/fmuobs/gen_obs_writers.py @@ -1,14 +1,12 @@ """Read contents from simple text files""" import logging -import warnings import re +import warnings from datetime import datetime -from pathlib import Path, PosixPath -from subscript.fmuobs.util import ( - ERT_ALT_DATE_FORMAT, - ERT_DATE_FORMAT, - ERT_ISO_DATE_FORMAT, -) +from pathlib import PosixPath +from typing import Optional, Union, List, Tuple + +from subscript.fmuobs.util import ERT_DATE_FORMAT, ERT_ISO_DATE_FORMAT LOGGER = logging.getLogger("gen_obs_writers") @@ -77,7 +75,7 @@ def ensure_correct_well_info_format(info): return info -def find_well_file_path(folder_path: PosixPath) -> PosixPath: +def find_well_file_path(folder_path: PosixPath) -> Optional[PosixPath]: """Find file with well information in folder Args: @@ -182,7 +180,7 @@ def add_extra_well_data_if_rft(dict_to_change: dict, parent_dir, obs_folders): print("After modification dict is ", dict_to_change) -def attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict) -> dict: +def attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict): """Attach data from secondary file if it exists Args: @@ -210,7 +208,8 @@ def attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict) - def dump_content_to_dict( - file_path: PosixPath, col_names: list = ("observations", "error") + file_path: PosixPath, + col_names: Union[List, Tuple] = ("observations", "error"), ) -> dict: """Read contents of file into list diff --git a/src/subscript/fmuobs/writers.py b/src/subscript/fmuobs/writers.py index a863aa964..3ccbf3ac7 100644 --- a/src/subscript/fmuobs/writers.py +++ b/src/subscript/fmuobs/writers.py @@ -280,7 +280,7 @@ def summary_df2obsdict(smry_df: pd.DataFrame) -> List[dict]: return smry_obs_list -def general_df2obsdict(general_df: pd.DataFrame, parent_dir: PosixPath) -> List[dict]: +def general_df2obsdict(general_df: pd.DataFrame, parent_dir: PosixPath) -> dict: """Generate a dictionary structure suitable for yaml for general observations in dataframe representation @@ -405,7 +405,7 @@ def block_df2obsdict(block_df: pd.DataFrame) -> List[dict]: return block_obs_list -def df2obsdict(obs_df: pd.DataFrame, parent_dir: PosixPath = Path(".")) -> dict: +def df2obsdict(obs_df: pd.DataFrame, parent_dir: PosixPath = PosixPath(".")) -> dict: """Generate a dictionary structure of all observations, this data structure is designed to look good in yaml, and is supported by WebViz and fmu-ensemble. diff --git a/tests/_common_fmuobs.py b/tests/_common_fmuobs.py index 7cc685425..4fa39cfe6 100644 --- a/tests/_common_fmuobs.py +++ b/tests/_common_fmuobs.py @@ -1,4 +1,5 @@ from pathlib import Path + import yaml TEST_DATA = TEST_DATA = "testdata_fmuobs/" @@ -74,10 +75,16 @@ def assert_equal_length(to_be_tested, correct, key): if to_be_tested_len != correct_len: if to_be_tested_len > correct_len: diff_set = to_be_tested_set.difference(correct_set) - mess = f"{key}: Produced keys are {to_be_tested_len - correct_len} more than they should ({diff_set})" + mess = ( + f"{key}: Produced keys are {to_be_tested_len - correct_len} " + f"more than they should ({diff_set})" + ) else: diff_set = correct_set.difference(to_be_tested_set) - mess = f"{key}: Produced keys are {correct_len - to_be_tested_len} less than they should ({diff_set})" + mess = ( + f"{key}: Produced keys are {correct_len - to_be_tested_len} " + f"less than they should ({diff_set})" + ) raise AssertionError(mess) diff --git a/tests/test_fmuobs_functions_4_general_obs_w_drogon.py b/tests/test_fmuobs_functions_4_general_obs_w_drogon.py index b3acb4cb8..573945fb4 100644 --- a/tests/test_fmuobs_functions_4_general_obs_w_drogon.py +++ b/tests/test_fmuobs_functions_4_general_obs_w_drogon.py @@ -1,12 +1,13 @@ """Test functions with drogon data""" import pandas as pd import pytest -from subscript.fmuobs.parsers import ertobs2df + from subscript.fmuobs.writers import general_df2obsdict + from ._common_fmuobs import ( - _find_observation_file, _assert_compulsories_are_correct, _compare_to_results_in_file, + _find_observation_file, ) @@ -81,13 +82,6 @@ def _fix_drogon_full_file(): return _find_observation_file("drogon_wbhp_rft_wct_gor_tracer_4d_plt.obs") -# def test_ertobs2df(drogon_full_obs_file): -# input_str = drogon_full_obs_file.read_text() -# print(input_str) -# full_df = ertobs2df(input_str) -# print(full_df) - - @pytest.mark.parametrize( "fixture_name", ["ert-doc_df", "drogon_tracer_df", "drogon_seismic_df", "drogon_rft_df"], @@ -117,16 +111,6 @@ def test_general_df2obsdict(fixture_name, drogon_full_obs_file, request): stream.close() _assert_compulsories_are_correct(results) if fixture_name != "ert-doc_df": - # Comparison with file not done for ert-doc, the ert-doc file is for + # Comparison with file not done for ert-doc, the ert-doc file is # not just for general_obs _compare_to_results_in_file(results, correct_result_file, where) - - -def test_general_df2obsdict_rft(drogon_full_obs_file, request): - fixture_name = "drogon_rft_df" - results = general_df2obsdict( - request.getfixturevalue(fixture_name), drogon_full_obs_file.parent - ) - # _assert_compulsories_are_correct(results) - - # _compare_to_results_in_file(results, fixture_name) diff --git a/tests/test_fmuobs_gen_obs_writers.py b/tests/test_fmuobs_gen_obs_writers.py index c03ffa2f4..a86cc8bac 100644 --- a/tests/test_fmuobs_gen_obs_writers.py +++ b/tests/test_fmuobs_gen_obs_writers.py @@ -1,8 +1,10 @@ -import re +"""Unit tests for gen_obs_writers""" from pathlib import Path -from subscript.fmuobs import gen_obs_writers + import pytest +from subscript.fmuobs import gen_obs_writers + TEST_DATA = "testdata_fmuobs" RFT_FOLDERS = ["drogon/rft/", "somewhere/completely/different/rft_ERT_use_MDadjusted/"] @@ -118,8 +120,3 @@ def test_tidy_general_obs_keys(): "tracer_jungle", "magic_seismic_data", } - - -# def test_add_extra_well_data_if_rft(dict_to_change: dict, parent_dir): -# def test_attach_spatial_data_if_exists(file_path: PosixPath, primary_content: dict) -> dict: -# def test_dump_content_to_dict( diff --git a/tests/test_fmuobs_make_dictionaries.py b/tests/test_fmuobs_make_dictionaries.py index 9184679e7..8bbd7bfca 100644 --- a/tests/test_fmuobs_make_dictionaries.py +++ b/tests/test_fmuobs_make_dictionaries.py @@ -1,15 +1,10 @@ -import re -from pathlib import Path -import yaml -from subscript.fmuobs.fmuobs import autoparse_file, df2obsdict -from pandas import DataFrame import pytest +from pandas import DataFrame + +from subscript.fmuobs.fmuobs import autoparse_file, df2obsdict + +from ._common_fmuobs import _find_observation_file -from ._common_fmuobs import ( - _find_observation_file, - _assert_compulsories_are_correct, - _compare_to_results_in_file, -) TEST_DATA = "testdata_fmuobs/"