Skip to content

Commit

Permalink
Move tests (#6)
Browse files Browse the repository at this point in the history
* move tests

* bump version
  • Loading branch information
MatthewFlamm authored Feb 24, 2019
1 parent 9ab563c commit 16d098b
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = */tests/*
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include README.md
include LICENSE
include requirements-test.txt
include requirements-test.txt
include .coveragerc
2 changes: 1 addition & 1 deletion pynws/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Constants for pynws
"""

__version__ = '0.1'
__version__ = '0.5'

API_URL = 'https://api.weather.gov/'
API_STATIONS = 'points/{},{}/stations'
Expand Down
1 change: 1 addition & 0 deletions pynws/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'''Tests and mock responses'''
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_forecast.py → pynws/tests/test_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pynws
import pytest

from tests.forecast_response import FORECAST_RESPONSE
from pynws.tests.forecast_response import FORECAST_RESPONSE

LATLON = (0, 0)
USERID = 'testing@test'
Expand Down
6 changes: 3 additions & 3 deletions tests/test_nws.py → pynws/tests/test_nws.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pynws
import pytest

from tests.observation_response import OBSERVATION_RESPONSE
from tests.station_response import STATION_RESPONSE
from tests.forecast_response import FORECAST_RESPONSE
from pynws.tests.observation_response import OBSERVATION_RESPONSE
from pynws.tests.station_response import STATION_RESPONSE
from pynws.tests.forecast_response import FORECAST_RESPONSE

LATLON = (0, 0)
USERID = 'testing@test'
Expand Down
11 changes: 9 additions & 2 deletions tests/test_obs.py → pynws/tests/test_obs.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
"""Test observations"""
import asyncio
import aiohttp
import pynws
import pytest

from tests.observation_response import OBSERVATION_RESPONSE
from pynws.tests.observation_response import OBSERVATION_RESPONSE

LATLON = (0, 0)
USERID = 'testing@test'

@pytest.fixture()
def obs_url(monkeypatch):
"""Monkeypatch observation url to /obs"""
def mock_url(a):
return '/obs'
monkeypatch.setattr('pynws.urls.obs_url', mock_url)

async def obs(request):
"""Return observation response"""
return aiohttp.web.json_response(data=OBSERVATION_RESPONSE)

async def test_obs_url(aiohttp_client, loop):
"""Observation url is correct"""
app = aiohttp.web.Application()
client = await aiohttp_client(app)
assert pynws.urls.obs_url('STNA') == pynws.const.API_URL + pynws.const.API_OBSERVATION.format('STNA')
assert pynws.urls.obs_url('STNA') == pynws.const.API_URL + \
pynws.const.API_OBSERVATION.format('STNA')

async def test_obs_response(aiohttp_client, loop, obs_url):
"""Getting response succeeds"""
app = aiohttp.web.Application()
app.router.add_get('/obs', obs)
client = await aiohttp_client(app)
await pynws.observations('STNA', client, USERID)

async def test_obs_fail(aiohttp_client, loop, obs_url):
"""Response fails when url not correct"""
app = aiohttp.web.Application()
client = await aiohttp_client(app)
with pytest.raises(aiohttp.ClientResponseError):
Expand Down
8 changes: 7 additions & 1 deletion tests/test_stn.py → pynws/tests/test_stn.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
"""Test stations"""
import asyncio
import aiohttp
import pynws
import pytest

from tests.station_response import STATION_RESPONSE
from pynws.tests.station_response import STATION_RESPONSE

LATLON = (0, 0)
USERID = 'testing@test'

@pytest.fixture()
def station_url(monkeypatch):
"""Monkeypatch station url"""
def mock_url(a, b):
return '/stations'
monkeypatch.setattr('pynws.urls.stn_url', mock_url)

async def stn(request):
"""Return station response"""
return aiohttp.web.json_response(data=STATION_RESPONSE)

async def test_stn_url(aiohttp_client, loop):
"""Test station url is correct"""
app = aiohttp.web.Application()
client = await aiohttp_client(app)
assert pynws.urls.stn_url(*LATLON) == pynws.const.API_URL + pynws.const.API_STATIONS.format(*LATLON)

async def test_stn_response(aiohttp_client, loop, station_url):
"""Test response of stations"""
app = aiohttp.web.Application()
app.router.add_get('/stations', stn)
client = await aiohttp_client(app)
await pynws.stations(*LATLON, client, USERID)

async def test_stn_fail(aiohttp_client, loop, station_url):
"""Station fails with wrong url"""
app = aiohttp.web.Application()
client = await aiohttp_client(app)
with pytest.raises(aiohttp.ClientResponseError):
Expand Down
Empty file removed tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ deps =

commands =
pytest --cov=pynws/
pylint pynws
pylint --ignore=tests pynws
{env:POST_COMMAND:python --version}
[travis]
python =
Expand Down

0 comments on commit 16d098b

Please sign in to comment.