Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd02ced

Browse files
committedMay 14, 2025·
change to ruff
1 parent 2671a7f commit dd02ced

15 files changed

+215
-551
lines changed
 

‎.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
.py text eol=lf
6+
.rst text eol=lf
7+
.txt text eol=lf
8+
.yaml text eol=lf
9+
.toml text eol=lf
10+
.license text eol=lf
11+
.md text eol=lf

‎.pre-commit-config.yaml

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
1-
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
1+
# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
44

55
repos:
6-
- repo: https://github.com/python/black
7-
rev: 23.3.0
8-
hooks:
9-
- id: black
10-
- repo: https://github.com/fsfe/reuse-tool
11-
rev: v1.1.2
12-
hooks:
13-
- id: reuse
146
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.4.0
7+
rev: v4.5.0
168
hooks:
179
- id: check-yaml
1810
- id: end-of-file-fixer
1911
- id: trailing-whitespace
20-
- repo: https://github.com/pycqa/pylint
21-
rev: v2.17.4
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.3.4
2214
hooks:
23-
- id: pylint
24-
name: pylint (library code)
25-
types: [python]
26-
args:
27-
- --disable=consider-using-f-string
28-
exclude: "^(docs/|examples/|tests/|setup.py$)"
29-
- id: pylint
30-
name: pylint (example code)
31-
description: Run pylint rules on "examples/*.py" files
32-
types: [python]
33-
files: "^examples/"
34-
args:
35-
- --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code
36-
- id: pylint
37-
name: pylint (test code)
38-
description: Run pylint rules on "tests/*.py" files
39-
types: [python]
40-
files: "^tests/"
41-
args:
42-
- --disable=missing-docstring,consider-using-f-string,duplicate-code
15+
- id: ruff-format
16+
- id: ruff
17+
args: ["--fix"]
18+
- repo: https://github.com/fsfe/reuse-tool
19+
rev: v3.0.1
20+
hooks:
21+
- id: reuse

‎.pylintrc

Lines changed: 0 additions & 399 deletions
This file was deleted.

‎README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Introduction
1313
:target: https://github.com/adafruit/Adafruit_CircuitPython_GPS/actions/
1414
:alt: Build Status
1515

16-
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
17-
:target: https://github.com/psf/black
18-
:alt: Code Style: Black
16+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
17+
:target: https://github.com/astral-sh/ruff
18+
:alt: Code Style: Ruff
1919

2020
GPS parsing module. Can send commands to, and parse simple NMEA data sentences
2121
from serial and I2C GPS modules to read latitude, longitude, and more.

