Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_pycopm_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- name: Run tests
run: |
pytest --cov=pycopm --exitfirst --cov-report term-missing tests/
pytest --cov=pycopm --exitfirst --cov-report term-missing --basetemp=test_outputs tests/

- name: Run hello world example
run: |
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ cython_debug/
# macOS
.DS_Store

# Tests
/tests/output

# Python environment
vpycopm/

Expand All @@ -183,7 +180,7 @@ opm-simulators/
cssr/
developing/
examples/configurations/drogon/drogon_coarser
output/
test_outputs/
playground/
presentation/
prototyping/
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Contributions are more than welcome using the fork and pull request approach
1. **black --target-version py312 src/ tests/** (this formats the code)
1. **pylint src/ tests/** (this analyses the code, and might rise issues that need to be fixed before the pull request)
1. **mypy --ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
1. **pytest --cov=pycopm --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
1. **pytest --cov=pycopm --cov-report term-missing --basetemp=test_outputs tests/ -n auto** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
1. **pycopm -i examples/decks/HELLO_WORLD.DATA -c 5,5,1 -m all -o output** (this runs the hello world example, which succeeds if the file output/HELLO_WORLD_PYCOPM.EGRID is created)
1. **pushd docs & make html** (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then copy all content from the docs/_build/html/ folder and replace the files in the [_docs_](https://github.com/cssr-tools/pycopm/tree/main/docs) folder)
* Tip for Linux users: See the [_ci_pycopm_ubuntu.yml_](https://github.com/cssr-tools/pycopm/blob/main/.github/workflows/ci_pycopm_ubuntu.yml) script and the [_Actions_](https://github.com/cssr-tools/pycopm/actions) for installation of pycopm, OPM Flow (binary packages), and dependencies, as well as the execution of the seven previous steps in Ubuntu 24.04 using Python 3.12.
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ numpydoc<=1.9.0
mypy<=1.18.2
pylint<=4.0.0
pytest-cov<=7.0.0
pytest-xdist<=3.8.0
sphinx<=8.2.3
sphinx-rtd-theme<=3.0.2
2 changes: 1 addition & 1 deletion docs/_sources/contributing.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Contribute to the software
#. **black --target-version py312 src/ tests/** (this formats the code)
#. **pylint src/ tests/** (this analyses the code, and might rise issues that need to be fixed before the pull request)
#. **mypy --ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
#. **pytest --cov=pycopm --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
#. **pytest --cov=pycopm --cov-report term-missing --basetemp=test_outputs tests/ -n auto** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
#. **pycopm -i examples/decks/HELLO_WORLD.DATA -c 5,5,1 -m all -o output** (this runs the hello world example, which succeeds if the file output/HELLO_WORLD_PYCOPM.EGRID is created)
#. **pushd docs & make html** (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then copy all content from the docs/_build/html/ folder and replace the files in the `docs <https://github.com/cssr-tools/pycopm/tree/main/docs>`_ folder)

Expand Down
8 changes: 4 additions & 4 deletions docs/contributing.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,18 @@ <h2>Contribute to the software<a class="headerlink" href="#contribute-to-the-sof
<blockquote>
<div><ol class="arabic simple">
<li><p><strong>pip install -r dev-requirements.txt</strong> (this installs the <a class="reference external" href="https://github.com/cssr-tools/pycopm/blob/main/dev-requirements.txt">dev-requirements.txt</a>)</p></li>
<li><p><strong>black target-version py312 src/ tests/</strong> (this formats the code)</p></li>
<li><p><strong>black --target-version py312 src/ tests/</strong> (this formats the code)</p></li>
<li><p><strong>pylint src/ tests/</strong> (this analyses the code, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>mypy ignore-missing-imports src/ tests/</strong> (this is a static checker, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>pytest cov=pycopm cov-report term-missing tests/</strong> (this runs locally the tests, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>mypy --ignore-missing-imports src/ tests/</strong> (this is a static checker, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>pytest --cov=pycopm --cov-report term-missing --basetemp=test_outputs tests/ -n auto</strong> (this runs locally the tests, and might rise issues that need to be fixed before the pull request)</p></li>
<li><p><strong>pycopm -i examples/decks/HELLO_WORLD.DATA -c 5,5,1 -m all -o output</strong> (this runs the hello world example, which succeeds if the file output/HELLO_WORLD_PYCOPM.EGRID is created)</p></li>
<li><p><strong>pushd docs &amp; make html</strong> (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then copy all content from the docs/_build/html/ folder and replace the files in the <a class="reference external" href="https://github.com/cssr-tools/pycopm/tree/main/docs">docs</a> folder)</p></li>
</ol>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>See the <a class="reference external" href="https://github.com/cssr-tools/pycopm/blob/main/.github/workflows/ci_pycopm_ubuntu.yml">ci_pycopm_ubuntu.yml</a> script and the <a class="reference external" href="https://github.com/cssr-tools/pycopm/actions">Actions</a> for installation of pycopm, OPM Flow (binary packages), and dependencies, as well as the execution of the seven previous steps in Ubuntu 24.04 using Python 3.12.
For macOS users, see the <a class="reference external" href="https://github.com/daavid00/OPM-Flow_macOS/blob/main/.github/workflows/ci_pycopm_macos.yml">ci_pycopm_macos.yml</a> script and the <a class="reference external" href="https://github.com/cssr-tools/pycopm/actions">OPM-Flow_macOS Actions</a> for installation of pycopm, OPM Flow (source build), and dependencies, as well as running the tests and the hello world example in macOS 26 using Python3.14.
Note that if you do not add the directory containing the OPM Flow executable to your system’s PATH environment variable (e.g., export PATH=$PATH:/Users/yourname/pycopm/build/opm-simulators/bin), then you can pass this in the execution of the tests and pycopm using the flags <strong>-f/flow</strong> (see <a class="reference external" href="https://github.com/daavid00/OPM-Flow_macOS/blob/main/.github/workflows/ci_pycopm_macos.yml#L72">this script</a>).</p>
Note that if you do not add the directory containing the OPM Flow executable to your system’s PATH environment variable (e.g., export PATH=$PATH:/Users/yourname/pycopm/build/opm-simulators/bin), then you can pass this in the execution of the tests and pycopm using the flags <strong>-f/--flow</strong> (see <a class="reference external" href="https://github.com/daavid00/OPM-Flow_macOS/blob/main/.github/workflows/ci_pycopm_macos.yml#L72">this script</a>).</p>
</div>
</div></blockquote>
</li>
Expand Down
8 changes: 4 additions & 4 deletions docs/text/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ Contribute to the software
#. In the main repo execute:

#. **pip install -r dev-requirements.txt** (this installs the `dev-requirements.txt <https://github.com/cssr-tools/pycopm/blob/main/dev-requirements.txt>`_)
#. **black --target-version py312 src/ tests/** (this formats the code)
#. **black \-\-target-version py312 src/ tests/** (this formats the code)
#. **pylint src/ tests/** (this analyses the code, and might rise issues that need to be fixed before the pull request)
#. **mypy --ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
#. **pytest --cov=pycopm --cov-report term-missing tests/** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
#. **mypy \-\-ignore-missing-imports src/ tests/** (this is a static checker, and might rise issues that need to be fixed before the pull request)
#. **pytest \-\-cov=pycopm \-\-cov-report term-missing \-\-basetemp=test_outputs tests/ -n auto** (this runs locally the tests, and might rise issues that need to be fixed before the pull request)
#. **pycopm -i examples/decks/HELLO_WORLD.DATA -c 5,5,1 -m all -o output** (this runs the hello world example, which succeeds if the file output/HELLO_WORLD_PYCOPM.EGRID is created)
#. **pushd docs & make html** (this generates the documentation, and might rise issues that need to be fixed before the pull request; if the build succeeds and if the contribution changes the documentation, then copy all content from the docs/_build/html/ folder and replace the files in the `docs <https://github.com/cssr-tools/pycopm/tree/main/docs>`_ folder)

.. tip::
See the `ci_pycopm_ubuntu.yml <https://github.com/cssr-tools/pycopm/blob/main/.github/workflows/ci_pycopm_ubuntu.yml>`_ script and the `Actions <https://github.com/cssr-tools/pycopm/actions>`_ for installation of pycopm, OPM Flow (binary packages), and dependencies, as well as the execution of the seven previous steps in Ubuntu 24.04 using Python 3.12.
For macOS users, see the `ci_pycopm_macos.yml <https://github.com/daavid00/OPM-Flow_macOS/blob/main/.github/workflows/ci_pycopm_macos.yml>`_ script and the `OPM-Flow_macOS Actions <https://github.com/cssr-tools/pycopm/actions>`_ for installation of pycopm, OPM Flow (source build), and dependencies, as well as running the tests and the hello world example in macOS 26 using Python3.14.
Note that if you do not add the directory containing the OPM Flow executable to your system's PATH environment variable (e.g., export PATH=$PATH:/Users/yourname/pycopm/build/opm-simulators/bin), then you can pass this in the execution of the tests and pycopm using the flags **-f/--flow** (see `this script <https://github.com/daavid00/OPM-Flow_macOS/blob/main/.github/workflows/ci_pycopm_macos.yml#L72>`_).
Note that if you do not add the directory containing the OPM Flow executable to your system's PATH environment variable (e.g., export PATH=$PATH:/Users/yourname/pycopm/build/opm-simulators/bin), then you can pass this in the execution of the tests and pycopm using the flags **-f/\-\-flow** (see `this script <https://github.com/daavid00/OPM-Flow_macOS/blob/main/.github/workflows/ci_pycopm_macos.yml#L72>`_).

#. Squash your commits into a single commit (see this `nice tutorial <https://gist.github.com/lpranam/4ae996b0a4bc37448dc80356efbca7fa>`_ if you are not familiar with this)
#. Push your commit and make a pull request
Expand Down
33 changes: 13 additions & 20 deletions tests/test_0_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@

"""Test the configuration files"""

import os
import pathlib
from pycopm.core.pycopm import main
from pathlib import Path
import shutil

testpth: pathlib.Path = pathlib.Path(__file__).parent
mainpth: pathlib.Path = pathlib.Path(__file__).parents[1]
from pycopm.core.pycopm import main


def test_main():
def test_0_main(tmp_path, monkeypatch):
"""See examples/configurations/norne/input.toml"""
confi = f"{mainpth}/examples/configurations/norne/input.toml"
if not os.path.exists(f"{testpth}/output"):
os.system(f"mkdir {testpth}/output")
os.system(f"mkdir {testpth}/output/main")
os.system(f"cp {confi} {testpth}/output/main/input.toml")
elif not os.path.exists(f"{testpth}/output/main"):
os.system(f"mkdir {testpth}/output/main")
os.system(f"cp {confi} {testpth}/output/main/input.toml")
elif not os.path.isfile(f"{testpth}/output/main/input.toml"):
os.system(f"cp {confi} {testpth}/output/main/input.toml")
os.chdir(f"{testpth}/output/main")
monkeypatch.chdir(tmp_path)
repo_root = Path(__file__).parents[1]
input_config = repo_root / "examples" / "configurations" / "norne" / "input.toml"
shutil.copy(input_config, tmp_path / "input.toml")
monkeypatch.chdir(tmp_path)
main()
assert os.path.exists(
f"{testpth}/output/main/postprocessing/wells/HISTO_DATA_WWPR_E-1H.png"
)
assert (tmp_path / "postprocessing" / "errors.txt").is_file()
assert (
tmp_path / "postprocessing" / "wells" / "HISTO_DATA_WWPR_E-1H.png"
).is_file()
17 changes: 6 additions & 11 deletions tests/test_1_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@

"""Test the ert functionality via the configuration file"""

import os
import pathlib
from pathlib import Path
import subprocess

testpth: pathlib.Path = pathlib.Path(__file__).parent
mainpth: pathlib.Path = pathlib.Path(__file__).parents[1]


def test_ert(flow):
def test_1_ert(flow, tmp_path, monkeypatch):
"""See examples/configurations/drogon/input.toml"""
if not os.path.exists(f"{testpth}/output"):
os.system(f"mkdir {testpth}/output")
os.chdir(f"{testpth}/output")
confi = f"{mainpth}/examples/configurations/drogon/input.toml"
repo_root = Path(__file__).parents[1]
monkeypatch.chdir(tmp_path)
confi = f"{repo_root}/examples/configurations/drogon/input.toml"
subprocess.run(["pycopm", "-i", confi, "-o", "ert", "-f", flow], check=True)
assert os.path.exists(f"{testpth}/output/ert/postprocessing/hm_missmatch.png")
assert (tmp_path / "ert" / "postprocessing" / "hm_missmatch.png").is_file()
61 changes: 19 additions & 42 deletions tests/test_2_coarsening.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,33 @@
# SPDX-FileCopyrightText: 2024-2026 NORCE Research AS
# SPDX-License-Identifier: GPL-3.0
# pylint: disable=R0801

"""Test the generic coarsening functionality"""

import os
import pathlib
from pathlib import Path
import subprocess

testpth: pathlib.Path = pathlib.Path(__file__).parent
mainpth: pathlib.Path = pathlib.Path(__file__).parents[1]


def test_coarsening(flow):
def test_2_coarsening(flow, tmp_path, monkeypatch):
"""See examples/decks/HELLO_WORLD.DATA"""
if not os.path.exists(f"{testpth}/output"):
os.system(f"mkdir {testpth}/output")
repo_root = Path(__file__).parents[1]
monkeypatch.chdir(tmp_path)
sub = "FINER"
subprocess.run(
[
"pycopm",
"-f",
flow,
"-f",
flow,
"-c",
"5,5,1",
"-i",
f"{mainpth}/examples/decks/HELLO_WORLD.DATA",
"-o",
f"{testpth}/output/coarser",
f"{repo_root}/examples/decks/HELLO_WORLD.DATA",
"-m",
"prep",
],
check=True,
)
assert os.path.exists(
f"{testpth}/output/coarser/HELLO_WORLD_PREP_PYCOPM_DRYRUN.INIT"
)
assert os.path.exists(
f"{testpth}/output/coarser/HELLO_WORLD_PREP_PYCOPM_DRYRUN.EGRID"
)
assert (tmp_path / "HELLO_WORLD_PREP_PYCOPM_DRYRUN.INIT").is_file()
assert (tmp_path / "HELLO_WORLD_PREP_PYCOPM_DRYRUN.EGRID").is_file()
for ahow in ["max", "min", "mode"]:
for nhow in ["max", "min", "mode"]:
for show in ["max", "min", "mean", "pvmean"]:
Expand All @@ -50,9 +37,7 @@ def test_coarsening(flow):
"-f",
flow,
"-i",
f"{mainpth}/examples/decks/HELLO_WORLD.DATA",
"-o",
f"{testpth}/output/coarser",
f"{repo_root}/examples/decks/HELLO_WORLD.DATA",
"-c",
"5,5,1",
"-m",
Expand All @@ -66,19 +51,15 @@ def test_coarsening(flow):
],
check=True,
)
assert os.path.exists(
f"{testpth}/output/coarser/HELLO_WORLD_PYCOPM.DATA"
)
os.system(f"rm {testpth}/output/coarser/HELLO_WORLD_PYCOPM.DATA")
assert (tmp_path / "HELLO_WORLD_PYCOPM.DATA").is_file()
subprocess.run(["rm", "HELLO_WORLD_PYCOPM.DATA"], check=True)
subprocess.run(
[
"pycopm",
"-f",
flow,
"-i",
f"{mainpth}/examples/decks/HELLO_WORLD.DATA",
"-o",
f"{testpth}/output/coarser",
f"{repo_root}/examples/decks/HELLO_WORLD.DATA",
"-m",
"deck_dry",
"-p",
Expand All @@ -94,17 +75,15 @@ def test_coarsening(flow):
],
check=True,
)
assert os.path.exists(f"{testpth}/output/coarser/{sub}.INIT")
assert os.path.exists(f"{testpth}/output/coarser/{sub}.EGRID")
assert (tmp_path / f"{sub}.INIT").is_file()
assert (tmp_path / f"{sub}.EGRID").is_file()
subprocess.run(
[
"pycopm",
"-f",
flow,
"-i",
f"{mainpth}/examples/decks/HELLO_WORLD.DATA",
"-o",
f"{testpth}/output/coarser",
f"{repo_root}/examples/decks/HELLO_WORLD.DATA",
"-c",
"1,5,1",
"-m",
Expand All @@ -116,17 +95,15 @@ def test_coarsening(flow):
],
check=True,
)
assert os.path.exists(f"{testpth}/output/coarser/TRANS{sub}.INIT")
assert os.path.exists(f"{testpth}/output/coarser/TRANS{sub}.EGRID")
assert (tmp_path / f"TRANS{sub}.INIT").is_file()
assert (tmp_path / f"TRANS{sub}.EGRID").is_file()
subprocess.run(
[
"pycopm",
"-f",
flow,
"-i",
f"{mainpth}/examples/decks/HELLO_WORLD.DATA",
"-o",
f"{testpth}/output/coarser",
f"{repo_root}/examples/decks/HELLO_WORLD.DATA",
"-c",
"5,1,4",
"-m",
Expand All @@ -138,5 +115,5 @@ def test_coarsening(flow):
],
check=True,
)
assert os.path.exists(f"{testpth}/output/coarser/TRANS2{sub}.INIT")
assert os.path.exists(f"{testpth}/output/coarser/TRANS2{sub}.EGRID")
assert (tmp_path / f"TRANS2{sub}.INIT").is_file()
assert (tmp_path / f"TRANS2{sub}.EGRID").is_file()
24 changes: 8 additions & 16 deletions tests/test_3_refinement.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
# SPDX-FileCopyrightText: 2025-2026 NORCE Research AS
# SPDX-License-Identifier: GPL-3.0
# pylint: disable=R0801

"""Test the generic refinement functionality"""

import os
import pathlib
from pathlib import Path
import subprocess
import numpy as np
from opm.io.ecl import EclFile as OpmFile

mainpth: pathlib.Path = pathlib.Path(__file__).parents[1]
testpth: pathlib.Path = pathlib.Path(__file__).parent


def test_refinement(flow):
def test_3_refinement(flow, tmp_path, monkeypatch):
"""See examples/decks/MODEL2.DATA"""
if not os.path.exists(f"{testpth}/output"):
os.system(f"mkdir {testpth}/output")
monkeypatch.chdir(tmp_path)
repo_root = Path(__file__).parents[1]
sub = "FINER"
subprocess.run(
[
"pycopm",
"-i",
f"{repo_root}/examples/decks/MODEL2.DATA",
"-f",
flow,
"-i",
f"{mainpth}/examples/decks/MODEL2.DATA",
"-o",
f"{testpth}/output/finer",
"-g",
"2,4,8",
"-l",
Expand All @@ -39,9 +32,8 @@ def test_refinement(flow):
],
check=True,
)
assert os.path.exists(f"{testpth}/output/finer/{sub}.INIT")
assert os.path.exists(f"{testpth}/output/finer/{sub}.EGRID")
os.chdir(f"{testpth}/output/finer")
assert (tmp_path / f"{sub}.INIT").is_file()
assert (tmp_path / f"{sub}.EGRID").is_file()
porv = np.array(OpmFile(f"{sub}.INIT")["PORV"])
assert abs(np.sum(porv) - 6506.25) < 1e-4
assert np.sum(porv > 0) == 2430
Loading
Loading