From ceaa2cd8e69ae7d7c96ee662543a98265109cfb8 Mon Sep 17 00:00:00 2001 From: Benoit Seignovert Date: Wed, 4 Nov 2020 19:20:30 +0100 Subject: [PATCH] Fix linter and doctests --- .gitignore | 4 +++- docs/calculation.rst | 40 +++++++++++++++++------------------ setup.py | 11 ++-------- tests/test_calculation_run.py | 5 +++-- webgeocalc/calculation.py | 4 ++-- webgeocalc/cli.py | 2 ++ 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index e5f95d6..b0f7580 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,10 @@ .eggs/ build/ dist/ +venv/ htmlcov/ __pycache__/ AUTHORS Changelog -docs/_build \ No newline at end of file +docs/_build +coverage.xml diff --git a/docs/calculation.rst b/docs/calculation.rst index 5b44197..6b2d08b 100644 --- a/docs/calculation.rst +++ b/docs/calculation.rst @@ -66,16 +66,16 @@ All WebGeoCalc calculation objects take their input attributes in to the any Calculation parameters: >>> Calculation( - api = 'ESA', - kernels = 6, - times = '2014-01-01T01:23:45.000', - calculation_type = 'STATE_VECTOR', - target = '67P/CHURYUMOV-GERASIMENKO (1969 R1)', - observer = 'ROSETTA ORBITER', - reference_frame = '67P/C-G_CK', - aberration_correction = 'NONE', - state_representation = 'LATITUDINAL', - ).api + ... api = 'ESA', + ... kernels = 6, + ... times = '2014-01-01T01:23:45.000', + ... calculation_type = 'STATE_VECTOR', + ... target = '67P/CHURYUMOV-GERASIMENKO (1969 R1)', + ... observer = 'ROSETTA ORBITER', + ... reference_frame = '67P/C-G_CK', + ... aberration_correction = 'NONE', + ... state_representation = 'LATITUDINAL', + ... ).api http://spice.esac.esa.int/webgeocalc/api 3-rd party WGC are also supported, either set :obj:`WGC_URL` @@ -83,16 +83,16 @@ All WebGeoCalc calculation objects take their input attributes in its ``URL`` to the :py:attr:`api` parameter: >>> Calculation( - api = 'https://wgc.obspm.fr/webgeocalc/api', - kernels = 6, - times = '2014-01-01T01:23:45.000', - calculation_type = 'STATE_VECTOR', - target = '67P/CHURYUMOV-GERASIMENKO (1969 R1)', - observer = 'ROSETTA ORBITER', - reference_frame = '67P/C-G_CK', - aberration_correction = 'NONE', - state_representation = 'LATITUDINAL', - ).api + ... api = 'https://wgc.obspm.fr/webgeocalc/api', + ... kernels = 6, + ... times = '2014-01-01T01:23:45.000', + ... calculation_type = 'STATE_VECTOR', + ... target = '67P/CHURYUMOV-GERASIMENKO (1969 R1)', + ... observer = 'ROSETTA ORBITER', + ... reference_frame = '67P/C-G_CK', + ... aberration_correction = 'NONE', + ... state_representation = 'LATITUDINAL', + ... ).api https://wgc.obspm.fr/webgeocalc/api In each cases, every new API is cached to improve diff --git a/setup.py b/setup.py index 880991c..cf1c3f6 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,6 @@ -#!/usr/bin/env python -'''Packaging Webgeocalc.''' +"""Packaging Webgeocalc.""" -# This will try to import setuptools. If not here, it fails with a message -try: - from setuptools import setup -except ImportError: - raise ImportError("This module could not be installed, probably because" - " setuptools is not installed on this computer." - "\nInstall ez_setup ([sudo] pip install ez_setup) and try again.") +from setuptools import setup setup( setup_requires=['pbr'], diff --git a/tests/test_calculation_run.py b/tests/test_calculation_run.py index a02c085..18356c2 100644 --- a/tests/test_calculation_run.py +++ b/tests/test_calculation_run.py @@ -7,7 +7,7 @@ from webgeocalc.errors import (CalculationAlreadySubmitted, CalculationFailed, CalculationNotCompleted, CalculationTimeOut, ResultAttributeError) -from webgeocalc.vars import JPL_URL, ESA_URL +from webgeocalc.vars import ESA_URL, JPL_URL @pytest.fixture def params(): @@ -448,7 +448,8 @@ def test_state_vector_single_time_esa(requests_mock, requests_mock.post(ESA_URL + '/calculation/new', json=response_sv_esa) requests_mock.get( - ESA_URL + '/calculation/' + response_sv_esa['calculationId'], json=response_sv_esa) + ESA_URL + '/calculation/' + response_sv_esa['calculationId'], + json=response_sv_esa) requests_mock.get( ESA_URL + '/calculation/' + response_sv_esa['calculationId'] + '/results', json=results_sv_esa) diff --git a/webgeocalc/calculation.py b/webgeocalc/calculation.py index 1ca5e73..40bd230 100644 --- a/webgeocalc/calculation.py +++ b/webgeocalc/calculation.py @@ -3,7 +3,7 @@ import time -from .api import Api, API, JPL_API, ESA_API +from .api import API, Api, ESA_API, JPL_API from .errors import (CalculationAlreadySubmitted, CalculationConflictAttr, CalculationFailed, CalculationIncompatibleAttr, CalculationInvalidAttr, CalculationInvalidValue, @@ -389,7 +389,7 @@ def run(self, timeout=30, sleep=1): if self.columns is not None and self.values is not None: return self.results - for i in range(int(timeout / sleep)): + for _ in range(int(timeout / sleep)): self.update() if self.phase == 'COMPLETE': diff --git a/webgeocalc/cli.py b/webgeocalc/cli.py index ea3e968..48fa60b 100644 --- a/webgeocalc/cli.py +++ b/webgeocalc/cli.py @@ -15,7 +15,9 @@ class GetApi(argparse.Action): """Custom API from key action.""" + def __call__(self, parser, args, values, option_string=None): + """Select API based on the provided key.""" key = values.upper() api = JPL_API if key == 'JPL' else ESA_API if key == 'ESA' else Api(key) setattr(args, self.dest, api)