Skip to content

Commit

Permalink
Add unittests for location.ParkingLocation (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
joro75 authored Oct 11, 2021
1 parent 75d5447 commit 08eddb8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
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

0 comments on commit 08eddb8

Please sign in to comment.