Skip to content

Commit a3f835c

Browse files
committed
Testing Singleton
1 parent e56338d commit a3f835c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

app/coordinates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"""app.coordinates.py"""
2+
3+
24
class Coordinates:
35
"""
46
A position on earth using decimal coordinates (latitude and longitude).
57
"""
8+
69
def __init__(self, latitude, longitude):
710
self.latitude = latitude
811
self.longitude = longitude
912

1013
def serialize(self):
1114
"""
1215
Serializes the coordinates into a dict.
16+
1317
:returns: The serialized coordinates.
1418
:rtype: dict
1519
"""

app/data/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
def data_source(source):
1515
"""
1616
Retrieves the provided data-source service.
17+
1718
:returns: The service.
1819
:rtype: LocationService
1920
"""

tests/test_countries.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@
2121
)
2222
def test_countries_country_name__country_code(country_name, expected_country_code):
2323
assert countries.country_code(country_name) == expected_country_code
24+
25+
__shared_instance = None
26+
@staticmethod
27+
def getInstance():
28+
"""Static Access Methods """
29+
if Country.__shared_instance == None:
30+
Country()
31+
return Country.__shared_instance
32+
33+
def __init__(self) -> None:
34+
""" Virtual Private Constructor"""
35+
if Country.__shared_instance != None:
36+
raise Exception("Singleton Class already initialized. Please use getInstance()")
37+
else:
38+
Country.__shared_instance = self

0 commit comments

Comments
 (0)