Skip to content
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.10
rev: v0.17.1
hooks:
- id: ruff-check
args:
Expand Down
4 changes: 2 additions & 2 deletions examples/filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"""

import argparse
import datetime
import datetime as dt
import sys
from pathlib import Path

Expand Down Expand Up @@ -132,7 +132,7 @@ def main() -> None: # ruff: ignore[too-many-branches, too-many-statements, comp
file_object = Path(args.testfile)
file_content = file_object.read_bytes()
file_stat = file_object.stat()
ttime = datetime.datetime.fromtimestamp(file_stat[8])
ttime = dt.datetime.fromtimestamp(file_stat[8])
file_f = {
"ID_FullName": args.folder,
"Name": "cgi.jpg",
Expand Down
86 changes: 43 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,62 +124,62 @@ docstring-code-format = true
extend-safe-fixes = [
"ANN",
"D",
"EM101",
"EM102",
"FA102",
"f-string-in-exception",
"FLY",
"future-required-type-annotation",
"raw-string-in-exception",
"SIM",
"TCH",
"UP"
]
future-annotations = true
ignore = [
"ANN001",
"ANN002",
"ANN003",
"ANN201",
"ANN202",
"ARG001",
"ARG002",
"boolean-positional-value-in-call",
"call-datetime-fromtimestamp",
"call-datetime-without-tzinfo",
"COM", # CONFIG: No trailing commas
"D100",
"D101",
"D102",
"D103",
"D104",
"D107",
"D203", # CONFIG: incompatible with D211
"D206", # CONFIG: formatter
"D212", # CONFIG: incompatible with D213
"D401",
"DOC201",
"DOC501",
"DTZ001",
"DTZ006",
"E501", # WONTFIX: we accept long strings (rest is formatted by black)
"FBT003",
"FIX002",
"N802",
"N818",
"PERF203", # WONFIX: affects only old Python versions
"PLR2004",
"PLR6301",
"RUF012",
"S607",
"SIM115",
"SLF001",
"TD002",
"TD003",
"TRY003",
"TRY300"
"docstring-missing-exception",
"docstring-missing-returns",
"docstring-tab-indentation", # CONFIG: formatter
"error-suffix-on-exception-name",
"incorrect-blank-line-before-class", # CONFIG: incompatible with D211
"invalid-function-name",
"line-contains-todo",
"line-too-long", # WONTFIX: we accept long strings (rest is formatted by black)
"magic-value-comparison",
"missing-return-type-private-function",
"missing-return-type-undocumented-public-function",
"missing-todo-author",
"missing-todo-link",
"missing-type-args",
"missing-type-function-argument",
"missing-type-kwargs",
"multi-line-summary-first-line", # CONFIG: incompatible with D213
"mutable-class-default",
"no-self-use",
"non-imperative-mood",
"open-file-with-context-handler",
"private-member-access",
"raise-vanilla-args",
"start-process-with-partial-path",
"try-consider-else",
"try-except-in-loop", # WONFIX: affects only old Python versions
"undocumented-public-class",
"undocumented-public-function",
"undocumented-public-init",
"undocumented-public-method",
"undocumented-public-module",
"undocumented-public-package",
"unused-function-argument",
"unused-method-argument"
]
preview = true
select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"examples/*.py" = ["T201"]
"setup.py" = ["T201"]
"test/*.py" = ["S101", "T201"]
"examples/*.py" = ["print"]
"setup.py" = ["print"]
"test/*.py" = ["assert", "print"]

[tool.setuptools]
include-package-data = false
Expand Down
12 changes: 6 additions & 6 deletions test/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

import datetime
import datetime as dt
import platform
import shutil
import stat
Expand Down Expand Up @@ -102,15 +102,15 @@ def test_alarm_timezone(self) -> None:
state_machine = self.get_statemachine()
for timezone in (
None,
datetime.timezone.utc,
datetime.timezone(datetime.timedelta(hours=5, minutes=45)),
dt.timezone.utc,
dt.timezone(dt.timedelta(hours=5, minutes=45)),
):
state_machine.SetAlarm(
datetime.time(12, 34, 56, tzinfo=timezone), Repeating=False
dt.time(12, 34, 56, tzinfo=timezone), Repeating=False
)
value = state_machine.GetAlarm()["Time"]
# The dummy backend explicitly resets stored alarm offsets to zero.
assert value == datetime.time(12, 34, 56, tzinfo=datetime.timezone.utc)
assert value == dt.time(12, 34, 56, tzinfo=dt.timezone.utc)

def test_model(self) -> None:
state_machine = self.get_statemachine()
Expand Down Expand Up @@ -347,7 +347,7 @@ def test_emoji_folder(self) -> None:
def test_addfile(self) -> None:
state_machine = self.get_statemachine()
file_stat = TEST_FILE.stat()
ttime = datetime.datetime.fromtimestamp(file_stat.st_mtime)
ttime = dt.datetime.fromtimestamp(file_stat.st_mtime)
content = TEST_FILE.read_bytes()
file_f = {
"ID_FullName": "testfolder",
Expand Down
6 changes: 3 additions & 3 deletions test/test_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import binascii
import ctypes
import datetime
import datetime as dt
import os
import sys
import unittest
Expand Down Expand Up @@ -492,7 +492,7 @@ def test_mms_decode(self) -> None:
message = [
{
"RejectDuplicates": 0,
"SMSCDateTime": datetime.datetime(2010, 7, 22, 17, 4, 11),
"SMSCDateTime": dt.datetime(2010, 7, 22, 17, 4, 11),
"Class": -1,
"Name": "",
"InboxFolder": 0,
Expand All @@ -513,7 +513,7 @@ def test_mms_decode(self) -> None:
"ReplaceMessage": 0,
"Coding": "8bit",
"Number": "33707520030",
"DateTime": datetime.datetime(2010, 7, 1, 9, 40, 21),
"DateTime": dt.datetime(2010, 7, 1, 9, 40, 21),
"DeliveryStatus": 0,
"State": "UnSent",
"MessageReference": 0,
Expand Down
28 changes: 14 additions & 14 deletions test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

"""Timezone conversion regression tests."""

import datetime
import datetime as dt
from types import SimpleNamespace

import pytest

import gammu

WALL_TIME = datetime.datetime(2026, 9, 16, 12, 34, 56)
WALL_TIME = dt.datetime(2026, 9, 16, 12, 34, 56)


def link_datetime(value):
Expand All @@ -44,15 +44,15 @@ def link_datetime(value):
"seconds", [0, 7200, -18000, 19800, -12600, 20700, 1, -1, 86399, -86399]
)
def test_datetime_offset_roundtrip(seconds):
offset = datetime.timedelta(seconds=seconds)
value = WALL_TIME.replace(tzinfo=datetime.timezone(offset))
offset = dt.timedelta(seconds=seconds)
value = WALL_TIME.replace(tzinfo=dt.timezone(offset))
result = link_datetime(value)
for field in ("DateTime", "SMSCDateTime"):
assert result[field].replace(tzinfo=None) == WALL_TIME
assert result[field].utcoffset() == offset


class NoOffset(datetime.tzinfo):
class NoOffset(dt.tzinfo):
def utcoffset(self, dt):
return None

Expand All @@ -68,7 +68,7 @@ def utcoffset(self, dt):
def test_naive_datetime(value):
result = link_datetime(value)["DateTime"]
assert result.replace(tzinfo=None) == WALL_TIME
assert result.tzinfo == datetime.timezone.utc
assert result.tzinfo == dt.timezone.utc


def test_missing_datetime():
Expand All @@ -87,18 +87,18 @@ def test_decode_pdu_offset(encoded_offset, seconds):
pdu[14] = encoded_offset
value = gammu.DecodePDU(bytes(pdu))["DateTime"]
assert value.replace(tzinfo=None) == WALL_TIME
assert value.utcoffset() == datetime.timedelta(seconds=seconds)
assert value.utcoffset() == dt.timedelta(seconds=seconds)


@pytest.mark.parametrize(
("offset", "error", "message"),
[
(42, TypeError, "timedelta"),
(datetime.timedelta(days=1), ValueError, "24"),
(datetime.timedelta(days=-1), ValueError, "24"),
(datetime.timedelta(days=999999999), ValueError, "24"),
(datetime.timedelta(microseconds=1), ValueError, "whole number"),
(datetime.timedelta(microseconds=-1), ValueError, "whole number"),
(dt.timedelta(days=1), ValueError, "24"),
(dt.timedelta(days=-1), ValueError, "24"),
(dt.timedelta(days=999999999), ValueError, "24"),
(dt.timedelta(microseconds=1), ValueError, "whole number"),
(dt.timedelta(microseconds=-1), ValueError, "whole number"),
],
)
@pytest.mark.parametrize("time_only", [False, True])
Expand All @@ -122,7 +122,7 @@ def test_invalid_offset(offset, error, message, time_only):
state_machine.SetDateTime(value)


class BrokenTimezone(datetime.tzinfo):
class BrokenTimezone(dt.tzinfo):
def utcoffset(self, dt):
message = "offset failed"
raise RuntimeError(message)
Expand All @@ -132,7 +132,7 @@ def utcoffset(self, dt):
def test_offset_exception(time_only):
state_machine = gammu.StateMachine()
if time_only:
value = datetime.time(12, 34, tzinfo=BrokenTimezone())
value = dt.time(12, 34, tzinfo=BrokenTimezone())
with pytest.raises(RuntimeError, match="offset failed"):
state_machine.SetAlarm(value, Repeating=False)
else:
Expand Down
Loading