From 5d5a9a652d523d019c4bd68093187dccd4badeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Cano=20Rodr=C3=ADguez?= Date: Sun, 18 Aug 2019 18:13:14 +0200 Subject: [PATCH] Fix MyPy errors in tests --- .circleci/config.yml | 2 +- docs/source/conf.py | 2 +- mypy.ini | 4 ++++ setup.cfg | 1 + src/poliastro/tests/test_jit.py | 3 ++- src/poliastro/tests/tests_twobody/test_orbit.py | 2 +- src/poliastro/tests/tests_twobody/test_perturbations.py | 8 +++++--- src/poliastro/tests/tests_twobody/test_propagation.py | 2 +- tox.ini | 2 +- 9 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 mypy.ini diff --git a/.circleci/config.yml b/.circleci/config.yml index c608a3cfb..8e10f5d72 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,7 +49,7 @@ jobs: name: run tests command: | . venv/bin/activate - MPLBACKEND=Agg pytest -m "not mpl_image_compare" --doctest-modules -vv # Test against installed code + MPLBACKEND=Agg pytest -m "not mpl_image_compare" --mypy --doctest-modules -vv # Test against installed code MPLBACKEND=Agg pytest -m "mpl_image_compare" --mpl test_py37: diff --git a/docs/source/conf.py b/docs/source/conf.py index ab9618c98..cea1f4adb 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -231,7 +231,7 @@ def setup(app): # -- Options for LaTeX output --------------------------------------------- -latex_elements = { +latex_elements = { # type: ignore # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000..a5cc256e5 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,4 @@ +[mypy] +ignore_missing_imports = True +check_untyped_defs = True +strict_optional = False diff --git a/setup.cfg b/setup.cfg index cce3c4f79..f50e2b631 100644 --- a/setup.cfg +++ b/setup.cfg @@ -82,6 +82,7 @@ dev = pytest>=3.2 pytest-cov<2.6.0 pytest-mpl + pytest-mypy sphinx sphinx_rtd_theme @ https://github.com/Juanlu001/sphinx_rtd_theme/archive/avoid-require-redefinition.zip sphinx-notfound-page diff --git a/src/poliastro/tests/test_jit.py b/src/poliastro/tests/test_jit.py index 6244200ae..4889ad049 100644 --- a/src/poliastro/tests/test_jit.py +++ b/src/poliastro/tests/test_jit.py @@ -1,4 +1,5 @@ from contextlib import contextmanager +from importlib.abc import MetaPathFinder from poliastro.core import _jit @@ -9,7 +10,7 @@ def _fake_numba_import(): # https://stackoverflow.com/a/2484402/554319 import sys - class FakeImportFailure: + class FakeImportFailure(MetaPathFinder): def __init__(self, modules): self.modules = modules diff --git a/src/poliastro/tests/tests_twobody/test_orbit.py b/src/poliastro/tests/tests_twobody/test_orbit.py index 3efe73690..2053c84d8 100755 --- a/src/poliastro/tests/tests_twobody/test_orbit.py +++ b/src/poliastro/tests/tests_twobody/test_orbit.py @@ -821,7 +821,7 @@ def test_arglat_within_range(): def test_pqw_returns_dimensionless(): - r_0 = ([1, 0, 0] * u.au).to(u.km) + r_0 = ([1, 0, 0] * u.au).to(u.km) # type: ignore v_0 = ([0, 6, 0] * u.au / u.year).to(u.km / u.day) ss = Orbit.from_vectors(Sun, r_0, v_0) diff --git a/src/poliastro/tests/tests_twobody/test_perturbations.py b/src/poliastro/tests/tests_twobody/test_perturbations.py index 01a26f7f0..5b7081684 100644 --- a/src/poliastro/tests/tests_twobody/test_perturbations.py +++ b/src/poliastro/tests/tests_twobody/test_perturbations.py @@ -46,8 +46,8 @@ def test_J2_propagation_Earth(): _, _, _, raan0, argp0, _ = rv2coe(k, r0, v0) _, _, _, raan, argp, _ = rv2coe(k, rr[0].to(u.km).value, vv[0].to(u.km / u.s).value) - raan_variation_rate = (raan - raan0) / tofs[0].to(u.s).value - argp_variation_rate = (argp - argp0) / tofs[0].to(u.s).value + raan_variation_rate = (raan - raan0) / tofs[0].to(u.s).value # type: ignore + argp_variation_rate = (argp - argp0) / tofs[0].to(u.s).value # type: ignore raan_variation_rate = (raan_variation_rate * u.rad / u.s).to(u.deg / u.h) argp_variation_rate = (argp_variation_rate * u.rad / u.s).to(u.deg / u.h) @@ -513,7 +513,9 @@ def test_solar_pressure(): # averaging over 5 last values in the way Curtis does for check in solar_pressure_checks: - index = int(1.0 * check["t_days"] / tof.to(u.day).value * 4000) + index = int( + 1.0 * check["t_days"] / tof.to(u.day).value * 4000 # type: ignore + ) delta_ecc, delta_inc, delta_raan, delta_argp = ( np.mean(delta_eccs[index - 5 : index]), np.mean(delta_incs[index - 5 : index]), diff --git a/src/poliastro/tests/tests_twobody/test_propagation.py b/src/poliastro/tests/tests_twobody/test_propagation.py index 43eebb225..d45631077 100644 --- a/src/poliastro/tests/tests_twobody/test_propagation.py +++ b/src/poliastro/tests/tests_twobody/test_propagation.py @@ -189,7 +189,7 @@ def test_propagation_parabolic(propagator): def test_propagation_zero_time_returns_same_state(): # Bug #50 - r0 = [1131.340, -2282.343, 6672.423] * u.km + r0 = [1131.340, -2282.343, 6672.423] * u.km # type: u.Quantity v0 = [-5.64305, 4.30333, 2.42879] * u.km / u.s ss0 = Orbit.from_vectors(Earth, r0, v0) tof = 0 * u.s diff --git a/tox.ini b/tox.ini index 255372e3a..bb4d4f201 100644 --- a/tox.ini +++ b/tox.ini @@ -29,7 +29,7 @@ extras = cesium skip_install = false commands = - {posargs:pytest -m "not mpl_image_compare" --cov --cov-report=term-missing -vv src/poliastro/tests} + {posargs:pytest -m "not mpl_image_compare" --mypy --cov --cov-report=term-missing -vv src/poliastro/tests} [testenv:images]