Skip to content

Remove deprecated packages asynctest, codecov #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -32,21 +32,22 @@ jobs:

- name: Run unit tests
run: |
py.test -vvv -s --ignore=kubernetes_asyncio/e2e_test --cov-report=xml --cov=kubernetes_asyncio
# splitted into 2 steps because of problem with event-loop in aiohttp
py.test -vvv -s --ignore=kubernetes_asyncio/e2e_test --ignore=kubernetes_asyncio/test --cov-report=xml --cov=kubernetes_asyncio
py.test -vvv -s --cov-report=xml --cov=kubernetes_asyncio2 kubernetes_asyncio/test --cov-append

- name: Run e2e tests
run: |
scripts/kube-init.sh py.test -vvv -s kubernetes_asyncio/e2e_test

- name: Lint with flake8 and isort (only on the latest version of Python)
if: matrix.python-version == 3.10
if: matrix.python-version == 3.11
run: |
flake8
isort -c --diff .

- name: Send coverage report
if: matrix.python-version == 3.10
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == 3.11
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ You can run the style checks and tests with
```bash
flake8 kubernetes_asyncio/
isort --diff kubernetes_asyncio/
nosetests
py.test
```
12 changes: 6 additions & 6 deletions kubernetes_asyncio/config/exec_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

import json
import sys

from asynctest import ANY, TestCase, mock, patch
from unittest import IsolatedAsyncioTestCase
from unittest.mock import ANY, AsyncMock, patch

from .config_exception import ConfigException
from .exec_provider import ExecProvider
from .kube_config import ConfigNode


class ExecProviderTest(TestCase):
class ExecProviderTest(IsolatedAsyncioTestCase):

