-
Notifications
You must be signed in to change notification settings - Fork 229
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
arch: Ensure compiler check catches permission errors #2340
arch: Ensure compiler check catches permission errors #2340
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!.
You can the test locally to make sure it does what you want with
py.test -vsx tests/test_error_checking.py -k test_sniff_compiler_version
(-vsx
is just for verbosity)
tests/test_error_checking.py
Outdated
]) | ||
def test_sniff_compiler_version(cc): | ||
with pytest.raises(SystemExit) as e: | ||
sniff_compiler_version(cc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to be
with pytest.raises(SystemExit) as e:
sniff_compiler_version(cc)
assert e == SystemExit
so there is a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could add assert e.type == SystemExit
, but pytest.raises(SystemExit)
catches only a SystemExit exception, there's no point. If it's not a SystemExit exception, it won't get caught.
For an example, consider the test.py
below, where non-SystemExit exceptions simply cause the test to fail.
import pytest
import sys
def test_succeeds():
with pytest.raises(SystemExit) as e:
sys.exit(1)
assert e.type == SystemExit
def test_fails():
with pytest.raises(SystemExit) as e:
raise NotImplementedError
def test_succeeds_again():
with pytest.raises(NotImplementedError) as e:
raise NotImplementedError
$ python -m pytest test.py
================================== test session starts ===================================
platform linux -- Python 3.9.15, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/gbruer/a
plugins: anyio-3.5.0
collected 3 items
test.py .F. [100%]
======================================== FAILURES ========================================
_______________________________________ test_fails _______________________________________
def test_fails():
with pytest.raises(SystemExit) as e:
> raise NotImplementedError
E NotImplementedError
test.py:12: NotImplementedError
================================ short test summary info =================================
FAILED test.py::test_fails - NotImplementedError
============================== 1 failed, 2 passed in 0.08s ===============================
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: this test should be moved to some other files as this one, test_error_checking
, is supposed to be for runtime (C-level) numerical and computational errors.
Perhaps test_environment
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys.exit(...)
is also quite brutal, perhaps we turn it into a RuntimeError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_environment.py
seems to be making sure the test environment is usable, so this test doesn't fit there in my opinion. This test is independent of the test environment. Should there be a second test file for non-numerical runtime errors?
I agree that RuntimeError is better. I'll make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a second test file for non-numerical runtime errors?
perhaps test_arch.py
where in the future we can also add all other /devito/arch
related tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the test to test_arch.py
and fixed the pep8 errors, so as far as I know, this is ready to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is benchmark setup that needs fixing and rebase, I'll do it and get it merged
I tested locally and it's fine. The issue is I'm not sure how I should consistently trigger the I could make a file without execute permissions and delete it afterwards. I'm not sure if that will be portable for the OS's that Devito supports, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Not sure where else to put that test though but not critical IMO
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2340 +/- ##
===========================================
- Coverage 86.72% 66.18% -20.54%
===========================================
Files 232 184 -48
Lines 43641 28818 -14823
Branches 8075 6381 -1694
===========================================
- Hits 37848 19074 -18774
- Misses 5084 8891 +3807
- Partials 709 853 +144 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just ened to find a better place for the test, test_error_checking
is meant for something else, and perhaps we should rename it
tests/test_error_checking.py
Outdated
]) | ||
def test_sniff_compiler_version(cc): | ||
with pytest.raises(SystemExit) as e: | ||
sniff_compiler_version(cc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a second test file for non-numerical runtime errors?
perhaps test_arch.py
where in the future we can also add all other /devito/arch
related tests?
there are a few pep8 issues to be resolved: https://github.com/devitocodes/devito/actions/runs/8525302940/job/23365391849?pr=2340 |
418cc24
to
695c437
Compare
Fixed compiler version sniff and test Added more information for failed MPI import Carry mpi4py import error in dummy MPI class Raised RuntimeError for missing compiler instead of sys.exit() Fixed flake8 errors Moved test to test_arch.py
695c437
to
a1dabe9
Compare
I added a test for #2336, but I'm not sure if it will actually error on the bug I was encountering, so I'd like to run the standard test suite to make sure.
Closes #2336