Skip to content

Commit

Permalink
Move Sleep process definition from tests/test_assync.py to tests/proc…
Browse files Browse the repository at this point in the history
…esses/__init__.py where other test processes are to facilitate reuse.
  • Loading branch information
huard committed Sep 16, 2022
1 parent 85ca819 commit 53ba8ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
35 changes: 35 additions & 0 deletions tests/processes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,38 @@ def bbox(request, response):
area = request.inputs['area'][0].data
response.outputs['extent'].data = area
return response


class Sleep(Process):
"""A long running process, just sleeping."""
def __init__(self):
inputs = [
LiteralInput('seconds', title='Seconds', data_type='float')
]
outputs = [
LiteralOutput('finished', title='Finished', data_type='boolean')
]

super(Sleep, self).__init__(
self._handler,
identifier='sleep',
title='Sleep',
abstract='Wait for specified number of seconds.',
inputs=inputs,
outputs=outputs,
store_supported=True,
status_supported=True
)

@staticmethod
def _handler(request, response):
import time

seconds = request.inputs['seconds'][0].data
step = seconds / 3
for i in range(3):
response.update_status('Sleep in progress...', i / 3 * 100)
time.sleep(step)

response.outputs['finished'].data = "True"
return response
30 changes: 2 additions & 28 deletions tests/test_assync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,17 @@
from pywps import Service, Process, LiteralInput, LiteralOutput
from pywps import get_ElementMakerForVersion
from pywps.tests import client_for, assert_response_accepted
from .processes import Sleep

VERSION = "1.0.0"

WPS, OWS = get_ElementMakerForVersion(VERSION)


def create_sleep():

def sleep(request, response):
seconds = request.inputs['seconds'][0].data
assert isinstance(seconds, float)

step = seconds / 3
for i in range(3):
# How is status working in version 4 ?
#self.status.set("Waiting...", i * 10)
time.sleep(step)

response.outputs['finished'].data = "True"
return response

return Process(handler=sleep,
identifier='sleep',
title='Sleep',
inputs=[
LiteralInput('seconds', title='Seconds', data_type='float')
],
outputs=[
LiteralOutput('finished', title='Finished', data_type='boolean')
]
)


class ExecuteTest(unittest.TestCase):

def test_assync(self):
client = client_for(Service(processes=[create_sleep()]))
client = client_for(Service(processes=[Sleep()]))
request_doc = WPS.Execute(
OWS.Identifier('sleep'),
WPS.DataInputs(
Expand Down

0 comments on commit 53ba8ac

Please sign in to comment.