Skip to content

Commit e4a3fa4

Browse files
authored
Merge pull request #918 from wagner-intevation/compatibility
Fix compatibility with current Python versions
2 parents 8b5ac00 + 1fa29da commit e4a3fa4

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

hug/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def _ensure_started(self):
631631
if async_handlers:
632632
loop = asyncio.get_event_loop()
633633
loop.run_until_complete(
634-
asyncio.gather(*[handler(self) for handler in async_handlers], loop=loop)
634+
asyncio.gather(*[handler(self) for handler in async_handlers])
635635
)
636636
for startup_handler in self.startup_handlers:
637637
if not startup_handler in async_handlers:

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def list_modules(dirname):
9797
packages=["hug"],
9898
requires=["falcon", "requests"],
9999
install_requires=["falcon==2.0.0", "requests"],
100-
setup_requires=["pytest-runner"],
101-
tests_require=["pytest", "mock", "marshmallow"],
100+
tests_require=["pytest", "marshmallow"],
102101
ext_modules=ext_modules,
103102
cmdclass=cmdclass,
104103
python_requires=">=3.5",

tests/test_coroutines.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def test_basic_call_coroutine():
3131
"""The most basic Happy-Path test for Hug APIs using async"""
3232

3333
@hug.call()
34-
@asyncio.coroutine
35-
def hello_world():
34+
async def hello_world():
3635
return "Hello World!"
3736

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

4443
@hug.call()
45-
@asyncio.coroutine
46-
def hello_world():
44+
async def hello_world():
4745
return getattr(asyncio, "ensure_future")(nested_hello_world())
4846

4947
@hug.local()
50-
@asyncio.coroutine
51-
def nested_hello_world():
48+
async def nested_hello_world():
5249
return "Hello World!"
5350

54-
assert loop.run_until_complete(hello_world()) == "Hello World!"
51+
assert loop.run_until_complete(hello_world()).result() == "Hello World!"
5552

5653

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

6057
class API(object):
6158
@hug.call()
62-
@asyncio.coroutine
63-
def hello_world(self=None):
59+
async def hello_world(self=None):
6460
return "Hello World!"
6561

6662
api_instance = API()
@@ -79,8 +75,7 @@ def hello_world(self):
7975
api_instance = API()
8076

8177
@hug.call()
82-
@asyncio.coroutine
83-
def hello_world():
78+
async def hello_world():
8479
return api_instance.hello_world()
8580

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

97-
@asyncio.coroutine
98-
def hello_world_method(self):
92+
async def hello_world_method(self):
9993
return "Hello World!"
10094

10195
api_instance = API()

tests/test_decorators.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,7 @@ def happens_on_startup(api):
15861586
happened_on_startup.append("non-async")
15871587

15881588
@hug.startup(api=hug_api)
1589-
@asyncio.coroutine
1590-
def async_happens_on_startup(api):
1589+
async def async_happens_on_startup(api):
15911590
happened_on_startup.append("async")
15921591

15931592
assert happens_on_startup in hug_api.startup_handlers

tests/test_output_format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def test_json_converter_numpy_types():
366366
ex_int = numpy.int_(9)
367367
ex_np_array = numpy.array([1, 2, 3, 4, 5])
368368
ex_np_int_array = numpy.int_([5, 4, 3])
369-
ex_np_float = numpy.float(0.5)
369+
ex_np_float = numpy.float64(0.5)
370370

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

0 commit comments

Comments
 (0)