Skip to content

Commit

Permalink
Unignore Ruff rules (#1138)
Browse files Browse the repository at this point in the history
* Ruff fixes

* More fixes

* More fixes

* More fixes

* More fixes

* More fixes

* More fixes
  • Loading branch information
epenet authored Apr 16, 2024
1 parent 2ca6618 commit 6271a32
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 124 deletions.
2 changes: 0 additions & 2 deletions bandit.yml

This file was deleted.

11 changes: 1 addition & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,16 @@ warn_unused_configs = true
warn_unused_ignores = true

[tool.ruff]
line-length = 80
line-length = 88
target-version = "py38"

[tool.ruff.lint]
ignore = [
"A001", # Variable is shadowing a Python builtin
"A002", # Argument is shadowing a Python builtin
"C400", # Unnecessary generator
"E501", # Line too long (81 > 80)
"ERA001", # Found commented-out code
"N815", # Variable in class scope should not be mixedCase
"PLR2004", # Magic value used in comparison, consider replacing
"PLR0911", # Too many return statements
"PLR0913", # Too many arguments in function definition
"PT001", # Use `@pytest.fixture()` over `@pytest.fixture`
"PT018", # Assertion should be broken down into multiple parts
"PT022", # No teardown in fixture `cli_runner`, use `return` instead of `yield`
"PT023", # Use `@pytest.mark.asyncio()` over `@pytest.mark.asyncio`
"PLW0127", # Self-assignment of variable
]
select = [
"A", #flake8-builtins
Expand Down
3 changes: 2 additions & 1 deletion src/renault_api/cli/charge/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
","
"(?P<duration>[0-9]+)"
)
_HOURS_PER_DAY = 24


@click.group()
Expand Down Expand Up @@ -208,7 +209,7 @@ def _parse_day_schedule(raw: str) -> Tuple[str, int]:
)

