Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for sensors.py and adds pytest as as pre-commit hook #84

Merged
merged 2 commits into from
Oct 15, 2021
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ repos:
entry: poetry run pylint
language: system
types: [python]
- id: pytest-check
name: pytest-check
entry: pytest
language: system
pass_filenames: false
always_run: true
- id: codespell
name: codespell
entry: poetry run codespell --write-changes --skip="./*"
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Need for pytest or else it will cause an import error in pytest"""
2 changes: 1 addition & 1 deletion mytoyota/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Toyota Connected Services Client"""
"""Toyota Connected Services Client"""
43 changes: 14 additions & 29 deletions mytoyota/sensors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Sensor representation for mytoyota"""
import logging
from typing import Optional

from mytoyota.const import CLOSED, INCAR, LOCKED, OFF, STATE, WARNING

Expand All @@ -9,12 +10,9 @@
class Hood:
"""Representation of the hood of the car"""

warning: bool = False
closed: bool = True

def __init__(self, hood: dict) -> None:
self.warning = hood.get(WARNING, None)
self.closed = hood.get(CLOSED, None)
self.warning: Optional[bool] = hood.get(WARNING, None)
self.closed: Optional[bool] = hood.get(CLOSED, None)

def __str__(self) -> str:
return str(self.as_dict())
Expand All @@ -27,14 +25,10 @@ def as_dict(self) -> dict:
class Door:
"""Representation of a door"""

warning: bool = False
closed: bool = True
locked: bool = True

def __init__(self, door: dict) -> None:
self.warning = door.get(WARNING, None)
self.closed = door.get(CLOSED, None)
self.locked = door.get(LOCKED, None)
self.warning: Optional[bool] = door.get(WARNING, None)
self.closed: Optional[bool] = door.get(CLOSED, None)
self.locked: Optional[bool] = door.get(LOCKED, None)

def __str__(self) -> str:
return str(self.as_dict())
Expand All @@ -59,7 +53,7 @@ class Doors:
warning: bool = False

def __init__(self, doors: dict):
self.warning = doors[WARNING]
self.warning = doors.get(WARNING, None)

self.driverseat = Door(doors.get("driverSeatDoor", {}))
self.passengerseat = Door(doors.get("passengerSeatDoor", {}))
Expand All @@ -85,12 +79,9 @@ def as_dict(self) -> dict:
class Window:
"""Representation of a window"""

warning: bool = False
state: str = None

def __init__(self, window) -> None:
self.warning = window.get(WARNING, None)
self.state = window.get(STATE, None)
self.warning: Optional[bool] = window.get(WARNING, None)
self.state: Optional[str] = window.get(STATE, None)

def __str__(self) -> str:
return str(self.as_dict())
Expand All @@ -114,7 +105,7 @@ class Windows:
warning: bool = False

def __init__(self, windows: dict) -> None:
self.warning = windows[WARNING]
self.warning = windows.get(WARNING, None)

self.driverseat = Window(windows.get("driverSeatWindow", {}))
self.passengerseat = Window(windows.get("passengerSeatWindow", {}))
Expand All @@ -138,12 +129,9 @@ def as_dict(self) -> dict:
class Light:
"""Representation of the lights"""

warning: bool = False
off: bool = True

def __init__(self, light: dict) -> None:
self.warning = light.get(WARNING, None)
self.off = light.get(OFF, None)
self.warning: Optional[bool] = light.get(WARNING, None)
self.off: Optional[bool] = light.get(OFF, None)

def __str__(self) -> str:
return str(self.as_dict())
Expand Down Expand Up @@ -187,12 +175,9 @@ def as_dict(self) -> dict:
class Key:
"""Representation of the ignition"""

warning: bool = False
in_car: bool = False

def __init__(self, key: dict) -> None:
self.warning = key.get(WARNING, None)
self.in_car = key.get(INCAR, None)
self.warning: Optional[bool] = key.get(WARNING, None)
self.in_car: Optional[bool] = key.get(INCAR, None)

def __str__(self) -> str:
return str(self.as_dict())
Expand Down
Loading