Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests locally? #82

Closed
gassmoeller opened this issue Nov 14, 2024 · 4 comments
Closed

Running tests locally? #82

gassmoeller opened this issue Nov 14, 2024 · 4 comments

Comments

@gassmoeller
Copy link
Contributor

I wanted to ask if it is expected to be able to run the tests locally? I tried to reproduce the test pipeline defined in .github/workflows/CI.yml locally to see if I can reproduce the tests, however I failed with two independent approaches:

  1. I tried to run the tests with my local installation (as described in Deprecation warnings when running the hello world example #80), but failed.

Log of output and error when running pytest --cov=pyopmspe11 --cov-report term-missing tests/ > log 2>&1: log.txt.

I think the crucial lines of the log are:

The Python package opm was not found, using resdata
The opm Python package was not found, using resdata
The deck files have been written to /home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/tests/configs/spe11a/deck.
python3 /home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/visualization/data.py -p spe11a -d spe11a -g all -r 280,1,120 -t 1 -w 0.16666666666666666 -u opm
----------------------------- Captured stderr call -----------------------------
Traceback (most recent call last):
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/visualization/data.py", line 1571, in <module>
    main()
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/visualization/data.py", line 121, in main
    read_opm(dig)
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/visualization/data.py", line 232, in read_opm
    dig["unrst"] = OpmRestart(f"{dig['sim']}.UNRST")
                   ^^^^^^^^^^
NameError: name 'OpmRestart' is not defined
Traceback (most recent call last):
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/bin/pyopmspe11", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/core/pyopmspe11.py", line 162, in main
    pyopmspe11()
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/core/pyopmspe11.py", line 77, in pyopmspe11
    data(dic)
  File "/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/utils/runs.py", line 86, in data
    prosc = subprocess.run(data_exe, check=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['python3', '/home/rene/work/reviews/2024-joss-pyopmspe11/pyopmspe11/vpyopmspe11/lib/python3.12/site-packages/pyopmspe11/visualization/data.py', '-p spe11a', '-d spe11a', '-g all', '-r 280,1,120', '-t 1', '-w 0.16666666666666666', '-u opm']' returned non-zero exit status 1.

This then also breaks all other tests because the python environment changes the working directory in the first test and doesnt change it back if the first test crashes (independent issue: it would be good to find a way to make the tests independent of each other, so you get a realistic picture of which tests fail, not just 'this test and maybe some of the others that fail because of the first one failing').

Since the message suggest I may have a problem with the installation of my opm package I tried to reproduce the CI workflow more closely and created a docker container with Ubuntu Jammy (the one used in the github action), then following verbatim all the steps in .github/workflows/CI.yml. I had to install some additional packages like pip and git, which is expected, because the github image already has some packages preinstalled. But I was also finally unsuccessful. The full log when I run pytest --cov=pyopmspe11 --cov-report term-missing tests/: log2.txt.

I think the crucial lines here are:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/visualization/data.py", line 1571, in <module>
    main()
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/visualization/data.py", line 154, in main
    dense_data(dig)
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/visualization/data.py", line 894, in dense_data
    get_corners(dig, dil)
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/visualization/data.py", line 856, in get_corners
    dil["simxcent"][j] = float(row[0])
ValueError: could not convert string to float: 'np.float64(0.049999999999999996)'
Traceback (most recent call last):
  File "/usr/local/bin/pyopmspe11", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/core/pyopmspe11.py", line 162, in main
    pyopmspe11()
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/core/pyopmspe11.py", line 77, in pyopmspe11
    data(dic)
  File "/usr/local/lib/python3.10/dist-packages/pyopmspe11/utils/runs.py", line 86, in data
    prosc = subprocess.run(data_exe, check=True)
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['python3', '/usr/local/lib/python3.10/dist-packages/pyopmspe11/visualization/data.py', '-p spe11a', '-d spe11a', '-g all', '-r 280,1,120', '-t 1', '-w 0.16666666666666666', '-u opm']' returned non-zero exit status 1.

This looks as if the test is trying to do the following in data.py: float(row[0]) with row[0] = "np.float64(0.049999999999999996)". I am not sure how this happens if the main workflow for the repository works correctly (e.g. here https://github.com/OPM/pyopmspe11/actions/runs/11122281215/job/30903209334).

It would be nice to be able to run the tests locally to make sure the installation works correctly. Is this a problem with my installation or is there something else that prevents the tests from working correctly in local installations?

Related to openjournals/joss-reviews#7357

@MatthewFlamm
Copy link

I ran into the first error as well: NameError: name 'OpmRestart' is not defined

@daavid00
Copy link
Collaborator

daavid00 commented Dec 4, 2024

Thanks @gassmoeller and @MatthewFlamm for your feedback, this PR #96 makes possible to run independently the tests, and in #99 details on how to install the requirements to run the tests is added.

@daavid00
Copy link
Collaborator

daavid00 commented Dec 4, 2024

This looks as if the test is trying to do the following in data.py: float(row[0]) with row[0] = "np.float64(0.049999999999999996)". I am not sure how this happens if the main workflow for the repository works correctly

Actually I also ran into this when I used Python3.12 in Ubuntu (I am a macOS user and this issue does not show up in Python3.12, and the CI used to run with Python3.8 in Ubuntu). Thanks for spotting this, and the fix has been merged also in #102, by changing from:
str([dic["xyz"][0], dic["ymy_center"][0], dic["xyz"][2]])[1:-1]
to
f"{dic['xyz'][0]}, {dic['ymy_center'][0]}, {dic['xyz'][2]}"

@gassmoeller
Copy link
Contributor Author

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants