Skip to content

Commit

Permalink
Improve testing wrt add2docs.
Browse files Browse the repository at this point in the history
The tests now to generate the added YAML files can be generated
with: pytest -k add2docs
  • Loading branch information
jcrivenaes committed Nov 22, 2022
1 parent f27016c commit 5afcc96
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 66 deletions.
Empty file removed .projectile
Empty file.
10 changes: 5 additions & 5 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Aggregate example 1

Minimal aggregation example, doing a "maximum" aggregation across all layers

.. literalinclude:: ../docs/test_to_docs/aggregate1.yml
.. literalinclude:: ../tests/yaml/aggregate1.yml
:language: yaml

Aggregate example 2
Expand All @@ -284,23 +284,23 @@ Aggregate example 2
Example using "minimum" aggregation. Zonation is provided in a property file, and ``eclroot:`` is
used as an alias

.. literalinclude:: ../docs/test_to_docs/aggregate2.yml
.. literalinclude:: ../tests/yaml/aggregate2.yml
:language: yaml

Aggregate example 3
"""""""""""""""""""

Example using "mean" aggregation and explicit map settings

.. literalinclude:: ../docs/test_to_docs/aggregate3.yml
.. literalinclude:: ../tests/yaml/aggregate3.yml
:language: yaml

Aggregate example 4
"""""""""""""""""""

Example using an interval-based zonation

.. literalinclude:: ../docs/test_to_docs/aggregate4.yml
.. literalinclude:: ../tests/yaml/aggregate4.yml
:language: yaml

Aggregate example 5
Expand All @@ -310,5 +310,5 @@ Example using "mean" aggregation, with weights calculated from cell thickness. "
is used as an alias. The map settings are calculated automatically, with resolution
determined by "pixel_to_cell_ratio".

.. literalinclude:: ../docs/test_to_docs/aggregate5.yml
.. literalinclude:: ../tests/yaml/aggregate5.yml
:language: yaml
53 changes: 24 additions & 29 deletions tests/test_scripts/test_grid3d_aggregate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@

import pytest
import xtgeo

from xtgeoapp_grd3dmaps.aggregate import grid3d_aggregate_map


def _copy2docs(file):
root = Path(__file__).absolute().parent.parent.parent
dst = root / "docs" / "test_to_docs"
shutil.copy2(file, dst)


def test_aggregated_map1_add2docs(datatree):
def test_aggregated_map1(datatree):
result = datatree / "aggregate1_folder"
result.mkdir(parents=True)
cfg = "tests/yaml/aggregate1.yml"

