From ac128c4438bab3450a8c9d9cff359731bde56418 Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:25:00 -0400 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#1083) (#1213) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 23.12.1 → 24.8.0](https://github.com/psf/black/compare/23.12.1...24.8.0) - [github.com/astral-sh/ruff-pre-commit: v0.1.13 → v0.5.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.13...v0.5.7) - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v4.6.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit ff0656d3b829086603c486d6db1ce3bbd333f704) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +- docs/conf.py | 1 + nailgun/__init__.py | 1 + nailgun/client.py | 1 + nailgun/config.py | 1 + nailgun/entities.py | 5 +- nailgun/entity_fields.py | 1 + nailgun/entity_mixins.py | 1 + tests/test_client.py | 1 + tests/test_config.py | 1 + tests/test_entities.py | 144 +++++++++++++++++++++--------------- tests/test_entity_fields.py | 1 + tests/test_entity_mixins.py | 73 +++++++++++------- 13 files changed, 146 insertions(+), 91 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a4a7304..ed53ec5a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,16 +5,16 @@ ci: repos: - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.8.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.5.7 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-yaml - id: debug-statements diff --git a/docs/conf.py b/docs/conf.py index efe6cb9b..607b6456 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,6 +4,7 @@ http://sphinx-doc.org/config.html """ + import os import sys diff --git a/nailgun/__init__.py b/nailgun/__init__.py index d1ac40c5..a623cbf9 100644 --- a/nailgun/__init__.py +++ b/nailgun/__init__.py @@ -14,6 +14,7 @@ :doc:`/examples` before the documentation here. """ + from logging import basicConfig basicConfig() diff --git a/nailgun/client.py b/nailgun/client.py index 3bfae9f1..6224e429 100644 --- a/nailgun/client.py +++ b/nailgun/client.py @@ -15,6 +15,7 @@ http://docs.python-requests.org/en/latest/api/#main-interface """ + from json import dumps import logging from warnings import simplefilter diff --git a/nailgun/config.py b/nailgun/config.py index 757d048b..6586a835 100644 --- a/nailgun/config.py +++ b/nailgun/config.py @@ -7,6 +7,7 @@ presenting that information. """ + import json from os.path import isfile, join from threading import Lock diff --git a/nailgun/entities.py b/nailgun/entities.py index bf3836a2..60455664 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -20,6 +20,7 @@ workings of entity classes. """ + from datetime import datetime from functools import lru_cache import hashlib @@ -2764,7 +2765,7 @@ def read(self, entity=None, attrs=None, ignore=None, params=None): if self._server_config: entity._server_config = self._server_config result = super().read(entity, attrs, ignore, params) - if 'content_view_components' in attrs and attrs['content_view_components']: + if attrs.get('content_view_components'): result.content_view_component = [ ContentViewComponent( server_config=self._server_config, @@ -4560,7 +4561,7 @@ def read(self, entity=None, attrs=None, ignore=None, params=None): ) else: result.image = None - if 'interfaces' in attrs and attrs['interfaces']: + if attrs.get('interfaces'): result.interface = [ Interface( server_config=self._server_config, diff --git a/nailgun/entity_fields.py b/nailgun/entity_fields.py index 5276382c..d9b16e79 100644 --- a/nailgun/entity_fields.py +++ b/nailgun/entity_fields.py @@ -18,6 +18,7 @@ unpleasant to work with manually. """ + import random from fauxfactory import ( diff --git a/nailgun/entity_mixins.py b/nailgun/entity_mixins.py index 06c1a1ea..04849e8f 100644 --- a/nailgun/entity_mixins.py +++ b/nailgun/entity_mixins.py @@ -1,4 +1,5 @@ """Defines a set of mixins that provide tools for interacting with entities.""" + import _thread as thread from collections.abc import Iterable import contextlib diff --git a/tests/test_client.py b/tests/test_client.py index cd5bb2b7..11bbc0ce 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,4 +1,5 @@ """Unit tests for :mod:`nailgun.client`.""" + import inspect from unittest import TestCase, mock diff --git a/tests/test_config.py b/tests/test_config.py index 457716a5..147d57c5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,5 @@ """Unit tests for :mod:`nailgun.config`.""" + import builtins import json from unittest import TestCase diff --git a/tests/test_entities.py b/tests/test_entities.py index a3564935..426d6cb8 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -1,4 +1,5 @@ """Tests for :mod:`nailgun.entities`.""" + from datetime import date, datetime from http.client import ACCEPTED, NO_CONTENT import inspect @@ -1279,8 +1280,9 @@ def test_ignore_arg_v1(self): ), ): with self.subTest(entity): - with mock.patch.object(EntityReadMixin, 'read') as read, mock.patch.object( - EntityReadMixin, 'read_json' + with ( + mock.patch.object(EntityReadMixin, 'read') as read, + mock.patch.object(EntityReadMixin, 'read_json'), ): with mock.patch.object( entities, @@ -1414,10 +1416,13 @@ def test_snapshot_ignore_arg(self): Assert that entity`s predefined values of ``ignore`` are always correctly passed on. """ - with mock.patch.object(EntityReadMixin, 'read') as read, mock.patch.object( - EntityReadMixin, - 'read_json', - return_value={'host': 3}, + with ( + mock.patch.object(EntityReadMixin, 'read') as read, + mock.patch.object( + EntityReadMixin, + 'read_json', + return_value={'host': 3}, + ), ): entities.Snapshot(self.cfg, id=2, host=3).read() # `call_args` is a two-tuple of (positional, keyword) args. @@ -1429,22 +1434,26 @@ def test_host_with_interface(self): Assert that host will have interfaces initialized and assigned correctly. """ - with mock.patch.object( - EntityReadMixin, - 'read', - return_value=entities.Host(self.cfg, id=2), - ), mock.patch.object( - EntityReadMixin, - 'read_json', - return_value={ - 'interfaces': [{'id': 2}, {'id': 3}], - 'parameters': None, - 'puppet_proxy': None, - }, - ), mock.patch.object( - entities, - '_feature_list', - return_value={'Puppet'}, + with ( + mock.patch.object( + EntityReadMixin, + 'read', + return_value=entities.Host(self.cfg, id=2), + ), + mock.patch.object( + EntityReadMixin, + 'read_json', + return_value={ + 'interfaces': [{'id': 2}, {'id': 3}], + 'parameters': None, + 'puppet_proxy': None, + }, + ), + mock.patch.object( + entities, + '_feature_list', + return_value={'Puppet'}, + ), ): host = entities.Host(self.cfg, id=2).read() self.assertTrue(hasattr(host, 'interface')) @@ -2395,14 +2404,17 @@ def test_content_upload_upload(self): """ filename = gen_string('alpha') filepath = os.path.join(gen_string('alpha'), filename) - with mock.patch.object( - entities.ContentUpload, - 'create', - ) as create, mock.patch.object( - entities.Repository, - 'import_uploads', - return_value={'status': 'success'}, - ) as import_uploads: + with ( + mock.patch.object( + entities.ContentUpload, + 'create', + ) as create, + mock.patch.object( + entities.Repository, + 'import_uploads', + return_value={'status': 'success'}, + ) as import_uploads, + ): mock_open = mock.mock_open(read_data=gen_string('alpha').encode('ascii')) with mock.patch(_BUILTIN_OPEN, mock_open, create=True): response = self.content_upload.upload(filepath, filename) @@ -2419,14 +2431,17 @@ def test_content_upload_no_filename(self): """ filename = gen_string('alpha') filepath = os.path.join(gen_string('alpha'), filename) - with mock.patch.object( - entities.ContentUpload, - 'create', - ) as create, mock.patch.object( - entities.Repository, - 'import_uploads', - return_value={'status': 'success'}, - ) as import_uploads: + with ( + mock.patch.object( + entities.ContentUpload, + 'create', + ) as create, + mock.patch.object( + entities.Repository, + 'import_uploads', + return_value={'status': 'success'}, + ) as import_uploads, + ): mock_open = mock.mock_open(read_data=gen_string('alpha').encode('ascii')) with mock.patch(_BUILTIN_OPEN, mock_open, create=True): response = self.content_upload.upload(filepath) @@ -3125,11 +3140,14 @@ def test_upload_content_v1(self): :meth:`tests.test_entities.GenericTestCase.test_generic`. """ kwargs = {'kwarg': gen_integer()} - with mock.patch.object(client, 'post') as post, mock.patch.object( - entities, - '_handle_response', - return_value={'status': 'success'}, - ) as handler: + with ( + mock.patch.object(client, 'post') as post, + mock.patch.object( + entities, + '_handle_response', + return_value={'status': 'success'}, + ) as handler, + ): response = self.repo.upload_content(**kwargs) self.assertEqual(post.call_count, 1) self.assertEqual(len(post.call_args[0]), 1) @@ -3144,11 +3162,15 @@ def test_upload_content_v2(self): the (mock) server fails to return a "success" status. """ kwargs = {'kwarg': gen_integer()} - with mock.patch.object(client, 'post') as post, mock.patch.object( - entities, - '_handle_response', - return_value={'status': 'failure'}, - ) as handler, self.assertRaises(entities.APIResponseError): + with ( + mock.patch.object(client, 'post') as post, + mock.patch.object( + entities, + '_handle_response', + return_value={'status': 'failure'}, + ) as handler, + self.assertRaises(entities.APIResponseError), + ): self.repo.upload_content(**kwargs) self.assertEqual(post.call_count, 1) self.assertEqual(len(post.call_args[0]), 1) @@ -3171,11 +3193,14 @@ def test_import_uploads_uploads(self): 'checksum': gen_string('numeric'), } ] - with mock.patch.object(client, 'put') as put, mock.patch.object( - entities, - '_handle_response', - return_value={'status': 'success'}, - ) as handler: + with ( + mock.patch.object(client, 'put') as put, + mock.patch.object( + entities, + '_handle_response', + return_value={'status': 'success'}, + ) as handler, + ): response = self.repo.import_uploads(uploads=uploads, **kwargs) self.assertEqual(put.call_count, 1) self.assertEqual(len(put.call_args[0]), 2) @@ -3192,11 +3217,14 @@ def test_import_uploads_upload_ids(self): """ kwargs = {'kwarg': gen_integer()} upload_ids = [gen_string('numeric')] - with mock.patch.object(client, 'put') as put, mock.patch.object( - entities, - '_handle_response', - return_value={'status': 'success'}, - ) as handler: + with ( + mock.patch.object(client, 'put') as put, + mock.patch.object( + entities, + '_handle_response', + return_value={'status': 'success'}, + ) as handler, + ): response = self.repo.import_uploads(upload_ids=upload_ids, **kwargs) self.assertEqual(put.call_count, 1) self.assertEqual(len(put.call_args[0]), 2) diff --git a/tests/test_entity_fields.py b/tests/test_entity_fields.py index 4a115b6e..0f541a5b 100644 --- a/tests/test_entity_fields.py +++ b/tests/test_entity_fields.py @@ -1,4 +1,5 @@ """Unit tests for :mod:`nailgun.entity_fields`.""" + import datetime from random import randint import socket diff --git a/tests/test_entity_mixins.py b/tests/test_entity_mixins.py index 2776c0f5..8417026a 100644 --- a/tests/test_entity_mixins.py +++ b/tests/test_entity_mixins.py @@ -1,4 +1,5 @@ """Tests for :mod:`nailgun.entity_mixins`.""" + import http.client as http_client from unittest import TestCase, mock @@ -631,9 +632,10 @@ def test_create_json_with_exception(self): response.json.return_value = return_value else: response.json.side_effect = JSONDecodeError("msg", "foo", 2) - with mock.patch.object( - self.entity, 'create_raw', return_value=response - ), self.assertRaises(HTTPError) as error: + with ( + mock.patch.object(self.entity, 'create_raw', return_value=response), + self.assertRaises(HTTPError) as error, + ): self.entity.create_json() self.assertEqual(response.raise_for_status.call_count, 1) self.assertEqual(response.json.call_count, 1) @@ -979,11 +981,14 @@ def test_delete_v1(self): """Check what happens if the server returns an error HTTP status code.""" response = mock.Mock() response.raise_for_status.side_effect = HTTPError('oh no!') - with mock.patch.object( - entity_mixins.EntityDeleteMixin, - 'delete_raw', - return_value=response, - ), self.assertRaises(HTTPError): + with ( + mock.patch.object( + entity_mixins.EntityDeleteMixin, + 'delete_raw', + return_value=response, + ), + self.assertRaises(HTTPError), + ): self.entity.delete() def test_delete_v2(self): @@ -991,11 +996,14 @@ def test_delete_v2(self): response = mock.Mock() response.status_code = http_client.ACCEPTED response.json.return_value = {'id': gen_integer()} - with mock.patch.object( - entity_mixins.EntityDeleteMixin, - 'delete_raw', - return_value=response, - ) as delete_raw, mock.patch.object(entity_mixins, '_poll_task') as poll_task: + with ( + mock.patch.object( + entity_mixins.EntityDeleteMixin, + 'delete_raw', + return_value=response, + ) as delete_raw, + mock.patch.object(entity_mixins, '_poll_task') as poll_task, + ): self.entity.delete() self.assertEqual(delete_raw.call_count, 1) self.assertEqual(poll_task.call_count, 1) @@ -1008,11 +1016,14 @@ def test_delete_v3(self): """Check what happens if the server returns an HTTP NO_CONTENT status.""" response = mock.Mock() response.status_code = http_client.NO_CONTENT - with mock.patch.object( - entity_mixins.EntityDeleteMixin, - 'delete_raw', - return_value=response, - ), mock.patch.object(entity_mixins, '_poll_task') as poll_task: + with ( + mock.patch.object( + entity_mixins.EntityDeleteMixin, + 'delete_raw', + return_value=response, + ), + mock.patch.object(entity_mixins, '_poll_task') as poll_task, + ): self.assertEqual(self.entity.delete(), None) self.assertEqual(poll_task.call_count, 0) @@ -1032,11 +1043,14 @@ def test_delete_v5(self): response = mock.Mock() response.status_code = http_client.OK response.content = '' - with mock.patch.object( - entity_mixins.EntityDeleteMixin, - 'delete_raw', - return_value=response, - ), mock.patch.object(entity_mixins, '_poll_task') as poll_task: + with ( + mock.patch.object( + entity_mixins.EntityDeleteMixin, + 'delete_raw', + return_value=response, + ), + mock.patch.object(entity_mixins, '_poll_task') as poll_task, + ): self.assertEqual(self.entity.delete(), None) self.assertEqual(poll_task.call_count, 0) @@ -1045,11 +1059,14 @@ def test_delete_v6(self): response = mock.Mock() response.status_code = http_client.OK response.content = ' ' - with mock.patch.object( - entity_mixins.EntityDeleteMixin, - 'delete_raw', - return_value=response, - ), mock.patch.object(entity_mixins, '_poll_task') as poll_task: + with ( + mock.patch.object( + entity_mixins.EntityDeleteMixin, + 'delete_raw', + return_value=response, + ), + mock.patch.object(entity_mixins, '_poll_task') as poll_task, + ): self.assertEqual(self.entity.delete(), None) self.assertEqual(poll_task.call_count, 0)