Skip to content

Commit

Permalink
Tests now download required srtm data themselves (if remote-data='any')
Browse files Browse the repository at this point in the history
Before, the remote-data tests would only work if one had downloaded the
N50E006.hgt tile beforehand. Either do

python setup.py test --remote-data=any

or

import pycraf
pycraf.test(remote_data='any')
  • Loading branch information
Benjamin Winkel committed Jul 28, 2017
1 parent 9193205 commit eeab3cf
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 21 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Expand Up @@ -139,11 +139,11 @@ before_install:
install:

# download SRTM data for tests
- wget -P ${TRAVIS_BUILD_DIR}/srtm/ http://viewfinderpanoramas.org/dem3/M32.zip
- wget -P ${TRAVIS_BUILD_DIR}/srtm/ http://viewfinderpanoramas.org/dem3/N32.zip
- unzip ${TRAVIS_BUILD_DIR}/srtm/M32.zip -d ${TRAVIS_BUILD_DIR}/srtm/
- unzip ${TRAVIS_BUILD_DIR}/srtm/N32.zip -d ${TRAVIS_BUILD_DIR}/srtm/
- mv ${TRAVIS_BUILD_DIR}/srtm/{M,N}*/*.hgt ${TRAVIS_BUILD_DIR}/srtm/
# - wget -P ${TRAVIS_BUILD_DIR}/srtm/ http://viewfinderpanoramas.org/dem3/M32.zip
# - wget -P ${TRAVIS_BUILD_DIR}/srtm/ http://viewfinderpanoramas.org/dem3/N32.zip
# - unzip ${TRAVIS_BUILD_DIR}/srtm/M32.zip -d ${TRAVIS_BUILD_DIR}/srtm/
# - unzip ${TRAVIS_BUILD_DIR}/srtm/N32.zip -d ${TRAVIS_BUILD_DIR}/srtm/
# - mv ${TRAVIS_BUILD_DIR}/srtm/{M,N}*/*.hgt ${TRAVIS_BUILD_DIR}/srtm/

# We now use the ci-helpers package to set up our testing environment.
# This is done by using Miniconda and then using conda and pip to install
Expand Down
10 changes: 9 additions & 1 deletion README.rst
Expand Up @@ -76,8 +76,16 @@ After installation (see below) you can test, if everything works as intended::
pycraf.test()
# this will skip over some tests that need to download
# data from the internet; to include them:
pycraf.test(source='any')
pycraf.test(remote_data='any')

By default, the `test` function will skip over tests that require
data from the internet. One can include them by::

pycraf.test(remote_data='any')

This will *always* download SRTM data (few tiles only) to test the
auto-download functionality! Do this only, if you can afford the network
traffic.


License
Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Expand Up @@ -46,10 +46,10 @@ platform:

install:
# downloading srtm data
- "mkdir %SRTMDATA%"
- "powershell -command \"& { Invoke-WebRequest -Uri 'http://viewfinderpanoramas.org/dem3/M32.zip' -OutFile '%SRTMDATA%\\M32.zip' }\""
- "powershell -command \"& { Expand-Archive '%SRTMDATA%\\M32.zip' -DestinationPath '%SRTMDATA%\\' }\""
- "powershell -command \"& { Move-Item '%SRTMDATA%\\*\\*.hgt' '%SRTMDATA%\\' }\""
# - "mkdir %SRTMDATA%"
# - "powershell -command \"& { Invoke-WebRequest -Uri 'http://viewfinderpanoramas.org/dem3/M32.zip' -OutFile '%SRTMDATA%\\M32.zip' }\""
# - "powershell -command \"& { Expand-Archive '%SRTMDATA%\\M32.zip' -DestinationPath '%SRTMDATA%\\' }\""
# - "powershell -command \"& { Move-Item '%SRTMDATA%\\*\\*.hgt' '%SRTMDATA%\\' }\""
- "git clone git://github.com/astropy/ci-helpers.git"
- "powershell ci-helpers/appveyor/install-miniconda.ps1"
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
Expand Down
4 changes: 4 additions & 0 deletions docs/install.rst
Expand Up @@ -168,6 +168,10 @@ the `pycraf issue tracker <http://github.com/bwinkel/pycraf/issues>`__.
>>> import pycraf # doctest: +SKIP
>>> pycraf.test(remote_data='any') # doctest: +SKIP

