/
test_geo.py
152 lines (117 loc) · 4.71 KB
/
test_geo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import re
import unittest
from decimal import Decimal
from faker import Faker
from faker.providers.geo.pt_PT import Provider as PtPtProvider
class TestGlobal(unittest.TestCase):
"""Tests geographic locations regardless of locale"""
def setUp(self):
self.fake = Faker() # No locale specified, gets global for this provider
Faker.seed(0)
def test_local_latlng(self):
loc = self.fake.local_latlng(country_code="US")
assert isinstance(loc, tuple)
assert len(loc) == 5
assert Decimal(loc[0])
assert Decimal(loc[1])
loc_short = self.fake.local_latlng(country_code="US", coords_only=True)
assert len(loc_short) == 2
assert Decimal(loc_short[0])
assert Decimal(loc_short[1])
class TestEnUS(unittest.TestCase):
"""Tests geographic locations in the en_US locale"""
def setUp(self):
self.fake = Faker("en_US")
Faker.seed(0)
def test_latitude(self):
lat = self.fake.latitude()
assert isinstance(lat, Decimal)
def test_longitude(self):
long = self.fake.longitude()
assert isinstance(long, Decimal)
def test_latlng(self):
loc = self.fake.latlng()
assert isinstance(loc, tuple)
assert len(loc) == 2
assert isinstance(loc[0], Decimal)
assert isinstance(loc[1], Decimal)
def test_coordinate(self):
loc = self.fake.coordinate()
assert isinstance(loc, Decimal)
def test_coordinate_centered(self):
loc = self.fake.coordinate(center=23)
assert round(loc) == 23
def test_coordinate_rounded(self):
loc = self.fake.coordinate(center=23, radius=3)
assert 20 <= round(loc) <= 26
def test_location_on_land(self):
loc = self.fake.location_on_land()
assert isinstance(loc, tuple)
assert len(loc) == 5
assert Decimal(loc[0]) # Should be able to cast first two elements of tuple to Decimal
assert Decimal(loc[1])
assert isinstance(loc[2], str) # Place is a string
assert isinstance(loc[3], str) # Country code is a string
assert len(loc[3]) == 2 # Country code is two letters
assert isinstance(loc[4], str) # Timezone is a string
def test_location_on_land_coords_only(self):
loc = self.fake.location_on_land(coords_only=True)
assert isinstance(loc, tuple)
assert len(loc) == 2
assert Decimal(loc[0]) # Should be able to cast first two elements of tuple to Decimal
assert Decimal(loc[1])
class TestSkSk(unittest.TestCase):
def setUp(self):
self.fake = Faker("sk_SK")
Faker.seed(0)
def test_location_on_land(self):
loc = self.fake.location_on_land()
assert isinstance(loc, tuple)
assert len(loc) == 5
assert Decimal(loc[0]) # Should be able to cast first two elements of tuple to Decimal
assert Decimal(loc[1])
assert isinstance(loc[2], str) # Place is a string
assert isinstance(loc[3], str) # Country code is a string
assert len(loc[3]) == 2 # Country code is two letters
assert isinstance(loc[4], str) # Timezone is a string
class TestCsCz(unittest.TestCase):
def setUp(self):
self.fake = Faker("cs_CZ")
Faker.seed(0)
def test_location_on_land(self):
loc = self.fake.location_on_land()
assert isinstance(loc, tuple)
assert len(loc) == 5
assert Decimal(loc[0]) # Should be able to cast first two elements of tuple to Decimal
assert Decimal(loc[1])
assert isinstance(loc[2], str) # Place is a string
assert isinstance(loc[3], str) # Country code is a string
assert len(loc[3]) == 2 # Country code is two letters
assert isinstance(loc[4], str) # Timezone is a string
class TestDeAT(unittest.TestCase):
"""Tests in addresses in the de_AT locale"""
def setUp(self):
self.fake = Faker("de_AT")
Faker.seed(0)
def test_local_latitude(self):
local_latitude = self.fake.local_latitude()
assert re.match(r"4[6-8]\.\d+", str(local_latitude))
def test_local_longitude(self):
local_longitude = self.fake.local_longitude()
assert re.match(r"1[1-5]\.\d+", str(local_longitude))
class TestPtPT(unittest.TestCase):
def setUp(self):
self.fake = Faker("pt_PT")
Faker.seed(0)
def test_nationality(self):
nationality = self.fake.nationality()
assert isinstance(nationality, str)
assert nationality in PtPtProvider.nationalities
class TestTrTr(TestEnUS):
def setUp(self):
self.fake = Faker("tr_TR")
Faker.seed(0)
class TestEnIe(TestEnUS):
def setUp(self):
self.fake = Faker("en_IE")
Faker.seed(0)