Skip to content

Commit 1327b53

Browse files
authored
Remove deprecated packages asynctest, codecov (#251)
* [tests] Remove deprecated asynctest * [tests] use codecov/codecov-action * Fix tests. * Fix e2e tests. * [chore] isort
1 parent 5bfb913 commit 1327b53

14 files changed

+65
-103
lines changed

.github/workflows/test.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: ["3.7", "3.8", "3.9", "3.10"]
11+
python-version: ["3.8", "3.9", "3.10", "3.11"]
1212

1313
steps:
1414
- uses: actions/checkout@v3
@@ -32,21 +32,22 @@ jobs:
3232
3333
- name: Run unit tests
3434
run: |
35-
py.test -vvv -s --ignore=kubernetes_asyncio/e2e_test --cov-report=xml --cov=kubernetes_asyncio
35+
# splitted into 2 steps because of problem with event-loop in aiohttp
36+
py.test -vvv -s --ignore=kubernetes_asyncio/e2e_test --ignore=kubernetes_asyncio/test --cov-report=xml --cov=kubernetes_asyncio
37+
py.test -vvv -s --cov-report=xml --cov=kubernetes_asyncio2 kubernetes_asyncio/test --cov-append
3638
3739
- name: Run e2e tests
3840
run: |
3941
scripts/kube-init.sh py.test -vvv -s kubernetes_asyncio/e2e_test
4042
4143
- name: Lint with flake8 and isort (only on the latest version of Python)
42-
if: matrix.python-version == 3.10
44+
if: matrix.python-version == 3.11
4345
run: |
4446
flake8
4547
isort -c --diff .
4648
4749
- name: Send coverage report
48-
if: matrix.python-version == 3.10
49-
env:
50-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
51-
run: |
52-
codecov
50+
uses: codecov/codecov-action@v3
51+
if: matrix.python-version == 3.11
52+
with:
53+
token: ${{ secrets.CODECOV_TOKEN }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ You can run the style checks and tests with
107107
```bash
108108
flake8 kubernetes_asyncio/
109109
isort --diff kubernetes_asyncio/
110-
nosetests
110+
py.test
111111
```

kubernetes_asyncio/config/exec_provider_test.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
import json
1616
import sys
17-
18-
from asynctest import ANY, TestCase, mock, patch
17+
from unittest import IsolatedAsyncioTestCase
18+
from unittest.mock import ANY, AsyncMock, patch
1919

2020
from .config_exception import ConfigException
2121
from .exec_provider import ExecProvider
2222
from .kube_config import ConfigNode
2323

2424

25-
class ExecProviderTest(TestCase):
25+
class ExecProviderTest(IsolatedAsyncioTestCase):
2626

2727
def setUp(self):
2828
self.input_ok = ConfigNode('test', {
@@ -44,9 +44,9 @@ def setUp(self):
4444
process_patch = patch('kubernetes_asyncio.config.exec_provider.asyncio.create_subprocess_exec')
4545
self.exec_mock = process_patch.start()
4646
self.process_mock = self.exec_mock.return_value
47-
self.process_mock.stdout.read = mock.CoroutineMock(return_value=self.output_ok)
48-
self.process_mock.stderr.read = mock.CoroutineMock(return_value='')
49-
self.process_mock.wait = mock.CoroutineMock(return_value=0)
47+
self.process_mock.stdout.read = AsyncMock(return_value=self.output_ok)
48+
self.process_mock.stderr.read = AsyncMock(return_value='')
49+
self.process_mock.wait = AsyncMock(return_value=0)
5050

5151
def tearDown(self):
5252
patch.stopall()

kubernetes_asyncio/config/google_auth_test.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from asynctest import TestCase, main
15+
from unittest import IsolatedAsyncioTestCase
1616

1717
from .google_auth import google_auth_credentials
1818

1919

20-
class TestGoogleAuth(TestCase):
20+
class TestGoogleAuth(IsolatedAsyncioTestCase):
2121

2222
async def test_google_auth_credentials(self):
2323

@@ -36,7 +36,3 @@ async def test_google_auth_credentials_exception(self):
3636

3737
with self.assertRaisesRegex(ValueError, "cmd-path, cmd-args are required."):
3838
await google_auth_credentials({})
39-
40-
41-
if __name__ == '__main__':
42-
main()

kubernetes_asyncio/config/kube_config_test.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import shutil
1919
import tempfile
2020
from types import SimpleNamespace
21+
from unittest import IsolatedAsyncioTestCase
22+
from unittest.mock import Mock, patch
2123

2224
import yaml
23-
from asynctest import Mock, TestCase, main, patch
2425
from six import PY3
2526

2627
from .config_exception import ConfigException
@@ -87,7 +88,7 @@ async def _return_async_value(val):
8788
return val
8889

8990

90-
class BaseTestCase(TestCase):
91+
class BaseTestCase(IsolatedAsyncioTestCase):
9192

9293
def setUp(self):
9394
self._temp_files = []
@@ -1139,7 +1140,3 @@ def test_save_changes(self):
11391140

11401141
# new token
11411142
self.assertEqual(provider.value['id-token'], "token-changed")
1142-
1143-
1144-
if __name__ == '__main__':
1145-
main()

kubernetes_asyncio/config/openid_test.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import asyncio
22
import json
33
from contextlib import contextmanager
4+
from unittest import IsolatedAsyncioTestCase
5+
from unittest.mock import patch
46

57
from aiohttp import web
68
from aiohttp.test_utils import (
79
TestClient as _TestClient, TestServer as _TestServer,
810
)
9-
from asynctest import TestCase, patch
1011

1112
from .config_exception import ConfigException
1213
from .openid import OpenIDRequestor
@@ -32,9 +33,7 @@ def respond_json(data):
3233
@contextmanager
3334
def working_client():
3435
loop = asyncio.get_event_loop()
35-
3636
app = web.Application()
37-
3837
app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
3938
app.router.add_post('/token', respond_json({'id-token': 'id-token-data', 'refresh-token': 'refresh-token-data'}))
4039

@@ -49,7 +48,6 @@ def working_client():
4948
def fail_well_known_client():
5049
loop = asyncio.get_event_loop()
5150
app = web.Application()
52-
5351
app.router.add_get('/.well-known/openid-configuration', make_responder(web.Response(status=500)))
5452

5553
with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
@@ -62,7 +60,6 @@ def fail_well_known_client():
6260
def fail_token_request_client():
6361
loop = asyncio.get_event_loop()
6462
app = web.Application()
65-
6663
app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
6764
app.router.add_post('/token', make_responder(web.Response(status=500)))
6865

@@ -73,7 +70,7 @@ def fail_token_request_client():
7370
yield client
7471

7572

76-
class OpenIDRequestorTest(TestCase):
73+
class OpenIDRequestorTest(IsolatedAsyncioTestCase):
7774

7875
def setUp(self):
7976
self.requestor = OpenIDRequestor(

kubernetes_asyncio/e2e_test/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def get_e2e_configuration():
2626
config.host = None
2727
if os.path.exists(
2828
os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)):
29-
loop = asyncio.get_event_loop()
29+
loop = asyncio.new_event_loop()
30+
asyncio.set_event_loop(loop)
3031
loop.run_until_complete(kube_config.load_kube_config(client_configuration=config))
3132
else:
3233
print('Unable to load config from %s' %

kubernetes_asyncio/e2e_test/test_api.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import os
1616
import uuid
17+
from unittest import IsolatedAsyncioTestCase
1718

18-
import asynctest
1919
import yaml
2020

2121
from kubernetes_asyncio import utils
@@ -25,7 +25,7 @@
2525
from kubernetes_asyncio.e2e_test import base
2626

2727

28-
class TestClientApi(asynctest.TestCase):
28+
class TestClientApi(IsolatedAsyncioTestCase):
2929

3030
@classmethod
3131
def setUpClass(cls):
@@ -136,7 +136,3 @@ async def test_create_daemonset(self):
136136

137137
options = v1_delete_options.V1DeleteOptions()
138138
resp = await api.delete_namespaced_daemon_set(name, 'default', body=options)
139-
140-
141-
if __name__ == '__main__':
142-
asynctest.main()

kubernetes_asyncio/e2e_test/test_batch.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
# under the License.
1414

1515
import uuid
16-
17-
import asynctest
16+
from unittest import IsolatedAsyncioTestCase
1817

1918
from kubernetes_asyncio.client import api_client
2019
from kubernetes_asyncio.client.api import batch_v1_api
2120
from kubernetes_asyncio.e2e_test import base
2221

2322

24-
class TestClientBatch(asynctest.TestCase):
23+
class TestClientBatch(IsolatedAsyncioTestCase):
2524

2625
@classmethod
2726
def setUpClass(cls):
@@ -57,7 +56,3 @@ async def test_job_apis(self):
5756

5857
resp = await api.delete_namespaced_job(
5958
name=name, body={}, namespace='default')
60-
61-
62-
if __name__ == '__main__':
63-
asynctest.main()

kubernetes_asyncio/e2e_test/test_client.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
import time
1616
import uuid
17-
18-
import asynctest
17+
from unittest import IsolatedAsyncioTestCase
1918

2019
from kubernetes_asyncio.client import api_client
2120
from kubernetes_asyncio.client.api import core_v1_api
@@ -28,7 +27,7 @@ def short_uuid():
2827
return id[-12:]
2928

3029

31-
class TestClient(asynctest.TestCase):
30+
class TestClient(IsolatedAsyncioTestCase):
3231

3332
@classmethod
3433
def setUpClass(cls):
@@ -229,7 +228,3 @@ async def test_node_apis(self):
229228
node = await api.read_node(name=item.metadata.name)
230229
self.assertTrue(len(node.metadata.labels) > 0)
231230
self.assertTrue(isinstance(node.metadata.labels, dict))
232-
233-
234-
if __name__ == '__main__':
235-
asynctest.main()

kubernetes_asyncio/stream/ws_client_test.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from asynctest import CoroutineMock, TestCase, patch
15+
from unittest import IsolatedAsyncioTestCase
16+
from unittest.mock import Mock, patch
1617

1718
from kubernetes_asyncio import client
1819
from kubernetes_asyncio.stream import WsApiClient
@@ -39,7 +40,7 @@ async def __anext__(self):
3940
return WsResponse(200, (chr(1) + 'mock').encode('utf-8'))
4041

4142

42-
class WSClientTest(TestCase):
43+
class WSClientTest(IsolatedAsyncioTestCase):
4344

4445
def test_websocket_client(self):
4546
for url, ws_url in [
@@ -55,7 +56,7 @@ def test_websocket_client(self):
5556
self.assertEqual(get_websocket_url(url), ws_url)
5657

5758
async def test_exec_ws(self):
58-
mock = CoroutineMock()
59+
mock = Mock()
5960
mock.RESTClientObject.return_value.pool_manager = mock
6061
mock.ws_connect.return_value = WsMock()
6162
with patch('kubernetes_asyncio.client.api_client.rest', mock):
@@ -82,7 +83,7 @@ async def test_exec_ws(self):
8283
)
8384

8485
async def test_exec_ws_with_heartbeat(self):
85-
mock = CoroutineMock()
86+
mock = Mock()
8687
mock.RESTClientObject.return_value.pool_manager = mock
8788
mock.ws_connect.return_value = WsMock()
8889
with patch('kubernetes_asyncio.client.api_client.rest', mock):
@@ -107,8 +108,3 @@ async def test_exec_ws_with_heartbeat(self):
107108
},
108109
heartbeat=30
109110
)
110-
111-
112-
if __name__ == '__main__':
113-
import asynctest
114-
asynctest.main()

kubernetes_asyncio/utils/create_from_yaml_test.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from asynctest import CoroutineMock, TestCase
15+
from unittest import IsolatedAsyncioTestCase
16+
from unittest.mock import AsyncMock
1617

1718
from kubernetes_asyncio.utils import create_from_dict, create_from_yaml
1819

1920

20-
class CreateFromYamlTest(TestCase):
21+
class CreateFromYamlTest(IsolatedAsyncioTestCase):
2122

2223
async def test_create_from_yaml(self):
23-
api_client = CoroutineMock()
24-
api_client.call_api = CoroutineMock()
24+
api_client = AsyncMock()
25+
api_client.call_api = AsyncMock()
2526
api_client.call_api.return_value = 'mock-value'
2627

2728
created = await create_from_yaml(api_client, 'examples/nginx-deployment.yaml')
@@ -34,8 +35,8 @@ async def test_create_from_yaml(self):
3435
self.assertEqual(created, [['mock-value']])
3536

3637
async def test_create_from_dict(self):
37-
api_client = CoroutineMock()
38-
api_client.call_api = CoroutineMock()
38+
api_client = AsyncMock()
39+
api_client.call_api = AsyncMock()
3940
api_client.call_api.return_value = 'mock-value'
4041

4142
created = await create_from_dict(api_client, {
@@ -54,8 +55,3 @@ async def test_create_from_dict(self):
5455

5556
# returned values
5657
self.assertEqual(created, ['mock-value'])
57-
58-
59-
if __name__ == '__main__':
60-
import asynctest
61-
asynctest.main()

0 commit comments

Comments
 (0)