Work on issues found by pylint (#896)

* Look at possibly-used-before-assignment.

* Use latest beta releases of ansible-core 2.19 for mypy and pylint.

* Look at unsupported-*.

* Look at unknown-option-value.

* Look at redefined-builtin.

* Look at superfluous-parens.

* Look at unspecified-encoding.

* Adjust to new cryptography version and to ansible-core 2.17's pylint.

* Look at super-with-arguments.

* Look at no-else-*.

* Look at try-except-raise.

* Look at inconsistent-return-statements.

* Look at redefined-outer-name.

* Look at redefined-argument-from-local.

* Look at attribute-defined-outside-init.

* Look at unused-variable.

* Look at protected-access.

* Look at raise-missing-from.

* Look at arguments-differ.

* Look at useless-suppression and use-symbolic-message-instead.

* Look at consider-using-dict-items.

* Look at consider-using-in.

* Look at consider-using-set-comprehension.

* Look at consider-using-with.

* Look at use-dict-literal.
This commit is contained in:
Felix Fontein
2025-05-18 00:57:28 +02:00
committed by GitHub
parent a3a5284f97
commit 318462fa24
96 changed files with 1748 additions and 1598 deletions

View File

@@ -94,39 +94,51 @@ TEST_EPOCH_SECONDS: list[tuple[datetime.timedelta, float, dict[str, int]]] = (
[
(
0,
dict(
year=1970, day=1, month=1, hour=0, minute=0, second=0, microsecond=0
),
{
"year": 1970,
"month": 1,
"day": 1,
"hour": 0,
"minute": 0,
"second": 0,
"microsecond": 0,
},
),
(
1e-6,
dict(
year=1970, day=1, month=1, hour=0, minute=0, second=0, microsecond=1
),
{
"year": 1970,
"month": 1,
"day": 1,
"hour": 0,
"minute": 0,
"second": 0,
"microsecond": 1,
},
),
(
1e-3,
dict(
year=1970,
day=1,
month=1,
hour=0,
minute=0,
second=0,
microsecond=1000,
),
{
"year": 1970,
"month": 1,
"day": 1,
"hour": 0,
"minute": 0,
"second": 0,
"microsecond": 1000,
},
),
(
3691.2,
dict(
year=1970,
day=1,
month=1,
hour=1,
minute=1,
second=31,
microsecond=200000,
),
{
"year": 1970,
"month": 1,
"day": 1,
"hour": 1,
"minute": 1,
"second": 31,
"microsecond": 200000,
},
),
],
)
@@ -283,25 +295,29 @@ TEST_GET_RELATIVE_TIME_OPTION: list[
)
@pytest.mark.parametrize("timezone, input, expected", TEST_REMOVE_TIMEZONE)
@pytest.mark.parametrize("timezone, input_timestamp, expected", TEST_REMOVE_TIMEZONE)
def test_remove_timezone(
timezone: datetime.timedelta, input: datetime.datetime, expected: datetime.datetime
timezone: datetime.timedelta,
input_timestamp: datetime.datetime,
expected: datetime.datetime,
) -> None:
with freeze_time("2024-02-03 04:05:06", tz_offset=timezone):
output_1 = remove_timezone(input)
output_1 = remove_timezone(input_timestamp)
assert expected == output_1
output_2 = add_or_remove_timezone(input, with_timezone=False)
output_2 = add_or_remove_timezone(input_timestamp, with_timezone=False)
assert expected == output_2
@pytest.mark.parametrize("timezone, input, expected", TEST_UTC_TIMEZONE)
@pytest.mark.parametrize("timezone, input_timestamp, expected", TEST_UTC_TIMEZONE)
def test_utc_timezone(
timezone: datetime.timedelta, input: datetime.datetime, expected: datetime.datetime
timezone: datetime.timedelta,
input_timestamp: datetime.datetime,
expected: datetime.datetime,
) -> None:
with freeze_time("2024-02-03 04:05:06", tz_offset=timezone):
output_1 = ensure_utc_timezone(input)
output_1 = ensure_utc_timezone(input_timestamp)
assert expected == output_1
output_2 = add_or_remove_timezone(input, with_timezone=True)
output_2 = add_or_remove_timezone(input_timestamp, with_timezone=True)
assert expected == output_2