From fb6a0a9f2d7a819a7447edbb2b5b922e497d543f Mon Sep 17 00:00:00 2001 From: John de Rooij Date: Sun, 10 Oct 2021 22:13:38 +0200 Subject: [PATCH] Add unittests for location.ParkingLocation --- mytoyota/location.py | 12 ++++++------ tests/test_parking_location.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 tests/test_parking_location.py diff --git a/mytoyota/location.py b/mytoyota/location.py index eb540336..ac13a3eb 100644 --- a/mytoyota/location.py +++ b/mytoyota/location.py @@ -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()) diff --git a/tests/test_parking_location.py b/tests/test_parking_location.py new file mode 100644 index 00000000..23848341 --- /dev/null +++ b/tests/test_parking_location.py @@ -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