Skip to content

Commit

Permalink
Merge pull request #918 from wagner-intevation/compatibility
Browse files Browse the repository at this point in the history
Fix compatibility with current Python versions
  • Loading branch information
underrun authored Jun 30, 2023
2 parents 8b5ac00 + 1fa29da commit e4a3fa4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion hug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def _ensure_started(self):
if async_handlers:
loop = asyncio.get_event_loop()
loop.run_until_complete(
asyncio.gather(*[handler(self) for handler in async_handlers], loop=loop)
asyncio.gather(*[handler(self) for handler in async_handlers])
)
for startup_handler in self.startup_handlers:
if not startup_handler in async_handlers:
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def list_modules(dirname):
packages=["hug"],
requires=["falcon", "requests"],
install_requires=["falcon==2.0.0", "requests"],
setup_requires=["pytest-runner"],
tests_require=["pytest", "mock", "marshmallow"],
tests_require=["pytest", "marshmallow"],
ext_modules=ext_modules,
cmdclass=cmdclass,
python_requires=">=3.5",
Expand Down
20 changes: 7 additions & 13 deletions tests/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def test_basic_call_coroutine():
"""The most basic Happy-Path test for Hug APIs using async"""

@hug.call()
@asyncio.coroutine
def hello_world():
async def hello_world():
return "Hello World!"

assert loop.run_until_complete(hello_world()) == "Hello World!"
Expand All @@ -42,25 +41,22 @@ def test_nested_basic_call_coroutine():
"""The most basic Happy-Path test for Hug APIs using async"""

@hug.call()
@asyncio.coroutine
def hello_world():
async def hello_world():
return getattr(asyncio, "ensure_future")(nested_hello_world())

@hug.local()
@asyncio.coroutine
def nested_hello_world():
async def nested_hello_world():
return "Hello World!"

assert loop.run_until_complete(hello_world()) == "Hello World!"
assert loop.run_until_complete(hello_world()).result() == "Hello World!"


def test_basic_call_on_method_coroutine():
"""Test to ensure the most basic call still works if applied to a method"""

class API(object):
@hug.call()
@asyncio.coroutine
def hello_world(self=None):
async def hello_world(self=None):
return "Hello World!"

api_instance = API()
Expand All @@ -79,8 +75,7 @@ def hello_world(self):
api_instance = API()

@hug.call()
@asyncio.coroutine
def hello_world():
async def hello_world():
return api_instance.hello_world()

assert api_instance.hello_world() == "Hello World!"
Expand All @@ -94,8 +89,7 @@ class API(object):
def __init__(self):
hug.call()(self.hello_world_method)

@asyncio.coroutine
def hello_world_method(self):
async def hello_world_method(self):
return "Hello World!"

api_instance = API()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,7 @@ def happens_on_startup(api):
happened_on_startup.append("non-async")

@hug.startup(api=hug_api)
@asyncio.coroutine
def async_happens_on_startup(api):
async def async_happens_on_startup(api):
happened_on_startup.append("async")

assert happens_on_startup in hug_api.startup_handlers
Expand Down
2 changes: 1 addition & 1 deletion tests/test_output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def test_json_converter_numpy_types():
ex_int = numpy.int_(9)
ex_np_array = numpy.array([1, 2, 3, 4, 5])
ex_np_int_array = numpy.int_([5, 4, 3])
ex_np_float = numpy.float(0.5)
ex_np_float = numpy.float64(0.5)

assert 9 == hug.output_format._json_converter(ex_int)
assert [1, 2, 3, 4, 5] == hug.output_format._json_converter(ex_np_array)
Expand Down

0 comments on commit e4a3fa4

Please sign in to comment.