grid3d_aggregate_map.main(
[
"--config",
Expand All @@ -29,13 +23,13 @@ def test_aggregated_map1_add2docs(datatree):
)
swat = xtgeo.surface_from_file(result / "all--max_swat--20030101.gri")
assert swat.values.min() == pytest.approx(0.14292679727077484, abs=1e-8)
_copy2docs(cfg)


def test_aggregated_map2_add2docs(datatree):
def test_aggregated_map2(datatree):
result = datatree / "aggregate2_folder"
result.mkdir(parents=True)
cfg = "tests/yaml/aggregate2.yml"

grid3d_aggregate_map.main(
[
"--config",
Expand All @@ -48,13 +42,13 @@ def test_aggregated_map2_add2docs(datatree):
)
swat = xtgeo.surface_from_file(result / "all--min_swat--20030101.gri")
assert swat.values.mean() == pytest.approx(0.7908786104444353, abs=1e-8)
_copy2docs(cfg)


def test_aggregated_map3_add2docs(datatree):
def test_aggregated_map3(datatree):
result = datatree / "aggregate3_folder"
result.mkdir(parents=True)
cfg = "tests/yaml/aggregate3.yml"

grid3d_aggregate_map.main(
[
"--config",
Expand All @@ -67,13 +61,13 @@ def test_aggregated_map3_add2docs(datatree):
)
poro = xtgeo.surface_from_file(result / "all--mean_poro.gri")
assert poro.values.mean() == pytest.approx(0.1677586422488292, abs=1e-8)
_copy2docs(cfg)


def test_aggregated_map4_add2docs(datatree):
def test_aggregated_map4(datatree):
result = datatree / "aggregate4_folder"
result.mkdir(parents=True)
yml = "tests/yaml/aggregate4.yml"

grid3d_aggregate_map.main(
[
"--config",
Expand All @@ -89,13 +83,13 @@ def test_aggregated_map4_add2docs(datatree):
assert (result / "all--max_swat--20030101.gri").is_file()
assert (result / "zone2--max_swat--20030101.gri").is_file()
assert (result / "zone3--max_swat--20030101.gri").is_file()
_copy2docs(yml)


def test_aggregated_map5_add2docs(datatree):
def test_aggregated_map5(datatree):
result = datatree / "aggregate5_folder"
result.mkdir(parents=True)
cfg = "tests/yaml/aggregate5.yml"

grid3d_aggregate_map.main(
[
"--config",
Expand All @@ -108,13 +102,13 @@ def test_aggregated_map5_add2docs(datatree):
)
poro = xtgeo.surface_from_file(result / "all--mean_poro.gri")
assert poro.values.mean() == pytest.approx(0.1648792893163274, abs=1e-8)
_copy2docs(cfg)


def test_aggregated_map6_add2docs(datatree):
def test_aggregated_map6(datatree):
result = datatree / "aggregate6_folder"
result.mkdir(parents=True)
cfg = "tests/yaml/aggregate6.yml"

grid3d_aggregate_map.main(
[
"--config",
Expand All @@ -126,14 +120,15 @@ def test_aggregated_map6_add2docs(datatree):
]
)
gri_files = [p.stem for p in Path(result).glob("*.gri")]
assert sorted(gri_files) == sorted([
"all--max_swat--19991201",
"all--max_swat--20030101",
"firstzone--max_swat--19991201",
"firstzone--max_swat--20030101",
"secondzone--max_swat--19991201",
"secondzone--max_swat--20030101",
"thirdzone--max_swat--19991201",
"thirdzone--max_swat--20030101",
])
_copy2docs(cfg)
assert sorted(gri_files) == sorted(
[
"all--max_swat--19991201",
"all--max_swat--20030101",
"firstzone--max_swat--19991201",
"firstzone--max_swat--20030101",
"secondzone--max_swat--19991201",
"secondzone--max_swat--20030101",
"thirdzone--max_swat--19991201",
"thirdzone--max_swat--20030101",
]
)
36 changes: 25 additions & 11 deletions tests/test_scripts/test_grid3d_average_map_dataio1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,29 @@
SOURCEPATH = Path(__file__).absolute().parent.parent.parent


def test_average_map_dataio1a_legacy(datatree):
@pytest.fixture(name="avgdataio1aconfig", scope="module")
def fixture_avgdataio1aconfig(datatree):
"""Fixture to make config."""
name = "avgdataio1a.yml"
cfg = datatree / name

content = YAMLCONTENT.replace("MODE", "fmu-dataio")

cfg.write_text(content)

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")

return name


def test_avgmap_dataio1a_add2docs(avgdataio1aconfig):
"""For using pytest -k add2docs to be ran prior to docs building."""
print("Export config to docs folder")
assert avgdataio1aconfig is not None


def test_average_map_1a_legacy(datatree):
"""Test AVG with YAML config example 3a as legacy example"""

tmp = datatree / "tmp_legacy"
Expand All @@ -92,19 +114,14 @@ def test_average_map_dataio1a_legacy(datatree):
assert out.is_file()


def test_average_map_dataio1a_add2docs(datatree):
def test_average_map_dataio1a(datatree, avgdataio1aconfig):
"""Test AVG with YAML config example 3a piped through dataio"""

content = YAMLCONTENT.replace("MODE", "fmu-dataio")

cfg = datatree / "avgdataio1a.yml"
cfg.write_text(content)

os.environ["FMU_GLOBAL_CONFIG"] = str(
datatree / "tests" / "data" / "reek" / "global_variables.yml"
)
grid3d_average_map.main(
["--config", "avgdataio1a.yml", "--dump", "dump_config.yml"]
["--config", avgdataio1aconfig, "--dump", "dump_config.yml"]
)

# read result file
Expand Down Expand Up @@ -135,6 +152,3 @@ def test_average_map_dataio1a_add2docs(datatree):
if legacy.is_file():
surf2 = xtgeo.surface_from_file(legacy)
assert surf2.generate_hash() == surf.generate_hash()

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
28 changes: 21 additions & 7 deletions tests/test_scripts/test_grid3d_hc_thickness_dataio1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,33 @@
SOURCEPATH = Path(__file__).absolute().parent.parent.parent


def test_hc_thickness_1a_add2docs(datatree):
"""Test HC thickness map piped through dataio"""
cfg = datatree / "hcdataio1a.yml"
@pytest.fixture(name="hcdataio1aconfig", scope="module")
def fixture_hcdataio1a(datatree):
"""Fixture to make config."""
name = "hcdataio1a.yml"
cfg = datatree / name

cfg.write_text(YAMLCONTENT)

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
return name


def test_hc_thickness_1a_add2docs(hcdataio1aconfig):
"""For using pytest -k add2docs to be ran prior to docs building."""
print("Export config to docs folder")
assert hcdataio1aconfig is not None


def test_hc_thickness_1a(datatree, hcdataio1aconfig):
"""Test HC thickness map piped through dataio"""

os.environ["FMU_GLOBAL_CONFIG"] = str(
datatree / "tests" / "data" / "reek" / "global_variables.yml"
)
grid3d_hc_thickness.main(
["--config", "hcdataio1a.yml", "--dump", "dump_config.yml"]
["--config", hcdataio1aconfig, "--dump", "dump_config.yml"]
)

# read result file
Expand All @@ -75,6 +92,3 @@ def test_hc_thickness_1a_add2docs(datatree):

assert metadata["data"]["spec"]["ncol"] == 146
assert metadata["data"]["property"]["attribute"] == "oilthickness"

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
27 changes: 20 additions & 7 deletions tests/test_scripts/test_grid3d_hc_thickness_dataio1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,33 @@
SOURCEPATH = Path(__file__).absolute().parent.parent.parent


def test_hc_thickness_1b_add2docs(datatree):
"""Test HC thickness map piped through dataio, using 'both' mode"""
@pytest.fixture(name="hcdataio1bconfig", scope="module")
def fixture_hcdataio1b(datatree):
"""Fixture to make config."""
name = "hcdataio1b.yml"
cfg = datatree / name

cfg = datatree / "hcdataio1b.yml"
cfg.write_text(YAMLCONTENT)

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
return name


def test_hc_thickness_1b_add2docs(hcdataio1bconfig):
"""For using pytest -k add2docs to be ran prior to docs building."""
print("Export config to docs folder")
assert hcdataio1bconfig is not None


def test_hc_thickness_1b(datatree, hcdataio1bconfig):
"""Test HC thickness map piped through dataio, using 'both' mode"""

os.environ["FMU_GLOBAL_CONFIG"] = str(
datatree / "tests" / "data" / "reek" / "global_variables.yml"
)
grid3d_hc_thickness.main(
["--config", "hcdataio1b.yml", "--dump", "dump_config.yml"]
["--config", hcdataio1bconfig, "--dump", "dump_config.yml"]
)

# read result file
Expand All @@ -76,6 +92,3 @@ def test_hc_thickness_1b_add2docs(datatree):
assert metadata["data"]["spec"]["ncol"] == 161
assert metadata["data"]["content"] == "property"
assert metadata["data"]["property"]["attribute"] == "oilthickness"

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
27 changes: 20 additions & 7 deletions tests/test_scripts/test_grid3d_hc_thickness_dataio1c.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,33 @@
SOURCEPATH = Path(__file__).absolute().parent.parent.parent


def test_hc_thickness_1c_add2docs(datatree):
"""Test HC thickness map piped through dataio, see former yaml hc_thickness2a."""
@pytest.fixture(name="hcdataio1cconfig", scope="module")
def fixture_hcdataio1c(datatree):
"""Fixture to make config."""
name = "hcdataio1c.yml"
cfg = datatree / name

cfg = datatree / "hcdataio1c.yml"
cfg.write_text(YAMLCONTENT)

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
return name


def test_hc_thickness_1c_add2docs(hcdataio1cconfig):
"""For using pytest -k add2docs to be ran prior to docs building."""
print("Export config to docs folder")
assert hcdataio1cconfig is not None


def test_hc_thickness_1c(datatree, hcdataio1cconfig):
"""Test HC thickness map piped through dataio, see former yaml hc_thickness2a."""

os.environ["FMU_GLOBAL_CONFIG"] = str(
datatree / "tests" / "data" / "reek" / "global_variables.yml"
)
grid3d_hc_thickness.main(
["--config", "hcdataio1c.yml", "--dump", "dump_config.yml"]
["--config", hcdataio1cconfig, "--dump", "dump_config.yml"]
)

# read result file
Expand All @@ -74,6 +90,3 @@ def test_hc_thickness_1c_add2docs(datatree):

assert metadata["data"]["spec"]["ncol"] == 292
assert metadata["data"]["time"]["t0"]["value"] == "1990-01-01T00:00:00"

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")

0 comments on commit 5afcc96

Please sign in to comment.