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 unittests for location.ParkingLocation #80

Merged
merged 4 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions mytoyota/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
class ParkingLocation:
"""ParkingLocation representation"""

latitude: float = None
longitude: float = None
timestamp: int = None
latitude: float = 0.0
longitude: float = 0.0
timestamp: int = 0

def __init__(self, parking: dict) -> None:
_LOGGER.debug("Raw parking location data: %s", str(parking))

self.latitude = float(parking.get("lat", None))
self.longitude = float(parking.get("lon", None))
self.timestamp = int(parking.get("timestamp", None))
self.latitude = float(parking.get("lat", 0.0))
self.longitude = float(parking.get("lon", 0.0))
self.timestamp = int(parking.get("timestamp", 0))

def __str__(self) -> str:
return str(self.as_dict())
Expand Down
23 changes: 23 additions & 0 deletions tests/test_parking_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""pytest tests for mytoyota.location.ParkingLocation"""

from mytoyota.location import ParkingLocation

# pylint: disable=no-self-use


class TestParkingLocation:
"""pytest functions to test ParkingLocation"""

def test_parking_location(self):
"""Test ParkingLocation"""
location = ParkingLocation({"timestamp": 987654, "lat": 1.234, "lon": 5.678})
assert location.latitude == 1.234
assert location.longitude == 5.678
assert location.timestamp == 987654

def test_parking_location_no_data(self):
"""Test ParkingLocation with no initialization data"""
location = ParkingLocation({})
assert location.latitude == 0.0
assert location.longitude == 0.0
assert location.timestamp == 0