Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch emu in a process during tests run #86

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ install:
- source activate birdy
# Packages for testing
- conda install pytest flake8
# Install Emu WPS
- conda install -c conda-forge -c birdhouse "emu>=0.9.1"
# Install birdy
- python setup.py install
- conda list
script:
- pytest -m 'not online'
- flake8
3 changes: 3 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ sphinx-autoapi
twine

pytest
git+git:/bird-house/emu@master#egg=emu
git+git:/bird-house/eggshell@master#egg=eggshell
git+git:/bird-house/pywps@master#egg=pywps
#pytest-runner==4.2
56 changes: 36 additions & 20 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,49 @@
import os
import pytest
import json
from owslib import crs
import sys
from multiprocessing import Process

from birdy.client import converters
from birdy import WPSClient

# These tests assume Emu is running on the localhost
url = "http://localhost:5000/wps"
url = "http://127.0.0.1:5000/wps"


def data_path(*args):
return os.path.join(os.path.dirname(__file__), "resources", *args)
def test_path(*args):
return os.path.join(os.path.dirname(__file__), *args)


@pytest.fixture(scope="module")
def wps():
def start_emu(request):
"""Starts a single instance of the emu WPS for the duration of the tests"""
log_file = test_path("pywps.log")
try:
os.remove(log_file)
except IOError:
pass

def run():
from emu.cli import cli
sys.argv = [sys.executable, 'start', '--log-file', log_file]
cli()
p = Process(target=run)
p.start()

def finalizer():
p.terminate()
print("--------\nEmu Logs\n--------")
print(open(log_file).read())

request.addfinalizer(finalizer)


@pytest.fixture(scope="module")
def wps(start_emu):
return WPSClient(url=url)


@pytest.mark.skip
@pytest.mark.online
# @pytest.mark.skip("52north wps is down.")
def test_52north():
Expand All @@ -29,28 +54,24 @@ def test_52north():
WPSClient(url)


@pytest.mark.online
def test_wps_client_backward_compability():
def test_wps_client_backward_compability(start_emu):
from birdy import BirdyClient
BirdyClient(url=url)
from birdy import import_wps
import_wps(url=url)


@pytest.mark.online
def test_wps_docs(wps):
assert "Processes" in wps.__doc__


@pytest.mark.online
def test_wps_client_single_output(wps):
result = wps.hello("david")
assert result.get()[0] == "Hello david"
result = wps.binaryoperatorfornumbers(inputa=1, inputb=2, operator="add")
assert result.get()[0] == 3.0


@pytest.mark.online
def test_wps_interact(wps):
for pid in wps._processes.keys():
if pid in ['bbox', ]: # Unsupported
Expand All @@ -59,7 +80,6 @@ def test_wps_interact(wps):
wps.interact(pid)


@pytest.mark.online
def test_wps_client_multiple_output(wps):
# For multiple outputs, the output is a namedtuple
result = wps.dummyprocess(10, 20)
Expand All @@ -80,7 +100,6 @@ def test_interactive(capsys):


@pytest.mark.skip(reason="Complex Output is not working.")
@pytest.mark.online
def test_wps_client_complex_output(wps):
# As reference
wps._convert_objects = False
Expand All @@ -99,24 +118,21 @@ def test_wps_client_complex_output(wps):
wps._convert_objects = False


@pytest.mark.online
def test_process_subset_only_one():
def test_process_subset_only_one(start_emu):
m = WPSClient(url=url, processes=["nap"])
assert count_class_methods(m) == 1

m = WPSClient(url=url, processes="nap")
assert count_class_methods(m) == 1


@pytest.mark.online
def test_process_subset_names():
def test_process_subset_names(start_emu):
with pytest.raises(ValueError, match="missing"):
WPSClient(url=url, processes=["missing"])
with pytest.raises(ValueError, match="wrong, process, names"):
WPSClient(url=url, processes=["wrong", "process", "names"])


@pytest.mark.online
def test_inputs(wps):
import netCDF4 as nc
time_ = datetime.datetime.now().time()
Expand All @@ -134,7 +150,7 @@ def test_inputs(wps):
string_choice="rock",
string_multiple_choice="sitting duck",
text="some text",
dataset="file://" + data_path("dummy.nc"),
dataset="file://" + test_path("resources", "dummy.nc"),
)
expected = (
"test string",
Expand All @@ -151,7 +167,7 @@ def test_inputs(wps):
)
assert expected == result.get(asobj=True)[:-2]

expected_netcdf = nc.Dataset(data_path("dummy.nc"))
expected_netcdf = nc.Dataset(test_path("resources", "dummy.nc"))
netcdf = result.get(asobj=True)[-2]
assert list(expected_netcdf.dimensions) == list(netcdf.dimensions)
assert list(expected_netcdf.variables) == list(netcdf.variables)
Expand Down