‎adafruit_gps.py

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@
2626
https://github.com/adafruit/circuitpython/releases
2727
2828
"""
29+
2930
import time
31+
3032
from micropython import const
3133

3234
try:
33-
from typing import Optional, Tuple, List
34-
from typing_extensions import Literal
35+
from typing import List, Optional, Tuple
36+
37+
from busio import I2C, UART
3538
from circuitpython_typing import ReadableBuffer
36-
from busio import UART, I2C
39+
from typing_extensions import Literal
3740
except ImportError:
3841
pass
3942

@@ -103,19 +106,19 @@ def _parse_degrees(nmea_data: str) -> int:
103106

104107

105108
def _parse_int(nmea_data: str) -> int:
106-
if nmea_data is None or nmea_data == "":
109+
if nmea_data is None or not nmea_data:
107110
return None
108111
return int(nmea_data)
109112

110113

111114
def _parse_float(nmea_data: str) -> float:
112-
if nmea_data is None or nmea_data == "":
115+
if nmea_data is None or not nmea_data:
113116
return None
114117
return float(nmea_data)
115118

116119

117120
def _parse_str(nmea_data: str) -> str:
118-
if nmea_data is None or nmea_data == "":
121+
if nmea_data is None or not nmea_data:
119122
return None
120123
return str(nmea_data)
121124

@@ -162,7 +165,6 @@ def _parse_data(sentence_type: int, data: List[str]) -> Optional[List]:
162165
"""Parse sentence data for the specified sentence type and
163166
return a list of parameters in the correct format, or return None.
164167
"""
165-
# pylint: disable=too-many-branches
166168

167169
if not _ST_MIN <= sentence_type <= _ST_MAX:
168170
# The sentence_type is unknown
@@ -239,14 +241,11 @@ def _parse_data(sentence_type: int, data: List[str]) -> Optional[List]:
239241
return params
240242

241243

242-
# pylint: disable-msg=too-many-instance-attributes
243244
class GPS:
244245
"""GPS parsing module. Can parse simple NMEA data sentences from serial
245246
GPS modules to read latitude, longitude, and more.
246247
"""
247248

248-
# lint warning about too many statements disabled
249-
# pylint: disable-msg=R0915
250249
def __init__(self, uart: UART, debug: bool = False) -> None:
251250
self._uart = uart
252251
# Initialize null starting values for GPS attributes.
@@ -362,7 +361,7 @@ def update(self) -> bool:
362361
# GP - GPS
363362
# GQ - QZSS
364363
# GN - GNSS / More than one of the above
365-
if talker not in (b"GA", b"GB", b"GI", b"GL", b"GP", b"GQ", b"GN"):
364+
if talker not in {b"GA", b"GB", b"GI", b"GL", b"GP", b"GQ", b"GN"}:
366365
# It's not a known GNSS source of data
367366
# Assume it's a valid packet anyway
368367
return True
@@ -397,7 +396,7 @@ def send_command(self, command: bytes, add_checksum: bool = True) -> None:
397396
for char in command:
398397
checksum ^= char
399398
self.write(b"*")
400-
self.write(bytes("{:02x}".format(checksum).upper(), "ascii"))
399+
self.write(bytes(f"{checksum:02x}".upper(), "ascii"))
401400
self.write(b"\r\n")
402401

403402
@property
@@ -444,7 +443,6 @@ def readline(self) -> Optional[bytes]:
444443

445444
def _read_sentence(self) -> Optional[str]:
446445
# Parse any NMEA sentence that is available.
447-
# pylint: disable=len-as-condition
448446
# This needs to be refactored when it can be tested.
449447

450448
# Only continue if we have at least 11 bytes in the input buffer
@@ -508,9 +506,7 @@ def _update_timestamp_utc(self, time_utc: str, date: Optional[str] = None) -> No
508506
month = int(date[2:4])
509507
year = 2000 + int(date[4:6])
510508

511-
self.timestamp_utc = time.struct_time(
512-
(year, month, day, hours, mins, secs, 0, 0, -1)
513-
)
509+
self.timestamp_utc = time.struct_time((year, month, day, hours, mins, secs, 0, 0, -1))
514510

515511
def _parse_vtg(self, data: List[str]) -> bool:
516512
# VTG - Course Over Ground and Ground Speed
@@ -547,15 +543,11 @@ def _parse_gll(self, data: List[str]) -> bool:
547543

548544
# Latitude
549545
self.latitude = _read_degrees(parsed_data, 0, "s")
550-
self.latitude_degrees, self.latitude_minutes = _read_deg_mins(
551-
data=data, index=0, neg="s"
552-
)
546+
self.latitude_degrees, self.latitude_minutes = _read_deg_mins(data=data, index=0, neg="s")
553547

554548
# Longitude
555549
self.longitude = _read_degrees(parsed_data, 2, "w")
556-
self.longitude_degrees, self.longitude_minutes = _read_deg_mins(
557-
data=data, index=2, neg="w"
558-
)
550+
self.longitude_degrees, self.longitude_minutes = _read_deg_mins(data=data, index=2, neg="w")
559551

560552
# UTC time of position
561553
self._update_timestamp_utc(parsed_data[4])
@@ -571,7 +563,7 @@ def _parse_gll(self, data: List[str]) -> bool:
571563
def _parse_rmc(self, data: List[str]) -> bool:
572564
# RMC - Recommended Minimum Navigation Information
573565

574-
if data is None or len(data) not in (12, 13):
566+
if data is None or len(data) not in {12, 13}:
575567
return False # Unexpected number of params.
576568
parsed_data = _parse_data({12: _RMC, 13: _RMC_4_1}[len(data)], data)
577569
if parsed_data is None:
@@ -591,15 +583,11 @@ def _parse_rmc(self, data: List[str]) -> bool:
591583

592584
# Latitude
593585
self.latitude = _read_degrees(parsed_data, 2, "s")
594-
self.latitude_degrees, self.latitude_minutes = _read_deg_mins(
595-
data=data, index=2, neg="s"
596-
)
586+
self.latitude_degrees, self.latitude_minutes = _read_deg_mins(data=data, index=2, neg="s")
597587

598588
# Longitude
599589
self.longitude = _read_degrees(parsed_data, 4, "w")
600-
self.longitude_degrees, self.longitude_minutes = _read_deg_mins(
601-
data=data, index=4, neg="w"
602-
)
590+
self.longitude_degrees, self.longitude_minutes = _read_deg_mins(data=data, index=4, neg="w")
603591

604592
# Speed over ground, knots
605593
self.speed_knots = parsed_data[6]
@@ -633,15 +621,11 @@ def _parse_gga(self, data: List[str]) -> bool:
633621

634622
# Latitude
635623
self.latitude = _read_degrees(parsed_data, 1, "s")
636-
self.longitude_degrees, self.longitude_minutes = _read_deg_mins(
637-
data=data, index=3, neg="w"
638-
)
624+
self.longitude_degrees, self.longitude_minutes = _read_deg_mins(data=data, index=3, neg="w")
639625

640626
# Longitude
641627
self.longitude = _read_degrees(parsed_data, 3, "w")
642-
self.latitude_degrees, self.latitude_minutes = _read_deg_mins(
643-
data=data, index=1, neg="s"
644-
)
628+
self.latitude_degrees, self.latitude_minutes = _read_deg_mins(data=data, index=1, neg="s")
645629

646630
# GPS quality indicator
647631
self.fix_quality = parsed_data[5]
@@ -668,7 +652,7 @@ def _parse_gga(self, data: List[str]) -> bool:
668652
def _parse_gsa(self, talker: bytes, data: List[str]) -> bool:
669653
# GSA - GPS DOP and active satellites
670654

671-
if data is None or len(data) not in (17, 18):
655+
if data is None or len(data) not in {17, 18}:
672656
return False # Unexpected number of params.
673657
if len(data) == 17:
674658
data = _parse_data(_GSA, data)
@@ -689,7 +673,7 @@ def _parse_gsa(self, talker: bytes, data: List[str]) -> bool:
689673
satlist = list(filter(None, data[2:-4]))
690674
self.sat_prns = []
691675
for sat in satlist:
692-
self.sat_prns.append("{}{}".format(talker, sat))
676+
self.sat_prns.append(f"{talker}{sat}")
693677

694678
# PDOP, dilution of precision
695679
self.pdop = _parse_float(data[14])
@@ -706,9 +690,8 @@ def _parse_gsa(self, talker: bytes, data: List[str]) -> bool:
706690

707691
def _parse_gsv(self, talker: bytes, data: List[str]) -> bool:
708692
# GSV - Satellites in view
709-
# pylint: disable=too-many-branches
710693

711-
if data is None or len(data) not in (7, 11, 15, 19):
694+
if data is None or len(data) not in {7, 11, 15, 19}:
712695
return False # Unexpected number of params.
713696
data = _parse_data(
714697
{7: _GSV7, 11: _GSV11, 15: _GSV15, 19: _GSV19}[len(data)],
@@ -734,7 +717,7 @@ def _parse_gsv(self, talker: bytes, data: List[str]) -> bool:
734717
j = i * 4
735718
value = (
736719
# Satellite number
737-
"{}{}".format(talker, sat_tup[0 + j]),
720+
f"{talker}{sat_tup[0 + j]}",
738721
# Elevation in degrees
739722
sat_tup[1 + j],
740723
# Azimuth in degrees
@@ -789,9 +772,7 @@ def __init__(
789772
debug: bool = False,
790773
timeout: float = 5.0,
791774
) -> None:
792-
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
793-
i2c_device,
794-
)
775+
from adafruit_bus_device import i2c_device # noqa: PLC0415
795776

796777
super().__init__(None, debug) # init the parent with no UART
797778
self._i2c = i2c_device.I2CDevice(i2c_bus, address)

‎docs/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11

22
.. If you created a package, create one automodule per module in the package.
33
4+
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
5+
.. use this format as the module name: "adafruit_foo.foo"
6+
7+
API Reference
8+
#############
9+
410
.. automodule:: adafruit_gps
511
:members:

‎docs/conf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# -*- coding: utf-8 -*-
2-
31
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
42
#
53
# SPDX-License-Identifier: MIT
64

5+
import datetime
76
import os
87
import sys
9-
import datetime
108

119
sys.path.insert(0, os.path.abspath(".."))
1210

@@ -40,9 +38,7 @@
4038
creation_year = "2017"
4139
current_year = str(datetime.datetime.now().year)
4240
year_duration = (
43-
current_year
44-
if current_year == creation_year
45-
else creation_year + " - " + current_year
41+
current_year if current_year == creation_year else creation_year + " - " + current_year
4642
)
4743
copyright = year_duration + " Tony DiCola, James Carr"
4844
author = "Tony DiCola, James Carr"

‎examples/gps_datalogging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import board
1616
import busio
17+
1718
import adafruit_gps
1819

1920
# Path to the file to log GPS data. By default this will be appended to

‎examples/gps_displayio_simpletest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
import time
5+
56
import board
67
from adafruit_display_text.label import Label
78
from displayio import Group

‎examples/gps_echotest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Will print NMEA sentences received from the GPS, great for testing connection
66
# Uses the GPS to send some commands, then reads directly from the GPS
77
import time
8+
89
import board
910
import busio
1011

‎examples/gps_satellitefix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# * GSV - Satellites in view
88

99
import time
10+
1011
import board
1112

1213
import adafruit_gps

‎examples/gps_simpletest.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Will wait for a fix and print a message every second with the current location
66
# and other details.
77
import time
8+
89
import board
910
import busio
1011

@@ -74,7 +75,7 @@
7475
# Print out details about the fix like location, date, etc.
7576
print("=" * 40) # Print a separator line.
7677
print(
77-
"Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format(
78+
"Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format( # noqa: UP032
7879
gps.timestamp_utc.tm_mon, # Grab parts of the time from the
7980
gps.timestamp_utc.tm_mday, # struct_time object that holds
8081
gps.timestamp_utc.tm_year, # the fix time. Note you might
@@ -83,32 +84,24 @@
8384
gps.timestamp_utc.tm_sec,
8485
)
8586
)
86-
print("Latitude: {0:.6f} degrees".format(gps.latitude))
87-
print("Longitude: {0:.6f} degrees".format(gps.longitude))
88-
print(
89-
"Precise Latitude: {} degs, {:2.4f} mins".format(
90-
gps.latitude_degrees, gps.latitude_minutes
91-
)
92-
)
93-
print(
94-
"Precise Longitude: {} degs, {:2.4f} mins".format(
95-
gps.longitude_degrees, gps.longitude_minutes
96-
)
97-
)
98-
print("Fix quality: {}".format(gps.fix_quality))
87+
print(f"Latitude: {gps.latitude:.6f} degrees")
88+
print(f"Longitude: {gps.longitude:.6f} degrees")
89+
print(f"Precise Latitude: {gps.latitude_degrees} degs, {gps.latitude_minutes:2.4f} mins")
90+
print(f"Precise Longitude: {gps.longitude_degrees} degs, {gps.longitude_minutes:2.4f} mins")
91+
print(f"Fix quality: {gps.fix_quality}")
9992
# Some attributes beyond latitude, longitude and timestamp are optional
10093
# and might not be present. Check if they're None before trying to use!
10194
if gps.satellites is not None:
102-
print("# satellites: {}".format(gps.satellites))
95+
print(f"# satellites: {gps.satellites}")
10396
if gps.altitude_m is not None:
104-
print("Altitude: {} meters".format(gps.altitude_m))
97+
print(f"Altitude: {gps.altitude_m} meters")
10598
if gps.speed_knots is not None:
106-
print("Speed: {} knots".format(gps.speed_knots))
99+
print(f"Speed: {gps.speed_knots} knots")
107100
if gps.speed_kmh is not None:
108-
print("Speed: {} km/h".format(gps.speed_kmh))
101+
print(f"Speed: {gps.speed_kmh} km/h")
109102
if gps.track_angle_deg is not None:
110-
print("Track angle: {} degrees".format(gps.track_angle_deg))
103+
print(f"Track angle: {gps.track_angle_deg} degrees")
111104
if gps.horizontal_dilution is not None:
112-
print("Horizontal dilution: {}".format(gps.horizontal_dilution))
105+
print(f"Horizontal dilution: {gps.horizontal_dilution}")
113106
if gps.height_geoid is not None:
114-
print("Height geoid: {} meters".format(gps.height_geoid))
107+
print(f"Height geoid: {gps.height_geoid} meters")

‎examples/gps_time_source.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
# time while there is powersource (ie coin cell battery)
77

88
import time
9+
910
import board
1011
import busio
1112
import rtc
13+
1214
import adafruit_gps
1315

1416
uart = busio.UART(board.TX, board.RX, baudrate=9600, timeout=10)
@@ -26,14 +28,9 @@
2628

2729

2830
def _format_datetime(datetime):
29-
return "{:02}/{:02}/{} {:02}:{:02}:{:02}".format(
30-
datetime.tm_mon,
31-
datetime.tm_mday,
32-
datetime.tm_year,
33-
datetime.tm_hour,
34-
datetime.tm_min,
35-
datetime.tm_sec,
36-
)
31+
date_part = f"{datetime.tm_mon:02}/{datetime.tm_mday:02}/{datetime.tm_year}"
32+
time_part = f"{datetime.tm_hour:02}:{datetime.tm_min:02}:{datetime.tm_sec:02}"
33+
return f"{date_part} {time_part}"
3734

3835

3936
last_print = time.monotonic()
@@ -47,12 +44,12 @@ def _format_datetime(datetime):
4744
print("No time data from GPS yet")
4845
continue
4946
# Time & date from GPS informations
50-
print("Fix timestamp: {}".format(_format_datetime(gps.timestamp_utc)))
47+
print(f"Fix timestamp: {_format_datetime(gps.timestamp_utc)}")
5148

5249
# Time & date from internal RTC
53-
print("RTC timestamp: {}".format(_format_datetime(the_rtc.datetime)))
50+
print(f"RTC timestamp: {_format_datetime(the_rtc.datetime)}")
5451

5552
# Time & date from time.localtime() function
5653
local_time = time.localtime()
5754

58-
print("Local time: {}".format(_format_datetime(local_time)))
55+
print(f"Local time: {_format_datetime(local_time)}")

‎ruff.toml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
target-version = "py38"
6+
line-length = 100
7+
8+
[lint]
9+
preview = true
10+
select = ["I", "PL", "UP"]
11+
12+
extend-select = [
13+
"D419", # empty-docstring
14+
"E501", # line-too-long
15+
"W291", # trailing-whitespace
16+
"PLC0414", # useless-import-alias
17+
"PLC2401", # non-ascii-name
18+
"PLC2801", # unnecessary-dunder-call
19+
"PLC3002", # unnecessary-direct-lambda-call
20+
"E999", # syntax-error
21+
"PLE0101", # return-in-init
22+
"F706", # return-outside-function
23+
"F704", # yield-outside-function
24+
"PLE0116", # continue-in-finally
25+
"PLE0117", # nonlocal-without-binding
26+
"PLE0241", # duplicate-bases
27+
"PLE0302", # unexpected-special-method-signature
28+
"PLE0604", # invalid-all-object
29+
"PLE0605", # invalid-all-format
30+
"PLE0643", # potential-index-error
31+
"PLE0704", # misplaced-bare-raise
32+
"PLE1141", # dict-iter-missing-items
33+
"PLE1142", # await-outside-async
34+
"PLE1205", # logging-too-many-args
35+
"PLE1206", # logging-too-few-args
36+
"PLE1307", # bad-string-format-type
37+
"PLE1310", # bad-str-strip-call
38+
"PLE1507", # invalid-envvar-value
39+
"PLE2502", # bidirectional-unicode
40+
"PLE2510", # invalid-character-backspace
41+
"PLE2512", # invalid-character-sub
42+
"PLE2513", # invalid-character-esc
43+
"PLE2514", # invalid-character-nul
44+
"PLE2515", # invalid-character-zero-width-space
45+
"PLR0124", # comparison-with-itself
46+
"PLR0202", # no-classmethod-decorator
47+
"PLR0203", # no-staticmethod-decorator
48+
"UP004", # useless-object-inheritance
49+
"PLR0206", # property-with-parameters
50+
"PLR0904", # too-many-public-methods
51+
"PLR0911", # too-many-return-statements
52+
"PLR0912", # too-many-branches
53+
"PLR0913", # too-many-arguments
54+
"PLR0914", # too-many-locals
55+
"PLR0915", # too-many-statements
56+
"PLR0916", # too-many-boolean-expressions
57+
"PLR1702", # too-many-nested-blocks
58+
"PLR1704", # redefined-argument-from-local
59+
"PLR1711", # useless-return
60+
"C416", # unnecessary-comprehension
61+
"PLR1733", # unnecessary-dict-index-lookup
62+
"PLR1736", # unnecessary-list-index-lookup
63+
64+
# ruff reports this rule is unstable
65+
#"PLR6301", # no-self-use
66+
67+
"PLW0108", # unnecessary-lambda
68+
"PLW0120", # useless-else-on-loop
69+
"PLW0127", # self-assigning-variable
70+
"PLW0129", # assert-on-string-literal
71+
"B033", # duplicate-value
72+
"PLW0131", # named-expr-without-context
73+
"PLW0245", # super-without-brackets
74+
"PLW0406", # import-self
75+
"PLW0602", # global-variable-not-assigned
76+
"PLW0603", # global-statement
77+
"PLW0604", # global-at-module-level
78+
79+
# fails on the try: import typing used by libraries
80+
#"F401", # unused-import
81+
82+
"F841", # unused-variable
83+
"E722", # bare-except
84+
"PLW0711", # binary-op-exception
85+
"PLW1501", # bad-open-mode
86+
"PLW1508", # invalid-envvar-default
87+
"PLW1509", # subprocess-popen-preexec-fn
88+
"PLW2101", # useless-with-lock
89+
"PLW3301", # nested-min-max
90+
]
91+
92+
ignore = [
93+
"PLR2004", # magic-value-comparison
94+
"UP030", # format literals
95+
"PLW1514", # unspecified-encoding
96+
"PLR0913", # too-many-arguments
97+
"PLR0915", # too-many-statements
98+
"PLR0917", # too-many-positional-arguments
99+
"PLR0904", # too-many-public-methods
100+
"PLR0912", # too-many-branches
101+
"PLR0916", # too-many-boolean-expressions
102+
]
103+
104+
[lint.per-file-ignores]
105+
"tests/adafruit_gps_test.py" = ["PLC2701"]
106+
107+
[format]
108+
line-ending = "lf"

‎tests/adafruit_gps_test.py

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# pylint: disable=missing-function-docstring,missing-module-docstring,invalid-name,protected-access,no-self-use,missing-class-docstring
2-
31
# SPDX-FileCopyrightText: 2021 Jonas Kittner
42
#
53
# SPDX-License-Identifier: MIT
64
import time
75
from unittest import mock
8-
from freezegun import freeze_time
6+
97
import pytest
8+
from freezegun import freeze_time
109

11-
from adafruit_gps import _parse_degrees
12-
from adafruit_gps import _parse_int
13-
from adafruit_gps import _parse_float
14-
from adafruit_gps import _parse_str
15-
from adafruit_gps import _read_degrees
16-
from adafruit_gps import _parse_talker
17-
from adafruit_gps import _parse_data
18-
from adafruit_gps import _read_deg_mins
19-
from adafruit_gps import GPS
10+
from adafruit_gps import (
11+
GPS,
12+
_parse_data,
13+
_parse_degrees,
14+
_parse_float,
15+
_parse_int,
16+
_parse_str,
17+
_parse_talker,
18+
_read_deg_mins,
19+
_read_degrees,
20+
)
2021

2122

2223
@pytest.mark.parametrize(
@@ -115,7 +116,7 @@ def test_parse_data_unexpected_parameter_type():
115116
class UartMock:
116117
"""mocking the UART connection an its methods"""
117118

118-
def write(self, bytestr):
119+
def write(self, bytestr): # noqa: PLR6301
119120
print(bytestr, end="")
120121

121122
@property
@@ -202,12 +203,8 @@ def test_GPS_update_rmc_no_magnetic_variation():
202203

203204

204205
def test_GPS_update_rmc_fix_is_set():
205-
r_valid = (
206-
b"$GPRMC,215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*6A\r\n"
207-
)
208-
r_invalid = (
209-
b"$GPRMC,215032.086,V,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*7D\r\n"
210-
)
206+
r_valid = b"$GPRMC,215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*6A\r\n"
207+
r_invalid = b"$GPRMC,215032.086,V,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*7D\r\n"
211208
with mock.patch.object(GPS, "readline", return_value=r_valid):
212209
gps = GPS(uart=UartMock())
213210
assert gps.update()
@@ -221,9 +218,7 @@ def test_GPS_update_rmc_fix_is_set():
221218

222219

223220
def test_GPS_update_rmc_fix_is_set_new():
224-
r_valid = (
225-
b"$GPRMC,215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*6A\r\n"
226-
)
221+
r_valid = b"$GPRMC,215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A*6A\r\n"
227222
r_invalid = b"$GPRMC,215032.086,V,ABC,N,00123.12345,E,0.45,56.35,021021,,,A*1B\r\n"
228223
with mock.patch.object(GPS, "readline", return_value=r_valid):
229224
gps = GPS(uart=UartMock())
@@ -290,11 +285,8 @@ def test_GPS_update_rmc_debug_shows_sentence(capsys):
290285
gps = GPS(uart=UartMock(), debug=True)
291286
assert gps.update()
292287
out, err = capsys.readouterr()
293-
assert err == ""
294-
assert (
295-
out
296-
== "('GPRMC', '215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A')\n"
297-
)
288+
assert not err
289+
assert out == "('GPRMC', '215032.086,A,1234.5678,N,00123.12345,E,0.45,56.35,021021,,,A')\n"
298290

299291

300292
def test_GPS_update_data_type_too_short():
@@ -308,15 +300,15 @@ def test_GPS_send_command_with_checksum(capsys):
308300
gps = GPS(uart=UartMock())
309301
gps.send_command(command=b"$PMTK001,314,3\r\n", add_checksum=True)
310302
out, err = capsys.readouterr()
311-
assert err == ""
303+
assert not err
312304
assert out == ("b'$'" "b'$PMTK001,314,3\\r\\n'" "b'*'" "b'15'" "b'\\r\\n'")
313305

314306

315307
def test_GPS_send_command_without_checksum(capsys):
316308
gps = GPS(uart=UartMock())
317309
gps.send_command(command=b"$PMTK001,314,3\r\n", add_checksum=False)
318310
out, err = capsys.readouterr()
319-
assert err == ""
311+
assert not err
320312
assert out == ("b'$'" "b'$PMTK001,314,3\\r\\n'" "b'\\r\\n'")
321313

322314

@@ -391,21 +383,17 @@ def test_GPS_update_from_GGA():
391383
assert gps.has_3d_fix is False
392384
assert gps.datetime == exp_time
393385
assert (
394-
gps._raw_sentence
395-
== "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"
386+
gps._raw_sentence == "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"
396387
)
397388
assert (
398-
gps.nmea_sentence
399-
== "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"
389+
gps.nmea_sentence == "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"
400390
)
401391

402392

403393
@pytest.mark.parametrize(
404394
"r",
405395
(
406-
pytest.param(
407-
b"$GPGSA,A,3,15,18,14,,,31,,,23,,,,04.5,02.1,04.0*0f\r\n", id="smaller v4.1"
408-
),
396+
pytest.param(b"$GPGSA,A,3,15,18,14,,,31,,,23,,,,04.5,02.1,04.0*0f\r\n", id="smaller v4.1"),
409397
pytest.param(
410398
b"$GPGSA,A,3,15,18,14,,,31,,,23,,,,04.5,02.1,04.0,3*10\r\n",
411399
id="greater v4.1",

0 commit comments

Comments
 (0)
Please sign in to comment.