From 9d16f9efb1200f164f4a6cb6bfb79cd2d3de93e8 Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Sat, 13 Mar 2021 14:29:23 -0500 Subject: [PATCH 1/4] Skip slow tests unless --run-slow is specified. `pytest --run-slow` OR `python3 setup.py test --args=--run-slow` --- docs/install.rst | 12 ++++++++++++ sbpy/activity/gas/tests/test_prodrate_remote.py | 1 + sbpy/conftest.py | 1 + 3 files changed, 14 insertions(+) diff --git a/docs/install.rst b/docs/install.rst index 6d8fc4d1..88477dfd 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -69,3 +69,15 @@ in order to use `sbpy` in your default Python environment. If you plan to work o .. code-block:: bash $ python setup.py develop --user + + +Running tests +^^^^^^^^^^^^^ + +To verify your installation is properly working, run `sbpy`'s testing suite: + +.. code-block:: bash + + $ python3 setpy.py test + +Add the `--remote-data` option to include tests that require a network connection, and `-args="--run-slow"` to include any slow tests. diff --git a/sbpy/activity/gas/tests/test_prodrate_remote.py b/sbpy/activity/gas/tests/test_prodrate_remote.py index 4f0c585e..2bdc1145 100644 --- a/sbpy/activity/gas/tests/test_prodrate_remote.py +++ b/sbpy/activity/gas/tests/test_prodrate_remote.py @@ -64,6 +64,7 @@ def data_path(filename): return os.path.join(data_dir, filename) +@pytest.mark.slow @remote_data def test_remote_prodrate_simple_hcn(): diff --git a/sbpy/conftest.py b/sbpy/conftest.py index c570fcc6..49434305 100644 --- a/sbpy/conftest.py +++ b/sbpy/conftest.py @@ -9,6 +9,7 @@ import os +import pytest from astropy.version import version as astropy_version # For Astropy 3.0 and later, we can use the standalone pytest plugin From f09e52941ad61cb5f0d802f14bc9da262d73f24d Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Sat, 5 Feb 2022 13:38:17 -0500 Subject: [PATCH 2/4] Register "slow" marker and mark slow tests. --- sbpy/activity/gas/tests/test_core.py | 26 +++++++++++-------- .../gas/tests/test_prodrate_remote.py | 6 ++--- sbpy/conftest.py | 4 +++ sbpy/data/tests/test_obs_remote.py | 1 + 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/sbpy/activity/gas/tests/test_core.py b/sbpy/activity/gas/tests/test_core.py index 8a6bdff7..1ae812e7 100644 --- a/sbpy/activity/gas/tests/test_core.py +++ b/sbpy/activity/gas/tests/test_core.py @@ -127,9 +127,11 @@ def test_column_density_small_angular_aperture(self): eph = dict(delta=1 * u.au) parent = 1e4 * u.km N_avg = 2 * Haser(Q, v, parent).column_density(rho, eph) - rho_km = (rho * eph['delta'] * 725.24 * u.km / u.arcsec / u.au).to('km') + rho_km = (rho * eph['delta'] * 725.24 * + u.km / u.arcsec / u.au).to('km') ideal = Q / v / 2 / rho_km - assert np.isclose(N_avg.to_value('1/m2'), ideal.to_value('1/m2'), rtol=0.001) + assert np.isclose(N_avg.to_value('1/m2'), + ideal.to_value('1/m2'), rtol=0.001) def test_column_density(self): """ @@ -412,12 +414,12 @@ def test_grid_count(self): 'tau_d': 101730 * u.s, 'v_outflow': 1 * u.km/u.s, 'sigma': 3e-16 * u.cm**2 - }) + }) # Fragment molecule is OH fragment = Phys.from_dict({ 'tau_T': photo_timescale('OH') * 0.93, 'v_photo': 1.05 * u.km/u.s - }) + }) coma = VectorialModel(base_q=base_q, parent=parent, @@ -441,21 +443,23 @@ def test_total_number_large_aperture(self): 'tau_d': 101730 * u.s, 'v_outflow': 1 * u.km/u.s, 'sigma': 3e-16 * u.cm**2 - }) + }) # Fragment molecule is OH fragment = Phys.from_dict({ 'tau_T': photo_timescale('OH') * 0.93, 'v_photo': 1.05 * u.km/u.s - }) + }) coma = VectorialModel(base_q=base_q, parent=parent, fragment=fragment) fragment_theory = coma.vmodel['num_fragments_theory'] - ap = core.CircularAperture((coma.vmodel['max_grid_radius'].value) * u.m) + ap = core.CircularAperture( + (coma.vmodel['max_grid_radius'].value) * u.m) assert np.isclose(fragment_theory, coma.total_number(ap), rtol=0.02) + @pytest.mark.slow def test_model_symmetry(self): """ The symmetry of the model allows the parent production to be @@ -486,12 +490,12 @@ def test_model_symmetry(self): 'tau_d': 101730 * u.s, 'v_outflow': 1 * u.km/u.s, 'sigma': 3e-16 * u.cm**2 - }) + }) # Fragment molecule is OH fragment = Phys.from_dict({ 'tau_T': photo_timescale('OH') * 0.93, 'v_photo': 1.05 * u.km/u.s - }) + }) coma = VectorialModel(base_q=base_production*(1/u.s), parent=parent, @@ -508,12 +512,12 @@ def test_model_symmetry(self): 'tau_d': 101730 * u.s, 'v_outflow': 1 * u.km/u.s, 'sigma': 3e-16 * u.cm**2 - }) + }) # Fragment molecule is OH fragment_check = Phys.from_dict({ 'tau_T': photo_timescale('OH') * 0.93, 'v_photo': 1.05 * u.km/u.s - }) + }) coma_check = VectorialModel(base_q=calculated_q*(1/u.s), parent=parent_check, fragment=fragment_check) diff --git a/sbpy/activity/gas/tests/test_prodrate_remote.py b/sbpy/activity/gas/tests/test_prodrate_remote.py index 2bdc1145..7401a8f8 100644 --- a/sbpy/activity/gas/tests/test_prodrate_remote.py +++ b/sbpy/activity/gas/tests/test_prodrate_remote.py @@ -152,9 +152,7 @@ def test_remote_prodrate_simple_ch3oh(): assert np.all(err < 0.35) -# Issue #296 -# MSK: disabling test as CO and HCN are no longer present in LAMDA database(?) -@pytest.mark.skip +@pytest.mark.slow @remote_data def test_einstein(): @@ -185,7 +183,7 @@ def test_einstein(): mol_name = mol['NAME'].data[0] - lam_search = Lamda.query(mol=mol_name.lower()) + lam_search = Lamda().query(mol=mol_name.lower()) lam_result = lam_search[1] diff --git a/sbpy/conftest.py b/sbpy/conftest.py index 49434305..a64eee81 100644 --- a/sbpy/conftest.py +++ b/sbpy/conftest.py @@ -49,6 +49,10 @@ def pytest_configure(config): packagename = os.path.basename(os.path.dirname(__file__)) TESTED_VERSIONS[packagename] = __version__ + config.addinivalue_line( + "markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')" + ) + # Uncomment the last two lines in this block to treat all DeprecationWarnings # as exceptions. For Astropy v2.0 or later, there are 2 additional keywords, # as follow (although default should work for most cases). diff --git a/sbpy/data/tests/test_obs_remote.py b/sbpy/data/tests/test_obs_remote.py index 50c35ab8..d0c8c0dc 100644 --- a/sbpy/data/tests/test_obs_remote.py +++ b/sbpy/data/tests/test_obs_remote.py @@ -14,6 +14,7 @@ @pytest.mark.remote_data class TestObsfromMPC: + @pytest.mark.slow def test_simple(self): # asteroid data = Obs.from_mpc('12893') From 78e486c4c7f52f594a6cfe282ab1e25b3e13bb4f Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Sat, 5 Feb 2022 13:38:44 -0500 Subject: [PATCH 3/4] Update installation notes. --- docs/install.rst | 74 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/docs/install.rst b/docs/install.rst index 88477dfd..7063334d 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -5,28 +5,34 @@ Installation Requirements ^^^^^^^^^^^^ -`sbpy` has the following requirements that will be automatically taken -care of with installation using pip: +`sbpy` has the following requirements that will be automatically taken care of +with installation using pip: * Python 3.6 or later * `numpy `__ 1.16.0 or later * pytest 3.1 or later * `astropy `__ -* `astroquery `__ 0.4.1.dev5892 or later: For retrieval of online data, e.g., ephemerides and orbits. -* `scipy `__: For numerical integrations in `sbpy.activity.gas` and `sbpy.photometry`, among others. -* `synphot `__ 0.1.3 or later: For calibration with respect to the Sun and Vega, filtering spectra through bandpasses. - -The following packages will have to be installed manually, if the user -wants to use them: - -* `oorb `__: For - orbit transformations (`~sbpy.data.Orbit.oo_transform`) and - propagations (`~sbpy.data.Orbit.oo_propagate`), as well as - ephemerides calculations (`~sbpy.data.Ephem.from_oo`). -* `pyradex `__: For non-LTE - production rate calculation related to cometary activity - (`~sbpy.activity.gas.NonLTE`). -* `ginga `__ and `photutils `__: To interactively enhance images of comets with the `~sbpy.imageanalysis.CometaryEnhancement` Ginga plugin. +* `astroquery `__ 0.4.1.dev5892 or + later: For retrieval of online data, e.g., ephemerides and orbits. +* `scipy `__: For numerical integrations in + `sbpy.activity.gas` and `sbpy.photometry`, among others. +* `synphot `__ 0.1.3 or + later: For calibration with respect to the Sun and Vega, filtering spectra + through bandpasses. + +The following packages will have to be installed manually, if the user wants to +use them: + +* `oorb `__: For orbit + transformations (`~sbpy.data.Orbit.oo_transform`) and propagations + (`~sbpy.data.Orbit.oo_propagate`), as well as ephemerides calculations + (`~sbpy.data.Ephem.from_oo`). +* `pyradex `__: For non-LTE production + rate calculation related to cometary activity (`~sbpy.activity.gas.NonLTE`). +* `ginga `__ and `photutils + `__: To interactively enhance + images of comets with the `~sbpy.imageanalysis.CometaryEnhancement` Ginga + plugin. Using pip @@ -49,9 +55,9 @@ The latest development version of `sbpy` can be easily installed using Using GitHub ^^^^^^^^^^^^ -This way of installing `sbpy` is recommended if you plan to contribute -to the module. The current development version of `sbpy` can be -obtained from `GitHub `__ using +This way of installing `sbpy` is recommended if you plan to contribute to the +module. The current development version of `sbpy` can be obtained from `GitHub +`__ using .. code-block:: bash @@ -63,7 +69,9 @@ This will create a new directory (``sbpy/``). In this directory, run $ python setup.py install --user -in order to use `sbpy` in your default Python environment. If you plan to work on the code and always want to use the latest version of your code, you can install it with +in order to use `sbpy` in your default Python environment. If you plan to work +on the code and always want to use the latest version of your code, you can +install it with .. code-block:: bash @@ -74,10 +82,28 @@ in order to use `sbpy` in your default Python environment. If you plan to work o Running tests ^^^^^^^^^^^^^ -To verify your installation is properly working, run `sbpy`'s testing suite: +To verify your installation is properly working, run `sbpy`'s testing suite. + +First, install the required testing packages by using the "test" option, e.g., +`sbpy[test]`: .. code-block:: bash - $ python3 setpy.py test + # for testing a stable package + $ pip install sbpy[test] + + # for testing a development packge from a GitHub + $ pip install sbpy[test]@git+https://github.com/NASA-Planetary-Science/sbpy.git + +Next, test with pytest: + +.. code-block:: bash + + $ pytest --pyargs sbpy + +Add the `--remote-data` option to aslo run tests that require a network +connection, and `-m "not slow"` to skip any tests marked as slow. -Add the `--remote-data` option to include tests that require a network connection, and `-args="--run-slow"` to include any slow tests. +It is recommended that developers use `tox` for testing in order to use +controlled environments. See the ``astropy` testing guidelines +`__ for more. \ No newline at end of file From 6450d5bd1dabae43a31faed54e780459f9cf73a7 Mon Sep 17 00:00:00 2001 From: "Michael S. P. Kelley" Date: Mon, 7 Feb 2022 09:17:03 -0500 Subject: [PATCH 4/4] PEP8 fix. --- sbpy/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sbpy/conftest.py b/sbpy/conftest.py index a64eee81..c2f4ceca 100644 --- a/sbpy/conftest.py +++ b/sbpy/conftest.py @@ -50,7 +50,8 @@ def pytest_configure(config): TESTED_VERSIONS[packagename] = __version__ config.addinivalue_line( - "markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')" + "markers", + "slow: marks tests as slow (deselect with '-m \"not slow\"')" ) # Uncomment the last two lines in this block to treat all DeprecationWarnings