def setUp(self):
self.input_ok = ConfigNode('test', {
Expand All @@ -44,9 +44,9 @@ def setUp(self):
process_patch = patch('kubernetes_asyncio.config.exec_provider.asyncio.create_subprocess_exec')
self.exec_mock = process_patch.start()
self.process_mock = self.exec_mock.return_value
self.process_mock.stdout.read = mock.CoroutineMock(return_value=self.output_ok)
self.process_mock.stderr.read = mock.CoroutineMock(return_value='')
self.process_mock.wait = mock.CoroutineMock(return_value=0)
self.process_mock.stdout.read = AsyncMock(return_value=self.output_ok)
self.process_mock.stderr.read = AsyncMock(return_value='')
self.process_mock.wait = AsyncMock(return_value=0)

def tearDown(self):
patch.stopall()
Expand Down
8 changes: 2 additions & 6 deletions kubernetes_asyncio/config/google_auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from asynctest import TestCase, main
from unittest import IsolatedAsyncioTestCase

from .google_auth import google_auth_credentials


class TestGoogleAuth(TestCase):
class TestGoogleAuth(IsolatedAsyncioTestCase):

async def test_google_auth_credentials(self):

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

with self.assertRaisesRegex(ValueError, "cmd-path, cmd-args are required."):
await google_auth_credentials({})


if __name__ == '__main__':
main()
9 changes: 3 additions & 6 deletions kubernetes_asyncio/config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import shutil
import tempfile
from types import SimpleNamespace
from unittest import IsolatedAsyncioTestCase
from unittest.mock import Mock, patch

import yaml
from asynctest import Mock, TestCase, main, patch
from six import PY3

from .config_exception import ConfigException
Expand Down Expand Up @@ -87,7 +88,7 @@ async def _return_async_value(val):
return val


class BaseTestCase(TestCase):
class BaseTestCase(IsolatedAsyncioTestCase):

def setUp(self):
self._temp_files = []
Expand Down Expand Up @@ -1139,7 +1140,3 @@ def test_save_changes(self):

# new token
self.assertEqual(provider.value['id-token'], "token-changed")


if __name__ == '__main__':
main()
9 changes: 3 additions & 6 deletions kubernetes_asyncio/config/openid_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import asyncio
import json
from contextlib import contextmanager
from unittest import IsolatedAsyncioTestCase
from unittest.mock import patch

from aiohttp import web
from aiohttp.test_utils import (
TestClient as _TestClient, TestServer as _TestServer,
)
from asynctest import TestCase, patch

from .config_exception import ConfigException
from .openid import OpenIDRequestor
Expand All @@ -32,9 +33,7 @@ def respond_json(data):
@contextmanager
def working_client():
loop = asyncio.get_event_loop()

app = web.Application()

app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
app.router.add_post('/token', respond_json({'id-token': 'id-token-data', 'refresh-token': 'refresh-token-data'}))

Expand All @@ -49,7 +48,6 @@ def working_client():
def fail_well_known_client():
loop = asyncio.get_event_loop()
app = web.Application()

app.router.add_get('/.well-known/openid-configuration', make_responder(web.Response(status=500)))

with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
Expand All @@ -62,7 +60,6 @@ def fail_well_known_client():
def fail_token_request_client():
loop = asyncio.get_event_loop()
app = web.Application()

app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
app.router.add_post('/token', make_responder(web.Response(status=500)))

Expand All @@ -73,7 +70,7 @@ def fail_token_request_client():
yield client


class OpenIDRequestorTest(TestCase):
class OpenIDRequestorTest(IsolatedAsyncioTestCase):

def setUp(self):
self.requestor = OpenIDRequestor(
Expand Down
3 changes: 2 additions & 1 deletion kubernetes_asyncio/e2e_test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def get_e2e_configuration():
config.host = None
if os.path.exists(
os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)):
loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(kube_config.load_kube_config(client_configuration=config))
else:
print('Unable to load config from %s' %
Expand Down
8 changes: 2 additions & 6 deletions kubernetes_asyncio/e2e_test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import os
import uuid
from unittest import IsolatedAsyncioTestCase

import asynctest
import yaml

from kubernetes_asyncio import utils
Expand All @@ -25,7 +25,7 @@
from kubernetes_asyncio.e2e_test import base


class TestClientApi(asynctest.TestCase):
class TestClientApi(IsolatedAsyncioTestCase):

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -136,7 +136,3 @@ async def test_create_daemonset(self):

options = v1_delete_options.V1DeleteOptions()
resp = await api.delete_namespaced_daemon_set(name, 'default', body=options)


if __name__ == '__main__':
asynctest.main()
9 changes: 2 additions & 7 deletions kubernetes_asyncio/e2e_test/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
# under the License.

import uuid

import asynctest
from unittest import IsolatedAsyncioTestCase

from kubernetes_asyncio.client import api_client
from kubernetes_asyncio.client.api import batch_v1_api
from kubernetes_asyncio.e2e_test import base


class TestClientBatch(asynctest.TestCase):
class TestClientBatch(IsolatedAsyncioTestCase):

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -57,7 +56,3 @@ async def test_job_apis(self):

resp = await api.delete_namespaced_job(
name=name, body={}, namespace='default')


if __name__ == '__main__':
asynctest.main()
9 changes: 2 additions & 7 deletions kubernetes_asyncio/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import time
import uuid

import asynctest
from unittest import IsolatedAsyncioTestCase

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


class TestClient(asynctest.TestCase):
class TestClient(IsolatedAsyncioTestCase):

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -229,7 +228,3 @@ async def test_node_apis(self):
node = await api.read_node(name=item.metadata.name)
self.assertTrue(len(node.metadata.labels) > 0)
self.assertTrue(isinstance(node.metadata.labels, dict))


if __name__ == '__main__':
asynctest.main()
14 changes: 5 additions & 9 deletions kubernetes_asyncio/stream/ws_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from asynctest import CoroutineMock, TestCase, patch
from unittest import IsolatedAsyncioTestCase
from unittest.mock import Mock, patch

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


class WSClientTest(TestCase):
class WSClientTest(IsolatedAsyncioTestCase):

def test_websocket_client(self):
for url, ws_url in [
Expand All @@ -55,7 +56,7 @@ def test_websocket_client(self):
self.assertEqual(get_websocket_url(url), ws_url)

async def test_exec_ws(self):
mock = CoroutineMock()
mock = Mock()
mock.RESTClientObject.return_value.pool_manager = mock
mock.ws_connect.return_value = WsMock()
with patch('kubernetes_asyncio.client.api_client.rest', mock):
Expand All @@ -82,7 +83,7 @@ async def test_exec_ws(self):
)

async def test_exec_ws_with_heartbeat(self):
mock = CoroutineMock()
mock = Mock()
mock.RESTClientObject.return_value.pool_manager = mock
mock.ws_connect.return_value = WsMock()
with patch('kubernetes_asyncio.client.api_client.rest', mock):
Expand All @@ -107,8 +108,3 @@ async def test_exec_ws_with_heartbeat(self):
},
heartbeat=30
)


if __name__ == '__main__':
import asynctest
asynctest.main()
18 changes: 7 additions & 11 deletions kubernetes_asyncio/utils/create_from_yaml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from asynctest import CoroutineMock, TestCase
from unittest import IsolatedAsyncioTestCase
from unittest.mock import AsyncMock

from kubernetes_asyncio.utils import create_from_dict, create_from_yaml


class CreateFromYamlTest(TestCase):
class CreateFromYamlTest(IsolatedAsyncioTestCase):

async def test_create_from_yaml(self):
api_client = CoroutineMock()
api_client.call_api = CoroutineMock()
api_client = AsyncMock()
api_client.call_api = AsyncMock()
api_client.call_api.return_value = 'mock-value'

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

async def test_create_from_dict(self):
api_client = CoroutineMock()
api_client.call_api = CoroutineMock()
api_client = AsyncMock()
api_client.call_api = AsyncMock()
api_client.call_api.return_value = 'mock-value'

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

# returned values
self.assertEqual(created, ['mock-value'])


if __name__ == '__main__':
import asynctest
asynctest.main()
Loading