From 58961a630c876b663ff47c0000d8b92051b15165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Werthm=C3=BCller?= Date: Fri, 4 Dec 2020 10:43:26 +0100 Subject: [PATCH] Make tests work locally (#154) Improve changelog. --- CHANGELOG.rst | 17 +++++++++-------- tests/test_cli.py | 31 +++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 47122852..4745d1ca 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,9 +13,15 @@ recent versions The package discretize went through a major restructuring with many name -changes and consequent deprecations. This version updates ``emg3d`` to be -compatible with ``discretize>=0.6.0`` in the long run. It also means that emg3d -will, from ``emg3d>=0.15.0`` onwards, only work with ``discretize>=0.6.0``. +changes and consequent deprecations (see below for a list of affected +mesh-properties for ``emg3d``). This version updates ``emg3d`` to be compatible +with ``discretize>=0.6.0`` in the long run. It also means that emg3d will, from +``emg3d>=0.15.0`` onwards, only work with ``discretize>=0.6.0``. + +Other notable changes: + +- Bug fix re storing/loading synthetics +- Moved from Travis CI to GitHub Actions. The relevant aliases and deprecations for ``emg3d`` are (consult the release notes of ``discretize`` for all changes): @@ -57,11 +63,6 @@ names (right). - ``vectorCCz`` => ``cell_centers_z`` - ``vol`` => ``cell_volumes`` -- Other changes: - - - Bug fix re storing/loading synthetics - - Moved from Travis CI to GitHub Actions. - *v0.14.3* : Bug fix ------------------- diff --git a/tests/test_cli.py b/tests/test_cli.py index 9712e49b..1b3524d6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,6 +2,7 @@ import pytest import numpy as np from numpy.testing import assert_allclose +from contextlib import suppress, ContextDecorator import emg3d from emg3d import cli @@ -23,11 +24,24 @@ pass +class disable_numba(ContextDecorator): + """Context decorator to disable-enable JIT and remove log file.""" + def __enter__(self): + os.environ["NUMBA_DISABLE_JIT"] = "1" + return self + + def __exit__(self, *exc): + os.environ["NUMBA_DISABLE_JIT"] = "0" + # Clean up + with suppress(FileNotFoundError): + os.remove('emg3d_out.log') + return False + + +@disable_numba() @pytest.mark.script_launch_mode('subprocess') def test_basic(script_runner): - os.environ["NUMBA_DISABLE_JIT"] = "1" - # Test the installed version runs by -h. ret = script_runner.run('emg3d', '-h') assert ret.success @@ -46,29 +60,26 @@ def test_basic(script_runner): ret = script_runner.run('python', 'emg3d', '--report') assert ret.success # Exclude time to avoid errors. - assert emg3d.utils.Report().__repr__()[115:] in ret.stdout + # Exclude empymod-version (after 475), because if run locally without + # having emg3d installed it will be "unknown" for the __main__ one. + assert emg3d.utils.Report().__repr__()[115:475] in ret.stdout # Test emg3d/cli/_main_.py by calling the file - I. ret = script_runner.run('python', 'emg3d/cli/main.py', '--version') assert ret.success - assert emg3d.utils.__version__ in ret.stdout + assert "emg3d v" in ret.stdout # Test emg3d/cli/_main_.py by calling the file - II. ret = script_runner.run('python', 'emg3d/cli/main.py', '--report') assert ret.success # Exclude time to avoid errors. - assert emg3d.utils.Report().__repr__()[115:] in ret.stdout + assert emg3d.utils.Report().__repr__()[115:475] in ret.stdout # Test emg3d/cli/_main_.py by calling the file - III. ret = script_runner.run('python', 'emg3d/cli/main.py', '-d') assert not ret.success assert "CONFIGURATION FILE NOT FOUND" in ret.stderr - os.environ["NUMBA_DISABLE_JIT"] = "0" - - # Clean up - os.remove('emg3d_out.log') - class TestParser: