Skip to content

Commit 4e17012

Browse files
make application test python 3.8 compatible
1 parent 27ed61f commit 4e17012

1 file changed

Lines changed: 43 additions & 39 deletions

File tree

tests/test_application.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
#
2-
# Copyright (c) 2021 Nitric Technologies Pty Ltd.
3-
#
4-
# This file is part of Nitric Python 3 SDK.
5-
# See https://github.com/nitrictech/python-sdk for further info.
6-
#
7-
# Licensed under the Apache License, Version 2.0 (the "License");
8-
# you may not use this file except in compliance with the License.
9-
# You may obtain a copy of the License at
10-
#
11-
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
13-
# Unless required by applicable law or agreed to in writing, software
14-
# distributed under the License is distributed on an "AS IS" BASIS,
15-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
# See the License for the specific language governing permissions and
17-
# limitations under the License.
18-
#
1+
# #
2+
# # Copyright (c) 2021 Nitric Technologies Pty Ltd.
3+
# #
4+
# # This file is part of Nitric Python 3 SDK.
5+
# # See https://github.com/nitrictech/python-sdk for further info.
6+
# #
7+
# # Licensed under the Apache License, Version 2.0 (the "License");
8+
# # you may not use this file except in compliance with the License.
9+
# # You may obtain a copy of the License at
10+
# #
11+
# # http://www.apache.org/licenses/LICENSE-2.0
12+
# #
13+
# # Unless required by applicable law or agreed to in writing, software
14+
# # distributed under the License is distributed on an "AS IS" BASIS,
15+
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# # See the License for the specific language governing permissions and
17+
# # limitations under the License.
18+
# #
1919
from unittest import IsolatedAsyncioTestCase
20-
from unittest.mock import patch, AsyncMock, Mock, call
20+
from unittest.mock import patch, AsyncMock, Mock
2121

2222
from grpclib import GRPCError, Status
2323
from opentelemetry.sdk.trace import TracerProvider, sampling
@@ -66,11 +66,12 @@ def test_run(self):
6666
mock_running_loop = Mock()
6767
mock_event_loop = Mock()
6868

69-
with (patch("asyncio.get_event_loop", mock_event_loop), patch("asyncio.get_running_loop", mock_running_loop)):
70-
application.run()
69+
with patch("asyncio.get_event_loop", mock_event_loop):
70+
with patch("asyncio.get_running_loop", mock_running_loop):
71+
application.run()
7172

72-
mock_running_loop.assert_called_once()
73-
mock_event_loop.assert_not_called()
73+
mock_running_loop.assert_called_once()
74+
mock_event_loop.assert_not_called()
7475

7576
def test_run_with_no_active_event_loop(self):
7677
application = Nitric()
@@ -80,11 +81,12 @@ def test_run_with_no_active_event_loop(self):
8081

8182
mock_event_loop = Mock()
8283

83-
with (patch("asyncio.get_event_loop", mock_event_loop), patch("asyncio.get_running_loop", mock_running_loop)):
84-
application.run()
84+
with patch("asyncio.get_event_loop", mock_event_loop):
85+
with patch("asyncio.get_running_loop", mock_running_loop):
86+
application.run()
8587

86-
mock_running_loop.assert_called_once()
87-
mock_event_loop.assert_called_once()
88+
mock_running_loop.assert_called_once()
89+
mock_event_loop.assert_called_once()
8890

8991
def test_run_with_keyboard_interrupt(self):
9092
application = Nitric()
@@ -94,11 +96,12 @@ def test_run_with_keyboard_interrupt(self):
9496

9597
mock_event_loop = Mock()
9698

97-
with (patch("asyncio.get_event_loop", mock_event_loop), patch("asyncio.get_running_loop", mock_running_loop)):
98-
application.run()
99+
with patch("asyncio.get_event_loop", mock_event_loop):
100+
with patch("asyncio.get_running_loop", mock_running_loop):
101+
application.run()
99102

100-
mock_running_loop.assert_called_once()
101-
mock_event_loop.assert_not_called()
103+
mock_running_loop.assert_called_once()
104+
mock_event_loop.assert_not_called()
102105

103106
def test_run_with_connection_refused(self):
104107
application = Nitric()
@@ -108,12 +111,13 @@ def test_run_with_connection_refused(self):
108111

109112
mock_event_loop = Mock()
110113

111-
with (patch("asyncio.get_event_loop", mock_event_loop), patch("asyncio.get_running_loop", mock_running_loop)):
112-
try:
113-
application.run()
114-
pytest.fail()
115-
except NitricUnavailableException as e:
116-
assert str(e).startswith("Unable to connect to a nitric server!")
114+
with patch("asyncio.get_event_loop", mock_event_loop):
115+
with patch("asyncio.get_running_loop", mock_running_loop):
116+
try:
117+
application.run()
118+
pytest.fail()
119+
except NitricUnavailableException as e:
120+
assert str(e).startswith("Unable to connect to a nitric server!")
117121

118-
mock_running_loop.assert_called_once()
119-
mock_event_loop.assert_not_called()
122+
mock_running_loop.assert_called_once()
123+
mock_event_loop.assert_not_called()

0 commit comments

Comments
 (0)