Skip to content

Commit

Permalink
Fix MyPy errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astrojuanlu committed Aug 18, 2019
1 parent fb4886a commit 5d5a9a6
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[mypy]
ignore_missing_imports = True
check_untyped_defs = True
strict_optional = False
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/poliastro/tests/test_jit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import contextmanager
from importlib.abc import MetaPathFinder

from poliastro.core import _jit

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/poliastro/tests/tests_twobody/test_orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 5 additions & 3 deletions src/poliastro/tests/tests_twobody/test_perturbations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]),
Expand Down
2 changes: 1 addition & 1 deletion src/poliastro/tests/tests_twobody/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5d5a9a6

Please sign in to comment.