diff --git a/.gitignore b/.gitignore index d50a54f..41df154 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ *.egg-info/ __pycache__/ venv/ +.tox/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..77abd59 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +sudo: false +dist: xenial +language: python +install: + - pip install tox + +script: + - tox -e $TOXENV + +matrix: + fast_finish: true + include: + # Python version is just for the look on travis. + - python: 2.7 + env: TOXENV=py27 + + - python: 3.5 + env: TOXENV=py35 + + - python: 3.6 + env: TOXENV=py36 + + - python: 3.7 + env: TOXENV=py37 + sudo: true diff --git a/CHANGELOG.md b/CHANGELOG.md index eafe921..fe0365a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * Added a ``--check-only`` argument to ``download.py`` to display the expiration dates of the files currently on disk. * Enable computation of the expiration date of the BSP file(s) on disk (requires to install the local repository using the [dev] option / See README for more information). * Dropped compatibility with Python 3.3 and 3.4, as skyfield did. +* Added basic tests for the ``get_skyfield_data_path`` function using `tox`. +* Added automated tests through Travis CI. ## 0.0.2 (2019-08-23) diff --git a/Makefile b/Makefile index 0bacc26..fa38ea3 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ help: @echo " * clean: remove all skyfield data from data directory." @echo " * package: build python source package." @echo "" - @echo " * install-dev: Install the requirements to execute download.py" + @echo " * install-dev: Install the requirements to switch to dev mode." + @echo " * test: Run tests using tox." download: python3 download.py @@ -19,3 +20,6 @@ package: install-dev: pip install -e .[dev] + +test: + tox diff --git a/setup.cfg b/setup.cfg index 324a76e..823ecbf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,6 +36,12 @@ setup_requires = dev = jplephem numpy + tox +tests = + pytest + skyfield + mock + # ipdb [bdist_wheel] universal = 1 diff --git a/tests/test_get_path.py b/tests/test_get_path.py new file mode 100644 index 0000000..22d2fa8 --- /dev/null +++ b/tests/test_get_path.py @@ -0,0 +1,18 @@ +import mock +from skyfield_data import get_skyfield_data_path +from skyfield.api import Loader + + +def test_load_no_cache(tmpdir): + with mock.patch('jplephem.spk.SPK.open'): # avoid naughty side-effects + with mock.patch('skyfield.iokit.download') as download_patched: + load = Loader(tmpdir.dirname) + load('de421.bsp') + assert download_patched.call_count == 1 + + +@mock.patch('skyfield.iokit.download') +def test_load_using_cache(download_patched): + load = Loader(get_skyfield_data_path()) + load('de421.bsp') + assert download_patched.call_count == 0 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..16ffc24 --- /dev/null +++ b/tox.ini @@ -0,0 +1,14 @@ +[tox] +envlist = py27,py35,py36,py37 + + +[testenv] +commands = + pytest -s +deps = + .[tests] + + +[testenv:py33] +deps = . +commands = pip freeze -l