Enable more ruff checks & fix them
This commit is contained in:
parent
e28f83b676
commit
b567f4df28
3 changed files with 12 additions and 8 deletions
|
|
@ -26,6 +26,7 @@ import datetime
|
|||
import hashlib
|
||||
import io
|
||||
import logging
|
||||
import pathlib
|
||||
import re
|
||||
import urllib.request
|
||||
from dataclasses import dataclass, field
|
||||
|
|
@ -237,7 +238,7 @@ class LeapSecondData:
|
|||
default is the standard location for the file on Debian systems.
|
||||
:param check_hash: Whether to check the embedded hash
|
||||
"""
|
||||
with open(filename, "rb") as open_file: # pragma no cover
|
||||
with pathlib.Path(filename).open("rb") as open_file: # pragma no cover
|
||||
return cls.from_open_file(open_file, check_hash=check_hash)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -301,7 +302,7 @@ class LeapSecondData:
|
|||
hasher = hashlib.sha1()
|
||||
|
||||
for row in open_file:
|
||||
row = row.strip()
|
||||
row = row.strip() # noqa: PLW2901
|
||||
if row.startswith(b"#h"):
|
||||
content_hash = cls._parse_content_hash(row)
|
||||
continue
|
||||
|
|
@ -318,11 +319,11 @@ class LeapSecondData:
|
|||
last_updated = _from_ntp_epoch(int(parts[1]))
|
||||
continue
|
||||
|
||||
row = row.split(b"#")[0].strip()
|
||||
row = row.split(b"#")[0].strip() # noqa: PLW2901
|
||||
content_to_hash.extend(re.findall(rb"\d+", row))
|
||||
|
||||
parts = row.split()
|
||||
if len(parts) != 2:
|
||||
if len(parts) != 2: # noqa: PLR2004
|
||||
continue
|
||||
hasher.update(parts[0])
|
||||
hasher.update(parts[1])
|
||||
|
|
@ -336,6 +337,6 @@ class LeapSecondData:
|
|||
raise InvalidHashError("No #h line found")
|
||||
digest = hasher.hexdigest()
|
||||
if digest != content_hash:
|
||||
raise InvalidHashError(f"Hash didn't match. Expected {content_hash[:8]}..., " f"got {digest[:8]}...")
|
||||
raise InvalidHashError(f"Hash didn't match. Expected {content_hash[:8]}..., got {digest[:8]}...")
|
||||
|
||||
return LeapSecondData(leap_seconds, valid_until, last_updated)
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@ build-backend = "setuptools.build_meta"
|
|||
[tool.ruff]
|
||||
line-length=120
|
||||
[tool.ruff.lint]
|
||||
select = ["E", "F", "D", "I", "N", "UP", "YTT", "BLE", "B", "FBT", "A", "COM", "C4", "DTZ"]
|
||||
ignore = ["D203", "D213", "D400", "D415"]
|
||||
select = ["E", "F", "D", "I", "N", "UP", "YTT", "BLE", "B", "FBT", "A", "COM", "C4", "DTZ", "FA", "ISC", "ICN", "PIE", "PYI", "Q", "RET", "SIM", "TID", "TCH", "ARG", "PTH", "C", "R", "W", "FLY", "RUF", "PL"]
|
||||
ignore = ["D203", "D213", "D400", "D415", "ISC001"]
|
||||
|
|
|
|||
|
|
@ -105,7 +105,10 @@ class LeapSecondDataTest(unittest.TestCase):
|
|||
when_tai = datetime.datetime(1999, 1, 1, 0, 0, 32, tzinfo=leapseconddata.tai)
|
||||
when_utc = db.tai_to_utc(when_tai)
|
||||
self.assertIs(when_utc.tzinfo, datetime.timezone.utc)
|
||||
print(when_utc)
|
||||
|
||||
when_tai = datetime.datetime(1999, 1, 1, 0, 0, 32, tzinfo=None) # noqa: DTZ001
|
||||
when_utc2 = db.tai_to_utc(when_tai)
|
||||
self.assertEqual(when_utc, when_utc2)
|
||||
|
||||
def test_to_tai(self) -> None:
|
||||
when = datetime.datetime(1999, 1, 1, tzinfo=datetime.timezone.utc) - datetime.timedelta(seconds=1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue