Skip to content
Prev Previous commit
Next Next commit
Testing Singleton
  • Loading branch information
Solracion committed Aug 12, 2021
commit a3f835c8bfff061464f20f7dbee6047b245f2aed
4 changes: 4 additions & 0 deletions app/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"""app.coordinates.py"""


class Coordinates:
"""
A position on earth using decimal coordinates (latitude and longitude).
"""

def __init__(self, latitude, longitude):
self.latitude = latitude
self.longitude = longitude

def serialize(self):
"""
Serializes the coordinates into a dict.

:returns: The serialized coordinates.
:rtype: dict
"""
Expand Down
1 change: 1 addition & 0 deletions app/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
def data_source(source):
"""
Retrieves the provided data-source service.

:returns: The service.
:rtype: LocationService
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/test_countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@
)
def test_countries_country_name__country_code(country_name, expected_country_code):
assert countries.country_code(country_name) == expected_country_code

__shared_instance = None
@staticmethod
def getInstance():
"""Static Access Methods """
if Country.__shared_instance == None:
Country()
return Country.__shared_instance

def __init__(self) -> None:
""" Virtual Private Constructor"""
if Country.__shared_instance != None:
raise Exception("Singleton Class already initialized. Please use getInstance()")
else:
Country.__shared_instance = self