Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1083) (#1214)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 23.12.1 → 24.8.0](psf/black@23.12.1...24.8.0)
- [github.com/astral-sh/ruff-pre-commit: v0.1.13 → v0.5.7](astral-sh/ruff-pre-commit@v0.1.13...v0.5.7)
- [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](pre-commit/pre-commit-hooks@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 ff0656d)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Satellite-QE and pre-commit-ci[bot] authored Aug 16, 2024
1 parent 8bd139d commit 06aca0c
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 91 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
http://sphinx-doc.org/config.html
"""

import os
import sys

Expand Down
1 change: 1 addition & 0 deletions nailgun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
:doc:`/examples` before the documentation here.
"""

from logging import basicConfig

basicConfig()
1 change: 1 addition & 0 deletions nailgun/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
http://docs.python-requests.org/en/latest/api/#main-interface
"""

from json import dumps
import logging
from warnings import simplefilter
Expand Down
1 change: 1 addition & 0 deletions nailgun/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
presenting that information.
"""

import json
from os.path import isfile, join
from threading import Lock
Expand Down
5 changes: 3 additions & 2 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
workings of entity classes.
"""

from datetime import datetime
from functools import lru_cache
import hashlib
Expand Down Expand Up @@ -2785,7 +2786,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,
Expand Down Expand Up @@ -4667,7 +4668,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,
Expand Down
1 change: 1 addition & 0 deletions nailgun/entity_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
unpleasant to work with manually.
"""

import random

from fauxfactory import (
Expand Down
1 change: 1 addition & 0 deletions nailgun/entity_mixins.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for :mod:`nailgun.client`."""

import inspect
from unittest import TestCase, mock

Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for :mod:`nailgun.config`."""

import builtins
import json
from unittest import TestCase
Expand Down
144 changes: 86 additions & 58 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for :mod:`nailgun.entities`."""

from datetime import date, datetime
from http.client import ACCEPTED, NO_CONTENT
import inspect
Expand Down Expand Up @@ -1281,8 +1282,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,
Expand Down Expand Up @@ -1416,10 +1418,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.
Expand All @@ -1431,22 +1436,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'))
Expand Down Expand Up @@ -2401,14 +2410,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)
Expand All @@ -2425,14 +2437,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)
Expand Down Expand Up @@ -3251,11 +3266,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)
Expand All @@ -3270,11 +3288,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)
Expand All @@ -3297,11 +3319,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)
Expand All @@ -3318,11 +3343,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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_entity_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for :mod:`nailgun.entity_fields`."""

import datetime
from random import randint
import socket
Expand Down
Loading

0 comments on commit 06aca0c

Please sign in to comment.