diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca33b927..1657192f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ on: jobs: lint: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Repository checkout uses: actions/checkout@v3 @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.6" + python-version: "3.8" - name: Install dependencies run: | @@ -29,12 +29,10 @@ jobs: tox -e lint test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: python-version: - - "3.6" - - "3.7" - "3.8" - "3.9" - "3.10" @@ -43,7 +41,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} diff --git a/integrate/test.py b/integrate/test.py index 13d57b4d..e120daa8 100644 --- a/integrate/test.py +++ b/integrate/test.py @@ -1,6 +1,6 @@ """Integration tests for `maas.client`.""" -from collections import Mapping +from collections.abc import Mapping from datetime import datetime from http import HTTPStatus import io diff --git a/maas/client/bones/__init__.py b/maas/client/bones/__init__.py index 7b5b8d31..cfb8dc85 100644 --- a/maas/client/bones/__init__.py +++ b/maas/client/bones/__init__.py @@ -337,9 +337,11 @@ def __init__(self, request, response, content, call): desc = "%s -> %s (%s)" % ( desc_for_request, desc_for_response, - desc_for_content - if len(desc_for_content) <= 50 - else (desc_for_content[:49] + "…"), + ( + desc_for_content + if len(desc_for_content) <= 50 + else (desc_for_content[:49] + "…") + ), ) super(CallError, self).__init__(desc) self.request = request @@ -460,7 +462,7 @@ async def dispatch(self, uri, body, headers): library. """ insecure = self.action.handler.session.insecure - connector = aiohttp.TCPConnector(verify_ssl=(not insecure)) + connector = aiohttp.TCPConnector(ssl=(not insecure)) session = aiohttp.ClientSession(connector=connector) async with session: response = await session.request( diff --git a/maas/client/bones/helpers.py b/maas/client/bones/helpers.py index a875b995..b041d029 100644 --- a/maas/client/bones/helpers.py +++ b/maas/client/bones/helpers.py @@ -40,7 +40,7 @@ async def fetch_api_description( ): """Fetch the API description from the remote MAAS instance.""" url_describe = urljoin(_ensure_url_string(url), "describe/") - connector = aiohttp.TCPConnector(verify_ssl=(not insecure)) + connector = aiohttp.TCPConnector(ssl=(not insecure)) session = aiohttp.ClientSession(connector=connector) async with session, session.get(url_describe) as response: if response.status != HTTPStatus.OK: @@ -270,11 +270,11 @@ def check_response_is_okay(response): if response.status != HTTPStatus.OK: raise RemoteError( "{0} -> {1.status} {1.reason}".format( - response.url_obj.human_repr(), response + response.url.human_repr(), response ) ) - connector = aiohttp.TCPConnector(verify_ssl=(not insecure)) + connector = aiohttp.TCPConnector(ssl=(not insecure)) session = aiohttp.ClientSession(connector=connector) async with session: # Check that this server supports `authenticate-api`. diff --git a/maas/client/errors.py b/maas/client/errors.py index 963339ff..e0698fdb 100644 --- a/maas/client/errors.py +++ b/maas/client/errors.py @@ -1,4 +1,4 @@ -""" Custom errors for libmaas """ +"""Custom errors for libmaas""" __all__ = ["MAASException", "OperationNotAllowed"] diff --git a/maas/client/flesh/tests/test_controllers.py b/maas/client/flesh/tests/test_controllers.py index e5e7e411..f0a21ff1 100644 --- a/maas/client/flesh/tests/test_controllers.py +++ b/maas/client/flesh/tests/test_controllers.py @@ -73,7 +73,7 @@ def test_returns_table_with_controllers(self): output = yaml.safe_load( cmd.execute(origin, options, target=tabular.RenderTarget.yaml) ) - self.assertEquals( + self.assertEqual( [ {"name": "hostname", "title": "Hostname"}, {"name": "node_type", "title": "Type"}, @@ -93,7 +93,7 @@ def test_returns_table_with_controllers(self): } for controller in racks + regions } - self.assertEquals( + self.assertEqual( sorted(controller_output.values(), key=itemgetter("hostname")), output["data"], ) diff --git a/maas/client/flesh/tests/test_devices.py b/maas/client/flesh/tests/test_devices.py index 2b355725..c8b54624 100644 --- a/maas/client/flesh/tests/test_devices.py +++ b/maas/client/flesh/tests/test_devices.py @@ -52,7 +52,7 @@ def test_returns_table_with_devices(self): output = yaml.safe_load( cmd.execute(origin, options, target=tabular.RenderTarget.yaml) ) - self.assertEquals( + self.assertEqual( [ {"name": "hostname", "title": "Hostname"}, {"name": "owner", "title": "Owner"}, @@ -76,7 +76,7 @@ def test_returns_table_with_devices(self): ], key=itemgetter("hostname"), ) - self.assertEquals(devices_output, output["data"]) + self.assertEqual(devices_output, output["data"]) def test_calls_handler_with_hostnames(self): origin = make_origin() diff --git a/maas/client/flesh/tests/test_machines.py b/maas/client/flesh/tests/test_machines.py index 6e3c9412..51247d8f 100644 --- a/maas/client/flesh/tests/test_machines.py +++ b/maas/client/flesh/tests/test_machines.py @@ -60,7 +60,7 @@ def test_returns_table_with_machines(self): output = yaml.safe_load( cmd.execute(origin, options, target=tabular.RenderTarget.yaml) ) - self.assertEquals( + self.assertEqual( [ {"name": "hostname", "title": "Hostname"}, {"name": "power", "title": "Power"}, @@ -91,7 +91,7 @@ def test_returns_table_with_machines(self): ], key=itemgetter("hostname"), ) - self.assertEquals(machines_output, output["data"]) + self.assertEqual(machines_output, output["data"]) def test_calls_handler_with_hostnames(self): origin = make_origin() diff --git a/maas/client/flesh/tests/test_nodes.py b/maas/client/flesh/tests/test_nodes.py index 5dce2604..ccb5e720 100644 --- a/maas/client/flesh/tests/test_nodes.py +++ b/maas/client/flesh/tests/test_nodes.py @@ -51,7 +51,7 @@ def test_returns_table_with_nodes(self): output = yaml.safe_load( cmd.execute(origin, options, target=tabular.RenderTarget.yaml) ) - self.assertEquals( + self.assertEqual( [ {"name": "hostname", "title": "Hostname"}, {"name": "node_type", "title": "Type"}, @@ -65,7 +65,7 @@ def test_returns_table_with_nodes(self): ], key=itemgetter("hostname"), ) - self.assertEquals(nodes_output, output["data"]) + self.assertEqual(nodes_output, output["data"]) def test_calls_handler_with_hostnames(self): origin = make_origin() diff --git a/maas/client/utils/tests/test.py b/maas/client/utils/tests/test.py index acd8e271..57f16e40 100644 --- a/maas/client/utils/tests/test.py +++ b/maas/client/utils/tests/test.py @@ -550,4 +550,4 @@ class TestRemoveNone(TestCase): def test_removes_all_None_values(self): data = {"None": None, "another_None": None, "keep": "value"} - self.assertEquals({"keep": "value"}, utils.remove_None(data)) + self.assertEqual({"keep": "value"}, utils.remove_None(data)) diff --git a/maas/client/utils/tests/test_diff.py b/maas/client/utils/tests/test_diff.py index 8b30c01e..c26b4ca8 100644 --- a/maas/client/utils/tests/test_diff.py +++ b/maas/client/utils/tests/test_diff.py @@ -26,13 +26,13 @@ class TestCalculateDictDiff(TestCase): def test_calcs_no_difference(self): orig_data = {"key1": "value1", "key2": "value2"} new_data = copy.deepcopy(orig_data) - self.assertEquals({}, calculate_dict_diff(orig_data, new_data)) + self.assertEqual({}, calculate_dict_diff(orig_data, new_data)) def test_calcs_changed_value(self): orig_data = {"key1": "value1", "key2": "value2"} new_data = copy.deepcopy(orig_data) new_data["key2"] = "new_value" - self.assertEquals( + self.assertEqual( {"key2": "new_value"}, calculate_dict_diff(orig_data, new_data) ) @@ -40,13 +40,13 @@ def test_calcs_deleted_value(self): orig_data = {"key1": "value1", "key2": "value2"} new_data = copy.deepcopy(orig_data) del new_data["key2"] - self.assertEquals({"key2": ""}, calculate_dict_diff(orig_data, new_data)) + self.assertEqual({"key2": ""}, calculate_dict_diff(orig_data, new_data)) def test_calcs_changes_and_deleted(self): orig_data = {"key1": "value1", "key2": "value2"} new_data = copy.deepcopy(orig_data) new_data["key1"] = "new_value" del new_data["key2"] - self.assertEquals( + self.assertEqual( {"key1": "new_value", "key2": ""}, calculate_dict_diff(orig_data, new_data) ) diff --git a/maas/client/viscera/boot_resources.py b/maas/client/viscera/boot_resources.py index 2ab51c40..c4288511 100644 --- a/maas/client/viscera/boot_resources.py +++ b/maas/client/viscera/boot_resources.py @@ -184,7 +184,7 @@ async def _upload_chunks( uploaded_size = 0 insecure = cls._handler.session.insecure - connector = aiohttp.TCPConnector(verify_ssl=(not insecure)) + connector = aiohttp.TCPConnector(ssl=(not insecure)) session = aiohttp.ClientSession(connector=connector) async with session: diff --git a/maas/client/viscera/testing/__init__.py b/maas/client/viscera/testing/__init__.py index f11ed71e..85ff4c0c 100644 --- a/maas/client/viscera/testing/__init__.py +++ b/maas/client/viscera/testing/__init__.py @@ -1,4 +1,4 @@ -""" Testing framework for maas.client.viscera """ +"""Testing framework for maas.client.viscera""" __all__ = ["bind"] diff --git a/maas/client/viscera/tests/test.py b/maas/client/viscera/tests/test.py index 62611720..cf100802 100644 --- a/maas/client/viscera/tests/test.py +++ b/maas/client/viscera/tests/test.py @@ -480,7 +480,7 @@ def test__can_access_pk_attributes_when_unloaded(self): object_pk = randint(0, 20) object_a = object_type(object_pk) self.assertFalse(object_a.loaded) - self.assertEquals(object_pk, object_a.pk) + self.assertEqual(object_pk, object_a.pk) def test__can_access_alt_pk_attributes_when_unloaded(self): object_type = type( @@ -495,7 +495,7 @@ def test__can_access_alt_pk_attributes_when_unloaded(self): object_alt_pk = randint(0, 20) object_a = object_type({"alt_pk_d": object_alt_pk, "__incomplete__": True}) self.assertFalse(object_a.loaded) - self.assertEquals(object_alt_pk, object_a.alt_pk) + self.assertEqual(object_alt_pk, object_a.alt_pk) def test__can_access_attributes_when_loaded(self): object_type = type( @@ -507,7 +507,7 @@ def test__can_access_attributes_when_loaded(self): object_name = make_name("name") object_a = object_type({"pk_d": object_pk, "name": object_name}) self.assertTrue(object_a.loaded) - self.assertEquals(object_name, object_a.name) + self.assertEqual(object_name, object_a.name) def test__equal_when_data_matches(self): data = {"key": make_name("value")} @@ -1210,7 +1210,7 @@ def test__init__requires_str_or_Object_class(self): ObjectFieldRelatedSet("name", ObjectSet) def test_datum_to_value_returns_empty_list_on_None(self): - self.assertEquals( + self.assertEqual( ObjectFieldRelatedSet("name", "class").datum_to_value(object(), None), [] ) @@ -1232,7 +1232,7 @@ def test_datum_to_value_converts_to_set_of_bound_class(self): field = ObjectFieldRelatedSet("related_ids", "RelObjectSet") rel_ids = range(5) rel_object_set = field.datum_to_value(instance, rel_ids) - self.assertEquals(5, len(rel_object_set)) + self.assertEqual(5, len(rel_object_set)) self.assertIsInstance(rel_object_set[0], rel_object_type) self.assertFalse(rel_object_set[0].loaded) self.assertThat( @@ -1253,7 +1253,7 @@ def test_datum_to_value_uses_reverse_name(self): field = ObjectFieldRelatedSet("related_ids", "RelObjectSet", reverse="reverse") rel_ids = range(5) rel_object_set = field.datum_to_value(instance, rel_ids) - self.assertEquals(5, len(rel_object_set)) + self.assertEqual(5, len(rel_object_set)) self.assertIsInstance(rel_object_set[0], rel_object_type) self.assertFalse(rel_object_set[0].loaded) self.assertThat( @@ -1273,7 +1273,7 @@ def test_datum_to_value_doesnt_include_reverse(self): field = ObjectFieldRelatedSet("related_ids", "RelObjectSet", reverse=None) rel_ids = range(5) rel_object_set = field.datum_to_value(instance, rel_ids) - self.assertEquals(5, len(rel_object_set)) + self.assertEqual(5, len(rel_object_set)) self.assertIsInstance(rel_object_set[0], rel_object_type) self.assertFalse(rel_object_set[0].loaded) self.assertThat(rel_object_set[0]._data, Equals({"pk_d": rel_ids[0]})) @@ -1297,7 +1297,7 @@ def test_datum_to_value_wraps_managed_create(self): rel_ids = range(5) rel_object_set = field.datum_to_value(instance, rel_ids) rel_object_set.create() - self.assertEquals( + self.assertEqual( "RelObjectSet.Managed#InstObject", type(rel_object_set).__name__ ) self.assertThat(create_mock.call_args_list, Equals([call(instance)])) diff --git a/maas/client/viscera/tests/test_bcache_cache_sets.py b/maas/client/viscera/tests/test_bcache_cache_sets.py index f7bba667..4f4fb00a 100644 --- a/maas/client/viscera/tests/test_bcache_cache_sets.py +++ b/maas/client/viscera/tests/test_bcache_cache_sets.py @@ -36,7 +36,7 @@ def test__read_bad_node_type(self): error = self.assertRaises( TypeError, BcacheCacheSets.read, random.randint(0, 100) ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): BcacheCacheSets = make_origin().BcacheCacheSets @@ -87,7 +87,7 @@ def test__create_bad_node_type(self): random.randint(0, 100), origin.BlockDevice({}), ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__create_bad_cache_device_type(self): BcacheCacheSets = make_origin().BcacheCacheSets @@ -97,7 +97,7 @@ def test__create_bad_cache_device_type(self): make_string_without_spaces(), random.randint(0, 100), ) - self.assertEquals( + self.assertEqual( "cache_device must be a BlockDevice or Partition, not int", str(error) ) @@ -141,7 +141,7 @@ def test__read_bad_node_type(self): random.randint(0, 100), random.randint(0, 100), ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): BcacheCacheSet = make_origin().BcacheCacheSet diff --git a/maas/client/viscera/tests/test_bcaches.py b/maas/client/viscera/tests/test_bcaches.py index 10271ce9..98c5732f 100644 --- a/maas/client/viscera/tests/test_bcaches.py +++ b/maas/client/viscera/tests/test_bcaches.py @@ -92,7 +92,7 @@ def test__get_by_name(self): def test__read_bad_node_type(self): Bcaches = make_origin().Bcaches error = self.assertRaises(TypeError, Bcaches.read, random.randint(0, 100)) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): Bcaches = make_origin().Bcaches @@ -158,7 +158,7 @@ def test__create_bad_node_type(self): random.randint(0, 100), CacheMode.WRITETHROUGH, ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__create_bad_cache_device_type(self): Bcaches = make_origin().Bcaches @@ -171,7 +171,7 @@ def test__create_bad_cache_device_type(self): random.randint(0, 100), CacheMode.WRITETHROUGH, ) - self.assertEquals( + self.assertEqual( "backing_device must be a BlockDevice or Partition, not int", str(error) ) @@ -187,7 +187,7 @@ def test__create_bad_cache_set_type(self): make_string_without_spaces(), CacheMode.WRITETHROUGH, ) - self.assertEquals( + self.assertEqual( "cache_set must be a BcacheCacheSet or int, not str", str(error) ) @@ -203,7 +203,7 @@ def test__create_bad_cache_mode_type(self): random.randint(0, 100), "writethrough", ) - self.assertEquals("cache_mode must be a CacheMode, not str", str(error)) + self.assertEqual("cache_mode must be a CacheMode, not str", str(error)) def test__create_with_block_device(self): origin = make_origin() @@ -257,7 +257,7 @@ def test__read_bad_node_type(self): error = self.assertRaises( TypeError, Bcache.read, random.randint(0, 100), random.randint(0, 100) ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): Bcache = make_origin().Bcache diff --git a/maas/client/viscera/tests/test_block_devices.py b/maas/client/viscera/tests/test_block_devices.py index 3775a2c3..2e54edaa 100644 --- a/maas/client/viscera/tests/test_block_devices.py +++ b/maas/client/viscera/tests/test_block_devices.py @@ -63,7 +63,7 @@ def test__get_by_name(self): def test__read_bad_node_type(self): BlockDevices = make_origin().BlockDevices error = self.assertRaises(TypeError, BlockDevices.read, random.randint(0, 100)) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): BlockDevices = make_origin().BlockDevices @@ -114,7 +114,7 @@ def test__create_bad_node_type(self): size=(4096 * 1024), block_size=512, ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__create_missing_size(self): BlockDevices = make_origin().BlockDevices @@ -127,7 +127,7 @@ def test__create_missing_size(self): serial="QEMU0001", block_size=512, ) - self.assertEquals("size must be provided and greater than zero.", str(error)) + self.assertEqual("size must be provided and greater than zero.", str(error)) def test__create_negative_size(self): BlockDevices = make_origin().BlockDevices @@ -141,7 +141,7 @@ def test__create_negative_size(self): size=-1, block_size=512, ) - self.assertEquals("size must be provided and greater than zero.", str(error)) + self.assertEqual("size must be provided and greater than zero.", str(error)) def test__create_missing_block_size(self): BlockDevices = make_origin().BlockDevices @@ -155,7 +155,7 @@ def test__create_missing_block_size(self): size=(4096 * 1024), block_size=None, ) - self.assertEquals( + self.assertEqual( "block_size must be provided and greater than zero.", str(error) ) @@ -171,7 +171,7 @@ def test__create_negative_block_size(self): size=(4096 * 1024), block_size=-1, ) - self.assertEquals( + self.assertEqual( "block_size must be provided and greater than zero.", str(error) ) @@ -185,7 +185,7 @@ def test__create_model_requires_serial(self): model="QEMU", size=(4096 * 1024), ) - self.assertEquals("serial must be provided when model is provided.", str(error)) + self.assertEqual("serial must be provided when model is provided.", str(error)) def test__create_serial_requires_model(self): BlockDevices = make_origin().BlockDevices @@ -197,7 +197,7 @@ def test__create_serial_requires_model(self): serial="QEMU0001", size=(4096 * 1024), ) - self.assertEquals("model must be provided when serial is provided.", str(error)) + self.assertEqual("model must be provided when serial is provided.", str(error)) def test__create_requires_model_and_serial_or_id_path(self): BlockDevices = make_origin().BlockDevices @@ -208,7 +208,7 @@ def test__create_requires_model_and_serial_or_id_path(self): "sda", size=(4096 * 1024), ) - self.assertEquals( + self.assertEqual( "Either model/serial is provided or id_path must be provided.", str(error) ) @@ -278,7 +278,7 @@ def test__read_bad_node_type(self): error = self.assertRaises( TypeError, BlockDevice.read, random.randint(0, 100), random.randint(0, 100) ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): BlockDevice = make_origin().BlockDevice diff --git a/maas/client/viscera/tests/test_boot_resources.py b/maas/client/viscera/tests/test_boot_resources.py index 796f6862..acd8ed84 100644 --- a/maas/client/viscera/tests/test_boot_resources.py +++ b/maas/client/viscera/tests/test_boot_resources.py @@ -153,21 +153,21 @@ def test__read(self): ] resources = BootResources.read() - self.assertEquals(2, len(resources)) + self.assertEqual(2, len(resources)) def test__start_import(self): BootResources = make_origin().BootResources import_action = getattr(BootResources._handler, "import") import_action.return_value = sentinel.result - self.assertEquals(sentinel.result, BootResources.start_import()) + self.assertEqual(sentinel.result, BootResources.start_import()) import_action.assert_called_once_with() def test__stop_import(self): BootResources = make_origin().BootResources BootResources._handler.stop_import.return_value = sentinel.result - self.assertEquals(sentinel.result, BootResources.stop_import()) + self.assertEqual(sentinel.result, BootResources.stop_import()) BootResources._handler.stop_import.assert_called_once_with() def test__create_raises_ValueError_when_name_missing_slash(self): @@ -175,7 +175,7 @@ def test__create_raises_ValueError_when_name_missing_slash(self): buf = io.BytesIO(b"") error = self.assertRaises(ValueError, BootResources.create, "", "", buf) - self.assertEquals("name must be in format os/release; missing '/'", str(error)) + self.assertEqual("name must be in format os/release; missing '/'", str(error)) def test__create_raises_ValueError_when_architecture_missing_slash(self): BootResources = make_origin().BootResources @@ -184,7 +184,7 @@ def test__create_raises_ValueError_when_architecture_missing_slash(self): error = self.assertRaises( ValueError, BootResources.create, "os/release", "", buf ) - self.assertEquals( + self.assertEqual( "architecture must be in format arch/subarch; missing '/'", str(error) ) @@ -196,7 +196,7 @@ def test__create_raises_ValueError_when_content_cannot_be_read(self): error = self.assertRaises( ValueError, BootResources.create, "os/release", "arch/subarch", buf ) - self.assertEquals("content must be readable", str(error)) + self.assertEqual("content must be readable", str(error)) def test__create_raises_ValueError_when_content_cannot_seek(self): BootResources = make_origin().BootResources @@ -206,7 +206,7 @@ def test__create_raises_ValueError_when_content_cannot_seek(self): error = self.assertRaises( ValueError, BootResources.create, "os/release", "arch/subarch", buf ) - self.assertEquals("content must be seekable", str(error)) + self.assertEqual("content must be seekable", str(error)) def test__create_raises_ValueError_when_chunk_size_is_zero(self): BootResources = make_origin().BootResources @@ -220,7 +220,7 @@ def test__create_raises_ValueError_when_chunk_size_is_zero(self): buf, chunk_size=0, ) - self.assertEquals("chunk_size must be greater than 0, not 0", str(error)) + self.assertEqual("chunk_size must be greater than 0, not 0", str(error)) def test__create_raises_ValueError_when_chunk_size_is_less_than_zero(self): BootResources = make_origin().BootResources @@ -234,7 +234,7 @@ def test__create_raises_ValueError_when_chunk_size_is_less_than_zero(self): buf, chunk_size=-1, ) - self.assertEquals("chunk_size must be greater than 0, not -1", str(error)) + self.assertEqual("chunk_size must be greater than 0, not -1", str(error)) def test__create_calls_create_on_handler_does_nothing_if_complete(self): resource_id = random.randint(0, 100) @@ -432,14 +432,14 @@ def test__create_uploads_in_chunks_and_reloads_resource(self): ) for i in range(0, len(data), chunk_size) ] - self.assertEquals(calls, put.call_args_list) + self.assertEqual(calls, put.call_args_list) # Check that progress handler was called on each chunk. calls = [ call(len(data[: chunk_size + i]) / len(data)) for i in range(0, len(data), chunk_size) ] - self.assertEquals(calls, progress_handler.call_args_list) + self.assertEqual(calls, progress_handler.call_args_list) def test__create_raises_CallError_on_chunk_upload_failure(self): resource_id = random.randint(0, 100) diff --git a/maas/client/viscera/tests/test_boot_source_selections.py b/maas/client/viscera/tests/test_boot_source_selections.py index 54370f75..615e6dc0 100644 --- a/maas/client/viscera/tests/test_boot_source_selections.py +++ b/maas/client/viscera/tests/test_boot_source_selections.py @@ -134,12 +134,12 @@ def test__read(self): ] selections = BootSourceSelections.read(source) - self.assertEquals(2, len(selections)) - self.assertEquals( + self.assertEqual(2, len(selections)) + self.assertEqual( origin.BootSource(source.id, {"bootsourceselection": selections[0]}), selections[0].boot_source, ) - self.assertEquals( + self.assertEqual( origin.BootSource(source.id, {"bootsourceselection": selections[1]}), selections[1].boot_source, ) diff --git a/maas/client/viscera/tests/test_boot_sources.py b/maas/client/viscera/tests/test_boot_sources.py index 943afc19..37d25c89 100644 --- a/maas/client/viscera/tests/test_boot_sources.py +++ b/maas/client/viscera/tests/test_boot_sources.py @@ -87,7 +87,7 @@ def test__read(self): ] sources = BootSources.read() - self.assertEquals(2, len(sources)) + self.assertEqual(2, len(sources)) def test__create_calls_create_with_keyring_filename(self): source_id = random.randint(0, 100) diff --git a/maas/client/viscera/tests/test_files.py b/maas/client/viscera/tests/test_files.py index 887ad34b..37709ff8 100644 --- a/maas/client/viscera/tests/test_files.py +++ b/maas/client/viscera/tests/test_files.py @@ -27,7 +27,7 @@ def test__read(self): origin.Files._handler.read.return_value = data resources = origin.Files.read() - self.assertEquals(2, len(resources)) + self.assertEqual(2, len(resources)) self.assertThat(resources, IsInstance(origin.Files)) self.assertThat(resources, AllMatch(IsInstance(origin.File))) self.assertThat( diff --git a/maas/client/viscera/tests/test_interfaces.py b/maas/client/viscera/tests/test_interfaces.py index 2eeabd87..5adc8281 100644 --- a/maas/client/viscera/tests/test_interfaces.py +++ b/maas/client/viscera/tests/test_interfaces.py @@ -54,7 +54,7 @@ class TestInterfaces(TestCase): def test__read_bad_node_type(self): Interfaces = make_origin().Interfaces error = self.assertRaises(TypeError, Interfaces.read, random.randint(0, 100)) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__read_with_system_id(self): Interfaces = make_origin().Interfaces @@ -95,7 +95,7 @@ def test__read_with_Node(self): def test__create_bad_node_type(self): Interfaces = make_origin().Interfaces error = self.assertRaises(TypeError, Interfaces.create, random.randint(0, 100)) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__create_bad_vlan_type(self): Interfaces = make_origin().Interfaces @@ -105,7 +105,7 @@ def test__create_bad_vlan_type(self): make_string_without_spaces(), vlan=make_string_without_spaces(), ) - self.assertEquals("vlan must be a Vlan or int, not str", str(error)) + self.assertEqual("vlan must be a Vlan or int, not str", str(error)) def test__create_bad_interface_type_type(self): Interfaces = make_origin().Interfaces @@ -115,16 +115,14 @@ def test__create_bad_interface_type_type(self): make_string_without_spaces(), interface_type=make_string_without_spaces(), ) - self.assertEquals( - "interface_type must be an InterfaceType, not str", str(error) - ) + self.assertEqual("interface_type must be an InterfaceType, not str", str(error)) def test__create_physical_requires_mac_address(self): Interfaces = make_origin().Interfaces error = self.assertRaises( ValueError, Interfaces.create, make_string_without_spaces() ) - self.assertEquals("mac_address required for physical interface", str(error)) + self.assertEqual("mac_address required for physical interface", str(error)) def test__create_physical_with_all_values(self): origin = make_origin() @@ -220,7 +218,7 @@ def test__create_bond_fails_with_parent(self): name=make_string_without_spaces(), parent=make_string_without_spaces(), ) - self.assertEquals("use parents not parent for bond interface", str(error)) + self.assertEqual("use parents not parent for bond interface", str(error)) def test__create_bond_fails_parents_not_iterable(self): Interfaces = make_origin().Interfaces @@ -232,7 +230,7 @@ def test__create_bond_fails_parents_not_iterable(self): name=make_string_without_spaces(), parents=random.randint(1, 20), ) - self.assertEquals("parents must be a iterable, not int", str(error)) + self.assertEqual("parents must be a iterable, not int", str(error)) def test__create_bond_fails_parents_is_not_Interface_or_int(self): Interfaces = make_origin().Interfaces @@ -244,7 +242,7 @@ def test__create_bond_fails_parents_is_not_Interface_or_int(self): name=make_string_without_spaces(), parents=[make_string_without_spaces()], ) - self.assertEquals("parent[0] must be an Interface or int, not str", str(error)) + self.assertEqual("parent[0] must be an Interface or int, not str", str(error)) def test__create_bond_fails_name_missing(self): Interfaces = make_origin().Interfaces @@ -255,7 +253,7 @@ def test__create_bond_fails_name_missing(self): InterfaceType.BOND, parents=[random.randint(1, 20)], ) - self.assertEquals("name is required for bond interface", str(error)) + self.assertEqual("name is required for bond interface", str(error)) def test__create_bond_with_all_values(self): origin = make_origin() @@ -395,7 +393,7 @@ def test__create_vlan_fails_with_parents(self): InterfaceType.VLAN, parents=[make_string_without_spaces()], ) - self.assertEquals("use parent not parents for VLAN interface", str(error)) + self.assertEqual("use parent not parents for VLAN interface", str(error)) def test__create_vlan_fails_without_parent(self): Interfaces = make_origin().Interfaces @@ -405,7 +403,7 @@ def test__create_vlan_fails_without_parent(self): make_string_without_spaces(), InterfaceType.VLAN, ) - self.assertEquals("parent is required for VLAN interface", str(error)) + self.assertEqual("parent is required for VLAN interface", str(error)) def test__create_vlan_fails_parent_wrong_type(self): Interfaces = make_origin().Interfaces @@ -416,7 +414,7 @@ def test__create_vlan_fails_parent_wrong_type(self): InterfaceType.VLAN, parent=make_string_without_spaces(), ) - self.assertEquals("parent must be an Interface or int, not str", str(error)) + self.assertEqual("parent must be an Interface or int, not str", str(error)) def test__create_vlan_fails_without_vlan(self): Interfaces = make_origin().Interfaces @@ -427,7 +425,7 @@ def test__create_vlan_fails_without_vlan(self): InterfaceType.VLAN, parent=random.randint(1, 10), ) - self.assertEquals("vlan is required for VLAN interface", str(error)) + self.assertEqual("vlan is required for VLAN interface", str(error)) def test__create_vlan_with_all_values(self): origin = make_origin() @@ -517,7 +515,7 @@ def test__create_bridge_fails_with_parents(self): InterfaceType.BRIDGE, parents=[make_string_without_spaces()], ) - self.assertEquals("use parent not parents for bridge interface", str(error)) + self.assertEqual("use parent not parents for bridge interface", str(error)) def test__create_bridge_fails_without_parent(self): Interfaces = make_origin().Interfaces @@ -527,7 +525,7 @@ def test__create_bridge_fails_without_parent(self): make_string_without_spaces(), InterfaceType.BRIDGE, ) - self.assertEquals("parent is required for bridge interface", str(error)) + self.assertEqual("parent is required for bridge interface", str(error)) def test__create_bridge_fails_parent_wrong_type(self): Interfaces = make_origin().Interfaces @@ -538,7 +536,7 @@ def test__create_bridge_fails_parent_wrong_type(self): InterfaceType.BRIDGE, parent=make_string_without_spaces(), ) - self.assertEquals("parent must be an Interface or int, not str", str(error)) + self.assertEqual("parent must be an Interface or int, not str", str(error)) def test__create_bridge_fails_missing_name(self): Interfaces = make_origin().Interfaces @@ -549,7 +547,7 @@ def test__create_bridge_fails_missing_name(self): InterfaceType.BRIDGE, parent=random.randint(1, 10), ) - self.assertEquals("name is required for bridge interface", str(error)) + self.assertEqual("name is required for bridge interface", str(error)) def test__create_bridge_with_all_values(self): origin = make_origin() @@ -664,7 +662,7 @@ def test__create_unknown_fails(self): make_string_without_spaces(), InterfaceType.UNKNOWN, ) - self.assertEquals( + self.assertEqual( "cannot create an interface of type: %s" % InterfaceType.UNKNOWN, str(error) ) @@ -679,7 +677,7 @@ def test__by_name(self): {"system_id": system_id, "id": random.randint(0, 100), "name": "eth1"} ) interfaces = Interfaces([eth0_Interface, eth1_Interface]) - self.assertEquals( + self.assertEqual( {"eth0": eth0_Interface, "eth1": eth1_Interface}, interfaces.by_name ) @@ -695,7 +693,7 @@ def test__get_by_name(self): ) interfaces = Interfaces([eth0_Interface, eth1_Interface]) eth0 = interfaces.get_by_name("eth0") - self.assertEquals(eth0, eth0_Interface) + self.assertEqual(eth0, eth0_Interface) class TestInterface(TestCase): @@ -741,7 +739,7 @@ def test__interface_read_TypeError(self): error = self.assertRaises( TypeError, Interface.read, random.randint(0, 100), random.randint(0, 100) ) - self.assertEquals("node must be a Node or str, not int", str(error)) + self.assertEqual("node must be a Node or str, not int", str(error)) def test__interface_save_tags(self): Interface = make_origin().Interface @@ -952,7 +950,7 @@ def test__interface_disconnect(self): Interface._handler.disconnect.assert_called_once_with( system_id=system_id, id=interface_data["id"] ) - self.assertEquals([], list(interface.links)) + self.assertEqual([], list(interface.links)) def test__interface_links_create_raises_TypeError_no_Interface(self): origin = make_origin() @@ -960,7 +958,7 @@ def test__interface_links_create_raises_TypeError_no_Interface(self): error = self.assertRaises( TypeError, InterfaceLinks.create, random.randint(0, 1000), LinkMode.AUTO ) - self.assertEquals("interface must be an Interface, not int", str(error)) + self.assertEqual("interface must be an Interface, not int", str(error)) def test__interface_links_create_raises_TypeError_no_LinkMode(self): origin = make_origin() @@ -971,7 +969,7 @@ def test__interface_links_create_raises_TypeError_no_LinkMode(self): error = self.assertRaises( TypeError, InterfaceLinks.create, interface, LinkMode.AUTO.value ) - self.assertEquals("mode must be a LinkMode, not str", str(error)) + self.assertEqual("mode must be a LinkMode, not str", str(error)) def test__interface_links_create_raises_TypeError_no_Subnet(self): origin = make_origin() @@ -986,7 +984,7 @@ def test__interface_links_create_raises_TypeError_no_Subnet(self): LinkMode.AUTO, subnet=make_string_without_spaces(), ) - self.assertEquals("subnet must be a Subnet or int, not str", str(error)) + self.assertEqual("subnet must be a Subnet or int, not str", str(error)) def test__interface_links_create_raises_ValueError_AUTO_no_Subnet(self): origin = make_origin() @@ -997,7 +995,7 @@ def test__interface_links_create_raises_ValueError_AUTO_no_Subnet(self): error = self.assertRaises( ValueError, InterfaceLinks.create, interface, LinkMode.AUTO ) - self.assertEquals("subnet is required for %s" % LinkMode.AUTO, str(error)) + self.assertEqual("subnet is required for %s" % LinkMode.AUTO, str(error)) def test__interface_links_create_raises_ValueError_STATIC_no_Subnet(self): origin = make_origin() @@ -1008,7 +1006,7 @@ def test__interface_links_create_raises_ValueError_STATIC_no_Subnet(self): error = self.assertRaises( ValueError, InterfaceLinks.create, interface, LinkMode.STATIC ) - self.assertEquals("subnet is required for %s" % LinkMode.STATIC, str(error)) + self.assertEqual("subnet is required for %s" % LinkMode.STATIC, str(error)) def test__interface_links_create_raises_ValueError_LINK_UP_gateway(self): origin = make_origin() @@ -1023,7 +1021,7 @@ def test__interface_links_create_raises_ValueError_LINK_UP_gateway(self): LinkMode.LINK_UP, default_gateway=True, ) - self.assertEquals( + self.assertEqual( "cannot set as default_gateway for %s" % LinkMode.LINK_UP, str(error) ) @@ -1040,7 +1038,7 @@ def test__interface_links_create_raises_ValueError_DHCP_gateway(self): LinkMode.DHCP, default_gateway=True, ) - self.assertEquals( + self.assertEqual( "cannot set as default_gateway for %s" % LinkMode.DHCP, str(error) ) diff --git a/maas/client/viscera/tests/test_ipranges.py b/maas/client/viscera/tests/test_ipranges.py index 5732da9f..dbdf360f 100644 --- a/maas/client/viscera/tests/test_ipranges.py +++ b/maas/client/viscera/tests/test_ipranges.py @@ -51,7 +51,7 @@ def test__ipranges_create_requires_IPRangeType(self): type=make_string_without_spaces(), comment=comment, ) - self.assertEquals("type must be an IPRangeType, not str", str(error)) + self.assertEqual("type must be an IPRangeType, not str", str(error)) def test__ipranges_read(self): """IPRanges.read() returns a list of IPRanges.""" diff --git a/maas/client/viscera/tests/test_machines.py b/maas/client/viscera/tests/test_machines.py index 62d97ad5..6a8e11f0 100644 --- a/maas/client/viscera/tests/test_machines.py +++ b/maas/client/viscera/tests/test_machines.py @@ -754,7 +754,7 @@ def test__query_power_state(self): machine._handler.query_power_state.return_value = query_data result = machine.query_power_state() self.assertIsInstance(result, PowerState) - self.assertEquals(PowerState.ON, result) + self.assertEqual(PowerState.ON, result) self.assertEqual(PowerState.ON, machine.power_state) def test__get_details(self): @@ -778,7 +778,7 @@ def test__get_details(self): machine.system_id, return_value=return_val ) data = machine.get_details() - self.assertItemsEqual(["lldp", "lshw"], data.keys()) + self.assertCountEqual(["lldp", "lshw"], data.keys()) lldp = ElementTree.fromstring(data["lldp"]) lshw = ElementTree.fromstring(data["lshw"]) assert IsInstance(lldp, ElementTree) diff --git a/maas/client/viscera/tests/test_vlans.py b/maas/client/viscera/tests/test_vlans.py index 750e7081..729b26a0 100644 --- a/maas/client/viscera/tests/test_vlans.py +++ b/maas/client/viscera/tests/test_vlans.py @@ -220,7 +220,7 @@ def test__vlan_update_relay_vlan_with_object(self): self.assertThat(vlan.relay_vlan.id, Equals(relay_vlan.id)) def test__vlan_update_relay_vlan_with_integer_id(self): - self.skip("see https://github.com/canonical/python-libmaas/issues/180") + self.skipTest("see https://github.com/canonical/python-libmaas/issues/180") origin = make_origin() Vlan = origin.Vlan Vlan._handler.params = ["fabric_id", "vid"] diff --git a/tox.ini b/tox.ini index 485859e4..0b6e3a65 100644 --- a/tox.ini +++ b/tox.ini @@ -2,9 +2,16 @@ envlist = py3, lint, imports [testenv:py3] -commands = coverage run setup.py test {posargs} +commands = coverage run -m unittest discover -s maas {posargs} sitepackages = False -deps = coverage +deps = + coverage + django >= 2.2.4, < 3.0 + fixtures >= 1.0.0 + testscenarios + testtools + Twisted<23.0.0 + setuptools<80.9.0 [testenv:integrate] commands = {envpython} -m integrate {posargs} @@ -30,6 +37,7 @@ deps = black [testenv:imports] commands = {toxinidir}/scripts/check-imports setenv = PYTHONPATH={toxinidir} +allowlist_externals = {toxinidir}/scripts/check-imports sitepackages = False skip_install = True deps = twisted