This will *always* download SRTM data (few tiles only) to test the
auto-download functionality! Do this only, if you can afford the
network traffic.

If you prefer testing on the command line and usually work with the source
code, you can also do

Expand Down
24 changes: 24 additions & 0 deletions pycraf/pathprof/tests/conftest.py
@@ -0,0 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pytest
from ... import pathprof


@pytest.fixture(scope='session')
def srtm_temp_dir(tmpdir_factory):

tdir = tmpdir_factory.mktemp('srtmdata')
return str(tdir)


@pytest.yield_fixture()
def srtm_handler(srtm_temp_dir):

with pathprof.srtm.SrtmConf.set(
srtm_dir=srtm_temp_dir,
server='nasa_v2.1',
download='missing',
):

yield
8 changes: 6 additions & 2 deletions pycraf/pathprof/tests/test_heightprofile.py
Expand Up @@ -10,7 +10,7 @@
from functools import partial
import numpy as np
from numpy.testing import assert_equal, assert_allclose
from astropy.tests.helper import assert_quantity_allclose
from astropy.tests.helper import assert_quantity_allclose, remote_data
from astropy import units as apu
from astropy.units import Quantity
from ... import pathprof
Expand All @@ -21,7 +21,9 @@
TOL_KWARGS = {'atol': 1.e-4, 'rtol': 1.e-4}


def test_srtm_height_profile():
@remote_data(source='any')
@pytest.mark.usefixtures('srtm_handler')
def test_srtm_height_profile(srtm_temp_dir):

lon_t, lat_t = 6.5 * apu.deg, 50.5 * apu.deg
lon_r, lat_r = 6.52 * apu.deg, 50.52 * apu.deg
Expand Down Expand Up @@ -69,6 +71,8 @@ def test_srtm_height_profile():
)


@remote_data(source='any')
@pytest.mark.usefixtures('srtm_handler')
def test_srtm_height_map():

lon_t, lat_t = 6.5 * apu.deg, 50.5 * apu.deg
Expand Down
6 changes: 4 additions & 2 deletions pycraf/pathprof/tests/test_propagation.py
Expand Up @@ -11,7 +11,7 @@
from functools import partial
import numpy as np
from numpy.testing import assert_equal, assert_allclose
from astropy.tests.helper import assert_quantity_allclose
from astropy.tests.helper import assert_quantity_allclose, remote_data
from astropy import units as apu
from astropy.units import Quantity
from ... import conversions as cnv
Expand Down Expand Up @@ -43,6 +43,8 @@
]


@remote_data(source='any')
@pytest.mark.usefixtures('srtm_handler')
class TestPropagation:

def setup(self):
Expand Down Expand Up @@ -81,7 +83,6 @@ def setup(self):
for case in self.cases:

freq, (h_tg, h_rg), time_percent, version, (G_t, G_r) = case

pprop = pathprof.PathProp(
freq * apu.GHz,
self.temperature, self.pressure,
Expand All @@ -92,6 +93,7 @@ def setup(self):
time_percent * apu.percent,
version=version,
)

self.pprops.append(pprop)

# Warning: if uncommenting, the test cases will be overwritten
Expand Down
7 changes: 0 additions & 7 deletions pycraf/pathprof/tests/test_srtm.py
Expand Up @@ -14,13 +14,6 @@
TOL_KWARGS = {'atol': 1.e-4, 'rtol': 1.e-4}


@pytest.fixture(scope='session')
def srtm_temp_dir(tmpdir_factory):

tdir = tmpdir_factory.mktemp('srtmdata')
return str(tdir)


class TestSrtmConf:

def test_context_manager(self):
Expand Down

0 comments on commit eeab3cf

Please sign in to comment.