hours = int(match.group("hours"))
if hours > 23: # pragma: no cover
if hours >= _HOURS_PER_DAY: # pragma: no cover
raise ValueError(
f"Invalid specification for charge schedule: `{raw}`. "
"Hours should be less than 24."
Expand Down
4 changes: 2 additions & 2 deletions src/renault_api/cli/renault_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def display_settings(ctx_data: Dict[str, Any]) -> None:
"""Get the current configuration keys."""
credential_store: CredentialStore = ctx_data["credential_store"]
wrapper = TextWrapper(width=80)
items = list(
items = [
[key, "\n".join(wrapper.wrap(credential_store.get_value(key) or "-"))]
for key in credential_store._store.keys()
)
]
click.echo(tabulate(items, headers=["Key", "Value"]))


Expand Down
8 changes: 1 addition & 7 deletions src/renault_api/gigya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ async def request(
"""Send request to Gigya."""
async with websession.request(method, url, data=data) as http_response:
response_text = await http_response.text()
# Disable logging on Gigya, to avoid unnecessary exposure.
# _LOGGER.debug(
# "Received Gigya response %s on %s: %s",
# http_response.status,
# url,
# response_text,
# )
# Don't log on Gigya, to avoid unnecessary exposure.
try:
gigya_response: models.GigyaResponse = schema.loads(response_text)
except JSONDecodeError as err:
Expand Down
27 changes: 4 additions & 23 deletions src/renault_api/renault_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ async def get_car_adapter(self) -> models.KamereonVehicleCarAdapterData:

async def get_contracts(self) -> List[models.KamereonVehicleContract]:
"""Get vehicle contracts."""
# await self.warn_on_method("get_contracts")
if self._contracts:
return self._contracts

Expand All @@ -127,7 +126,6 @@ async def get_contracts(self) -> List[models.KamereonVehicleContract]:

async def get_battery_status(self) -> models.KamereonVehicleBatteryStatusData:
"""Get vehicle battery status."""
# await self.warn_on_method("get_battery_status")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -140,7 +138,6 @@ async def get_battery_status(self) -> models.KamereonVehicleBatteryStatusData:

async def get_location(self) -> models.KamereonVehicleLocationData:
"""Get vehicle location."""
# await self.warn_on_method("get_location")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -153,7 +150,6 @@ async def get_location(self) -> models.KamereonVehicleLocationData:

async def get_hvac_status(self) -> models.KamereonVehicleHvacStatusData:
"""Get vehicle hvac status."""
# await self.warn_on_method("get_hvac_status")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -166,7 +162,6 @@ async def get_hvac_status(self) -> models.KamereonVehicleHvacStatusData:

async def get_hvac_settings(self) -> models.KamereonVehicleHvacSettingsData:
"""Get vehicle hvac settings (schedule+mode)."""
# await self.warn_on_method("get_hvac_settings")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -179,7 +174,6 @@ async def get_hvac_settings(self) -> models.KamereonVehicleHvacSettingsData:

async def get_charge_mode(self) -> models.KamereonVehicleChargeModeData:
"""Get vehicle charge mode."""
# await self.warn_on_method("get_charge_mode")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -192,7 +186,6 @@ async def get_charge_mode(self) -> models.KamereonVehicleChargeModeData:

async def get_cockpit(self) -> models.KamereonVehicleCockpitData:
"""Get vehicle cockpit."""
# await self.warn_on_method("get_cockpit")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -205,7 +198,6 @@ async def get_cockpit(self) -> models.KamereonVehicleCockpitData:

async def get_lock_status(self) -> models.KamereonVehicleLockStatusData:
"""Get vehicle lock status."""
# await self.warn_on_method("get_lock_status")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -218,7 +210,6 @@ async def get_lock_status(self) -> models.KamereonVehicleLockStatusData:

async def get_res_state(self) -> models.KamereonVehicleResStateData:
"""Get vehicle res state."""
# await self.warn_on_method("get_res_state")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -231,7 +222,6 @@ async def get_res_state(self) -> models.KamereonVehicleResStateData:

async def get_charging_settings(self) -> models.KamereonVehicleChargingSettingsData:
"""Get vehicle charging settings."""
# await self.warn_on_method("get_charging_settings")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -246,7 +236,6 @@ async def get_notification_settings(
self,
) -> models.KamereonVehicleNotificationSettingsData:
"""Get vehicle notification settings."""
# await self.warn_on_method("get_notification_settings")
response = await self.session.get_vehicle_data(
account_id=self.account_id,
vin=self.vin,
Expand All @@ -263,7 +252,6 @@ async def get_charge_history(
self, start: datetime, end: datetime, period: str
) -> models.KamereonVehicleChargeHistoryData:
"""Get vehicle charge history."""
# await self.warn_on_method("get_charge_history")
if not isinstance(start, datetime): # pragma: no cover
raise TypeError(
"`start` should be an instance of datetime.datetime, not {}".format(
Expand Down Expand Up @@ -299,7 +287,6 @@ async def get_charges(
self, start: datetime, end: datetime
) -> models.KamereonVehicleChargesData:
"""Get vehicle charges."""
# await self.warn_on_method("get_charges")
if not isinstance(start, datetime): # pragma: no cover
raise TypeError(
"`start` should be an instance of datetime.datetime, not {}".format(
Expand Down Expand Up @@ -332,7 +319,6 @@ async def get_hvac_history(
self, start: datetime, end: datetime, period: str
) -> models.KamereonVehicleHvacHistoryData:
"""Get vehicle hvac history."""
# await self.warn_on_method("get_hvac_history")
if not isinstance(start, datetime): # pragma: no cover
raise TypeError(
"`start` should be an instance of datetime.datetime, not {}".format(
Expand Down Expand Up @@ -368,7 +354,6 @@ async def get_hvac_sessions(
self, start: datetime, end: datetime
) -> models.KamereonVehicleHvacSessionsData:
"""Get vehicle hvac sessions."""
# await self.warn_on_method("get_hvac_sessions")
if not isinstance(start, datetime): # pragma: no cover
raise TypeError(
"`start` should be an instance of datetime.datetime, not {}".format(
Expand Down Expand Up @@ -401,7 +386,6 @@ async def set_ac_start(
self, temperature: float, when: Optional[datetime] = None
) -> models.KamereonVehicleHvacStartActionData:
"""Start vehicle ac."""
# await self.warn_on_method("set_ac_start")
attributes = {
"action": "start",
"targetTemperature": temperature,
Expand Down Expand Up @@ -448,15 +432,14 @@ async def set_hvac_schedules(
self, schedules: List[models.HvacSchedule]
) -> models.KamereonVehicleHvacScheduleActionData:
"""Set vehicle charge schedules."""
# await self.warn_on_method("set_hvac_schedules")
for schedule in schedules:
if not isinstance(schedule, models.HvacSchedule): # pragma: no cover
raise TypeError(
"`schedules` should be a list of HvacSchedule, not {}".format(
schedules.__class__
)
)
attributes = {"schedules": list(schedule.for_json() for schedule in schedules)}
attributes = {"schedules": [schedule.for_json() for schedule in schedules]}

response = await self.session.set_vehicle_action(
account_id=self.account_id,
Expand All @@ -475,15 +458,14 @@ async def set_charge_schedules(
self, schedules: List[models.ChargeSchedule]
) -> models.KamereonVehicleChargeScheduleActionData:
"""Set vehicle charge schedules."""
# await self.warn_on_method("set_charge_schedules")
for schedule in schedules:
if not isinstance(schedule, models.ChargeSchedule): # pragma: no cover
raise TypeError(
"`schedules` should be a list of ChargeSchedule, not {}".format(
schedules.__class__
)
)
attributes = {"schedules": list(schedule.for_json() for schedule in schedules)}
attributes = {"schedules": [schedule.for_json() for schedule in schedules]}

response = await self.session.set_vehicle_action(
account_id=self.account_id,
Expand All @@ -502,7 +484,6 @@ async def set_charge_mode(
self, charge_mode: str
) -> models.KamereonVehicleChargeModeActionData:
"""Set vehicle charge mode."""
# await self.warn_on_method("set_charge_mode")
attributes = {"action": charge_mode}

response = await self.session.set_vehicle_action(
Expand All @@ -522,7 +503,7 @@ async def set_charge_start(self) -> models.KamereonVehicleChargingStartActionDat

if details.controls_action_via_kcm("charge"):
attributes = {"action": "resume"}
response = response = await self.session.set_vehicle_action(
response = await self.session.set_vehicle_action(
account_id=self.account_id,
vin=self.vin,
endpoint="charge/pause-resume",
Expand Down Expand Up @@ -550,7 +531,7 @@ async def set_charge_stop(self) -> models.KamereonVehicleChargingStartActionData

if details.controls_action_via_kcm("charge"):
attributes = {"action": "pause"}
response = response = await self.session.set_vehicle_action(
response = await self.session.set_vehicle_action(
account_id=self.account_id,
vin=self.vin,
endpoint="charge/pause-resume",
Expand Down
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ def mocked_responses() -> Generator[aioresponses, None, None]:
yield m


@pytest.fixture
def cli_runner(
monkeypatch: MonkeyPatch, tmpdir: pathlib.Path
) -> Generator[CliRunner, None, None]:
@pytest.fixture()
def cli_runner(monkeypatch: MonkeyPatch, tmpdir: pathlib.Path) -> CliRunner:
"""Fixture for invoking command-line interfaces."""
runner = CliRunner()

Expand All @@ -65,7 +63,7 @@ def get_test_zone() -> Any:

monkeypatch.setattr("tzlocal.get_localzone", get_test_zone)

yield runner
return runner


def create_aiohttp_closed_event(
Expand Down
8 changes: 4 additions & 4 deletions tests/gigya/test_gigya.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from renault_api import gigya


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_login(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -32,7 +32,7 @@ async def test_login(
assert response.get_session_cookie() == TEST_LOGIN_TOKEN


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_login_error(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -49,7 +49,7 @@ async def test_login_error(
)


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_person_id(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -65,7 +65,7 @@ async def test_person_id(
assert response.get_person_id() == TEST_PERSON_ID


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_get_jwt_token(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand Down
10 changes: 5 additions & 5 deletions tests/kamereon/test_kamereon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from renault_api.kamereon import exceptions


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_get_person(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -37,7 +37,7 @@ async def test_get_person(
assert len(person.accounts) == 2


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_get_account_vehicles(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -54,7 +54,7 @@ async def test_get_account_vehicles(
)


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_get_vehicle_data(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -73,7 +73,7 @@ async def test_get_vehicle_data(
)


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_get_vehicle_data_xml_bad_gateway(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand All @@ -98,7 +98,7 @@ async def test_get_vehicle_data_xml_bad_gateway(
)


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_set_vehicle_action(
websession: aiohttp.ClientSession, mocked_responses: aioresponses
) -> None:
Expand Down
Loading

0 comments on commit 6271a32

Please sign in to comment.