diff --git a/bandit.yml b/bandit.yml deleted file mode 100644 index faa41c53..00000000 --- a/bandit.yml +++ /dev/null @@ -1,2 +0,0 @@ -assert_used: - skips: ["./tests/*"] diff --git a/pyproject.toml b/pyproject.toml index 94b4d806..ead318fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/src/renault_api/cli/charge/schedule.py b/src/renault_api/cli/charge/schedule.py index 5db8de8e..eee32355 100644 --- a/src/renault_api/cli/charge/schedule.py +++ b/src/renault_api/cli/charge/schedule.py @@ -27,6 +27,7 @@ "," "(?P[0-9]+)" ) +_HOURS_PER_DAY = 24 @click.group() @@ -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." diff --git a/src/renault_api/cli/renault_settings.py b/src/renault_api/cli/renault_settings.py index a3cb5c56..3461c67e 100644 --- a/src/renault_api/cli/renault_settings.py +++ b/src/renault_api/cli/renault_settings.py @@ -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"])) diff --git a/src/renault_api/gigya/__init__.py b/src/renault_api/gigya/__init__.py index e0189c40..c72c79cc 100644 --- a/src/renault_api/gigya/__init__.py +++ b/src/renault_api/gigya/__init__.py @@ -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: diff --git a/src/renault_api/renault_vehicle.py b/src/renault_api/renault_vehicle.py index d953977d..cb778050 100644 --- a/src/renault_api/renault_vehicle.py +++ b/src/renault_api/renault_vehicle.py @@ -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 @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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( @@ -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( @@ -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( @@ -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( @@ -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, @@ -448,7 +432,6 @@ 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( @@ -456,7 +439,7 @@ async def set_hvac_schedules( 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, @@ -475,7 +458,6 @@ 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( @@ -483,7 +465,7 @@ async def set_charge_schedules( 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, @@ -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( @@ -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", @@ -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", diff --git a/tests/conftest.py b/tests/conftest.py index cda1cae2..14ecf462 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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() @@ -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( diff --git a/tests/gigya/test_gigya.py b/tests/gigya/test_gigya.py index 7ea6d773..feea6ce9 100644 --- a/tests/gigya/test_gigya.py +++ b/tests/gigya/test_gigya.py @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/tests/kamereon/test_kamereon.py b/tests/kamereon/test_kamereon.py index 4e1f7077..90753736 100644 --- a/tests/kamereon/test_kamereon.py +++ b/tests/kamereon/test_kamereon.py @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/tests/kamereon/test_kamereon_vehicle_action.py b/tests/kamereon/test_kamereon_vehicle_action.py index 4d3129d0..a23ef8cf 100644 --- a/tests/kamereon/test_kamereon_vehicle_action.py +++ b/tests/kamereon/test_kamereon_vehicle_action.py @@ -54,7 +54,7 @@ def test_charge_schedule_for_json() -> None: # Check that for_json returns the same as the original data assert vehicle_data.schedules is not None for_json = { - "schedules": list(schedule.for_json() for schedule in vehicle_data.schedules) + "schedules": [schedule.for_json() for schedule in vehicle_data.schedules] } assert for_json == { "schedules": [ @@ -149,7 +149,7 @@ def test_charge_schedule_for_json() -> None: # Activated flag has been updated in 'vehicle_data.update' # Refresh for_json with the updated data for_json = { # type: ignore[unreachable] - "schedules": list(schedule.for_json() for schedule in vehicle_data.schedules) + "schedules": [schedule.for_json() for schedule in vehicle_data.schedules] } assert for_json == { "schedules": [ @@ -227,7 +227,7 @@ def test_hvac_schedule_for_json() -> None: # verify for_json returns proper original data assert vehicle_data.schedules is not None for_json = { - "schedules": list(schedule.for_json() for schedule in vehicle_data.schedules) + "schedules": [schedule.for_json() for schedule in vehicle_data.schedules] } expected_json = { "schedules": [ @@ -278,7 +278,7 @@ def test_hvac_schedule_for_json() -> None: ) for_json = { - "schedules": list(schedule.for_json() for schedule in vehicle_data.schedules) + "schedules": [schedule.for_json() for schedule in vehicle_data.schedules] } expected_json = { "schedules": [ diff --git a/tests/kamereon/test_kamereon_vehicle_contract.py b/tests/kamereon/test_kamereon_vehicle_contract.py index 3ed3268d..ac0dcd19 100644 --- a/tests/kamereon/test_kamereon_vehicle_contract.py +++ b/tests/kamereon/test_kamereon_vehicle_contract.py @@ -42,13 +42,6 @@ def test_has_required_contract_1() -> None: assert response.contractList is not None assert has_required_contracts(response.contractList, "battery-status") - # "Deprecated in 0.1.3, contract codes are country-specific" - # " and can't be used to guess requirements." - # assert not has_required_contracts(response.contractList, "charge-mode") - # assert not has_required_contracts(response.contractList, "charging-settings") - # assert not has_required_contracts(response.contractList, "hvac-history") - # assert not has_required_contracts(response.contractList, "hvac-sessions") - # assert not has_required_contracts(response.contractList, "hvac-status") def test_has_required_contract_2() -> None: diff --git a/tests/ruff.toml b/tests/ruff.toml new file mode 100644 index 00000000..91447072 --- /dev/null +++ b/tests/ruff.toml @@ -0,0 +1,13 @@ +# This extend our general Ruff rules specifically for tests +extend = "../pyproject.toml" + +[lint] +extend-ignore = [ + "PLR2004", # Magic value used in comparison, consider replacing +] + +[lint.isort] +known-first-party = [ + "renault-api", + "tests", +] diff --git a/tests/test_api_keys.py b/tests/test_api_keys.py index b0ded334..a1b100f2 100644 --- a/tests/test_api_keys.py +++ b/tests/test_api_keys.py @@ -14,7 +14,7 @@ from renault_api.helpers import get_api_keys -@pytest.mark.asyncio +@pytest.mark.asyncio() @pytest.mark.parametrize("locale", AVAILABLE_LOCALES.keys()) async def test_available_locales(locale: str) -> None: """Ensure all items AVAILABLE_LOCALES have correct data.""" @@ -31,7 +31,7 @@ async def test_available_locales(locale: str) -> None: assert api_keys[key] -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_missing_aiohttp_session() -> None: """Ensure failure to unknown locale if aiohttp_session is not set.""" locale = "invalid" @@ -41,7 +41,7 @@ async def test_missing_aiohttp_session() -> None: assert "aiohttp_session is not set." in str(excinfo) -@pytest.mark.asyncio +@pytest.mark.asyncio() @pytest.mark.parametrize("locale", AVAILABLE_LOCALES.keys()) @pytest.mark.skip(reason="Makes real calls to Renault servers") async def test_preload_force_api_keys(websession: ClientSession, locale: str) -> None: @@ -53,7 +53,7 @@ async def test_preload_force_api_keys(websession: ClientSession, locale: str) -> assert api_keys == expected_api_keys -@pytest.mark.asyncio +@pytest.mark.asyncio() @pytest.mark.skip("API keys are out of date.") async def test_preload_unknown_api_keys( websession: ClientSession, mocked_responses: aioresponses @@ -73,7 +73,7 @@ async def test_preload_unknown_api_keys( assert api_keys == expected_api_keys -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_preload_invalid_api_keys( websession: ClientSession, mocked_responses: aioresponses ) -> None: diff --git a/tests/test_renault_account.py b/tests/test_renault_account.py index 71a97b17..793a3f04 100644 --- a/tests/test_renault_account.py +++ b/tests/test_renault_account.py @@ -15,7 +15,7 @@ from renault_api.renault_account import RenaultAccount -@pytest.fixture +@pytest.fixture() def account(websession: aiohttp.ClientSession) -> RenaultAccount: """Fixture for testing RenaultAccount.""" return RenaultAccount( @@ -40,7 +40,7 @@ def tests_init(websession: aiohttp.ClientSession) -> None: ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_vehicles( account: RenaultAccount, mocked_responses: aioresponses ) -> None: @@ -49,7 +49,7 @@ async def test_get_vehicles( await account.get_vehicles() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_api_vehicles( account: RenaultAccount, mocked_responses: aioresponses ) -> None: @@ -58,7 +58,7 @@ async def test_get_api_vehicles( await account.get_api_vehicles() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_api_vehicle(account: RenaultAccount) -> None: """Test get_api_vehicle.""" vehicle = await account.get_api_vehicle(TEST_VIN) diff --git a/tests/test_renault_client.py b/tests/test_renault_client.py index 3164eb4f..19654b95 100644 --- a/tests/test_renault_client.py +++ b/tests/test_renault_client.py @@ -14,7 +14,7 @@ from renault_api.renault_client import RenaultClient -@pytest.fixture +@pytest.fixture() def client(websession: aiohttp.ClientSession) -> RenaultClient: """Fixture for testing RenaultClient.""" return RenaultClient( @@ -36,7 +36,7 @@ def test_init(websession: aiohttp.ClientSession) -> None: ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_person( client: RenaultClient, mocked_responses: aioresponses ) -> None: @@ -47,7 +47,7 @@ async def test_get_person( assert len(person.accounts) == 2 -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_api_accounts( client: RenaultClient, mocked_responses: aioresponses ) -> None: @@ -57,7 +57,7 @@ async def test_get_api_accounts( assert len(accounts) == 2 -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_api_account(client: RenaultClient) -> None: """Test get_api_account.""" account = await client.get_api_account(TEST_ACCOUNT_ID) diff --git a/tests/test_renault_session.py b/tests/test_renault_session.py index 57633996..1c0ab96e 100644 --- a/tests/test_renault_session.py +++ b/tests/test_renault_session.py @@ -35,7 +35,7 @@ def get_logged_in_session(websession: aiohttp.ClientSession) -> RenaultSession: ) -@pytest.fixture +@pytest.fixture() def session(websession: aiohttp.ClientSession) -> RenaultSession: """Fixture for testing RenaultSession.""" return RenaultSession( @@ -45,7 +45,7 @@ def session(websession: aiohttp.ClientSession) -> RenaultSession: ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_init_locale_only(websession: aiohttp.ClientSession) -> None: """Test initialisation with locale only.""" session = RenaultSession( @@ -59,7 +59,7 @@ async def test_init_locale_only(websession: aiohttp.ClientSession) -> None: assert await session._get_kamereon_root_url() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_init_country_only(websession: aiohttp.ClientSession) -> None: """Test initialisation with country only.""" session = RenaultSession( @@ -89,7 +89,7 @@ async def test_init_country_only(websession: aiohttp.ClientSession) -> None: assert await session._get_kamereon_root_url() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_init_locale_details_only(websession: aiohttp.ClientSession) -> None: """Test initialisation with locale_details only.""" session = RenaultSession( @@ -107,7 +107,7 @@ async def test_init_locale_details_only(websession: aiohttp.ClientSession) -> No assert await session._get_kamereon_root_url() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_init_locale_and_details(websession: aiohttp.ClientSession) -> None: """Test initialisation with locale and locale_details.""" session = RenaultSession( @@ -122,7 +122,7 @@ async def test_init_locale_and_details(websession: aiohttp.ClientSession) -> Non assert await session._get_kamereon_root_url() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_init_locale_country(websession: aiohttp.ClientSession) -> None: """Test initialisation with locale and country.""" session = RenaultSession( @@ -137,7 +137,7 @@ async def test_init_locale_country(websession: aiohttp.ClientSession) -> None: assert await session._get_kamereon_root_url() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_not_logged_in(session: RenaultSession) -> None: """Test errors when not logged in.""" with pytest.raises( @@ -159,7 +159,7 @@ async def test_not_logged_in(session: RenaultSession) -> None: await session._get_jwt() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_login(session: RenaultSession, mocked_responses: aioresponses) -> None: """Test login/person/jwt response.""" fixtures.inject_gigya_all(mocked_responses) @@ -180,7 +180,7 @@ async def test_login(session: RenaultSession, mocked_responses: aioresponses) -> assert len(mocked_responses.requests) == 3 -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_expired_login_token( websession: aiohttp.ClientSession, mocked_responses: aioresponses ) -> None: diff --git a/tests/test_renault_vehicle.py b/tests/test_renault_vehicle.py index fc9d51eb..f5887773 100644 --- a/tests/test_renault_vehicle.py +++ b/tests/test_renault_vehicle.py @@ -24,7 +24,7 @@ from renault_api.renault_vehicle import RenaultVehicle -@pytest.fixture +@pytest.fixture() def vehicle(websession: aiohttp.ClientSession) -> RenaultVehicle: """Fixture for testing RenaultVehicle.""" return RenaultVehicle( @@ -52,7 +52,7 @@ def test_init(websession: aiohttp.ClientSession) -> None: ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_details( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -64,7 +64,7 @@ async def test_get_details( assert await vehicle.get_details() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_car_adapter( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -76,7 +76,7 @@ async def test_get_car_adapter( assert await vehicle.get_car_adapter() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_contracts( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -89,7 +89,7 @@ async def test_get_contracts( assert await vehicle.get_contracts() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_has_contract_for_endpoint_1( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -101,20 +101,16 @@ async def test_has_contract_for_endpoint_1( assert await vehicle.has_contract_for_endpoint("charge-mode") -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_has_contract_for_endpoint_2( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: """Test has_contract_for_endpoint.""" fixtures.inject_get_vehicle_contracts(mocked_responses, "fr_FR.1.json") assert await vehicle.has_contract_for_endpoint("battery-status") - # "Deprecated in 0.1.3, contract codes are country-specific" - # " and can't be used to guess requirements." - # assert not await vehicle.has_contract_for_endpoint("hvac-status") - # assert not await vehicle.has_contract_for_endpoint("charge-mode") -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_battery_status( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -123,7 +119,7 @@ async def test_get_battery_status( assert await vehicle.get_battery_status() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_location( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -132,7 +128,7 @@ async def test_get_location( assert await vehicle.get_location() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_hvac_status( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -141,7 +137,7 @@ async def test_get_hvac_status( assert await vehicle.get_hvac_status() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_hvac_settings( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -155,8 +151,10 @@ async def test_get_hvac_settings( assert schedules assert schedules[1].id == 2 assert schedules[1].activated is True - assert schedules[1].wednesday and schedules[1].wednesday.readyAtTime == "T15:15Z" - assert schedules[1].friday and schedules[1].friday.readyAtTime == "T15:15Z" + assert schedules[1].wednesday + assert schedules[1].wednesday.readyAtTime == "T15:15Z" + assert schedules[1].friday + assert schedules[1].friday.readyAtTime == "T15:15Z" for i in (0, 2, 3, 4): assert schedules[i].id == i + 1 @@ -165,7 +163,7 @@ async def test_get_hvac_settings( assert schedules[i].__dict__[day] is None -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_charge_mode( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -174,7 +172,7 @@ async def test_get_charge_mode( assert await vehicle.get_charge_mode() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_cockpit( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -183,7 +181,7 @@ async def test_get_cockpit( assert await vehicle.get_cockpit() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_lock_status( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -192,7 +190,7 @@ async def test_get_lock_status( assert await vehicle.get_lock_status() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_charging_settings( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -201,7 +199,7 @@ async def test_get_charging_settings( assert await vehicle.get_charging_settings() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_notification_settings( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -210,7 +208,7 @@ async def test_get_notification_settings( assert await vehicle.get_notification_settings() -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_charge_history_month( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -223,7 +221,7 @@ async def test_get_charge_history_month( ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_charge_history_day( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -236,7 +234,7 @@ async def test_get_charge_history_day( ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_charges( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -248,7 +246,7 @@ async def test_get_charges( ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_hvac_history( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -261,7 +259,7 @@ async def test_get_hvac_history( ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_get_hvac_sessions( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -273,7 +271,7 @@ async def test_get_hvac_sessions( ) -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_set_ac_start( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -298,7 +296,7 @@ async def test_set_ac_start( assert expected_json == request.kwargs["json"] -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_set_ac_stop( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -313,7 +311,7 @@ async def test_set_ac_stop( assert expected_json == request.kwargs["json"] -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_set_charge_mode( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -329,7 +327,7 @@ async def test_set_charge_mode( assert expected_json == request.kwargs["json"] -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_set_charge_schedules( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -347,7 +345,7 @@ async def test_set_charge_schedules( assert expected_json == request.kwargs["json"] -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_set_charge_start( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: @@ -364,7 +362,7 @@ async def test_set_charge_start( assert expected_json == request.kwargs["json"] -@pytest.mark.asyncio +@pytest.mark.asyncio() async def test_set_hvac_schedules( vehicle: RenaultVehicle, mocked_responses: aioresponses ) -> None: