Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'geopy' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
def test_output_format(self):
bbox = self.method([Point(50, 160), Point(30, 170)],
" %(lon2)s|%(lat2)s -- %(lat1)s|%(lon1)s ")
self.assertEqual(bbox, " 170.0|50.0 -- 30.0|160.0 ")
def test_point_setitem_normalization(self):
point = Point()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
with self.assertRaises(ValueError):
point[0] = 100
self.assertEqual(1, len(w))
self.assertEqual((0, 0, 0), tuple(point))
point[0] = -80
point[1] = 200
# Please note that attribute assignments are not normalized.
# Only __setitem__ assignments are.
self.assertEqual((-80, -160, 0), tuple(point))
with self.assertRaises(ValueError):
point[1] = float("nan")
self.assertEqual(1, len(w))
self.assertEqual((-80, -160, 0), tuple(point))
def test_reverse_with_language_de(self):
"""
Here.reverse using point and language parameter to get a non-English response
"""
res = self.reverse_run(
{"query": Point(40.753898, -73.985071), "language": "de-DE"},
{}
)
self.assertIn("Vereinigte Staaten", res.address)
def test_reverse_with_include_country_code(self):
"""
Bing.reverse using point and include country-code in the response
"""
res = self.reverse_run(
{"query": Point(40.753898, -73.985071),
"include_country_code": True},
{},
)
self.assertEqual(res.raw["address"].get("countryRegionIso2", 'missing'), 'US')
def test_point_from_string(self):
# Examples are from the docstring of `Point.from_string`.
self.assertEqual(Point("41.5;-81.0"), (41.5, -81.0, 0.0))
self.assertEqual(Point("41.5,-81.0"), (41.5, -81.0, 0.0))
self.assertEqual(Point("41.5 -81.0"), (41.5, -81.0, 0.0))
self.assertEqual(Point("41.5 N -81.0 W"), (41.5, 81.0, 0.0))
self.assertEqual(Point("-41.5 S;81.0 E"), (41.5, 81.0, 0.0))
self.assertEqual(Point("23 26m 22s N 23 27m 30s E"),
(23.439444444444444, 23.458333333333332, 0.0))
self.assertEqual(Point("23 26' 22\" N 23 27' 30\" E"),
(23.439444444444444, 23.458333333333332, 0.0))
self.assertEqual(Point(u("UT: N 39\xb020' 0'' / W 74\xb035' 0''")),
(39.333333333333336, -74.58333333333333, 0.0))
def test_point_assign_coordinates(self):
point = Point(self.lat + 10, self.lon + 10, self.alt + 10)
point.latitude = self.lat
point.longitude = self.lon
point.altitude = self.alt
self.assertEqual(point[0], self.lat)
self.assertEqual(point[1], self.lon)
self.assertEqual(point[2], self.alt)
self.assertEqual(self.coords, tuple(point))
self.assertEqual(point.latitude, self.lat)
self.assertEqual(point.longitude, self.lon)
self.assertEqual(point.altitude, self.alt)
def test_location_ne(self):
"""
Location.__ne__
"""
loc1 = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
loc2 = Location(GRAND_CENTRAL_STR, None)
self.assertNotEqual(loc1, loc2)
def test_check_status(self):
"""
GoogleV3 raises correctly on Google-specific API status flags
"""
self.assertEqual(self.geocoder._check_status("ZERO_RESULTS"), None)
with self.assertRaises(exc.GeocoderQuotaExceeded):
self.geocoder._check_status("OVER_QUERY_LIMIT")
with self.assertRaises(exc.GeocoderQueryError):
self.geocoder._check_status("REQUEST_DENIED")
with self.assertRaises(exc.GeocoderQueryError):
self.geocoder._check_status("INVALID_REQUEST")
with self.assertRaises(exc.GeocoderQueryError):
self.geocoder._check_status("_")
def test_ssl_context_with_proxy_is_respected(self):
# Create an ssl context which should not allow the negotiation with
# the `self.remote_website_https`.
bad_ctx = ssl.create_default_context(cafile=CERT_SELFSIGNED_CA)
geocoder_dummy = DummyGeocoder(proxies={"https": self.proxy_url},
ssl_context=bad_ctx,
timeout=self.timeout)
self.assertEqual(0, len(self.proxy_server.requests))
with self.assertRaises(GeocoderServiceError) as cm:
geocoder_dummy.geocode(self.remote_website_https)
self.assertIn('SSL', str(cm.exception))
self.assertEqual(1, len(self.proxy_server.requests))
# Non-geopy errors must not be swallowed
self.mock_func.side_effect = ValueError
with self.assertRaises(ValueError):
rl(sentinel.arg)
self.assertEqual(1, self.mock_func.call_count)
self.mock_func.reset_mock()
# geopy errors must be swallowed and retried
self.mock_func.side_effect = GeocoderServiceError
self.assertEqual(sentinel.return_value, rl(sentinel.arg))
self.assertEqual(4, self.mock_func.call_count)
self.mock_func.reset_mock()
# Successful value must be returned
self.mock_func.side_effect = [
GeocoderServiceError, GeocoderServiceError, sentinel.good
]
self.assertEqual(sentinel.good, rl(sentinel.arg))
self.assertEqual(3, self.mock_func.call_count)
self.mock_func.reset_mock()
# When swallowing is disabled, the exception must be raised
rl.swallow_exceptions = False
self.mock_func.side_effect = GeocoderQuotaExceeded
with self.assertRaises(GeocoderQuotaExceeded):
rl(sentinel.arg)
self.assertEqual(4, self.mock_func.call_count)
self.mock_func.reset_mock()