def setUpClass(cls): cls.geocoder = IGNFrance(api_key=env.get('IGNFRANCE_KEY'), username=env.get('IGNFRANCE_USERNAME'), password=env.get('IGNFRANCE_PASSWORD'), referer=env.get('IGNFRANCE_REFERER'), timeout=20) cls.delta_exact = 0.2
def setUpClass(cls): if not credentials: return cls.geocoder = IGNFrance( api_key=env.get('IGNFRANCE_KEY'), username=env.get('IGNFRANCE_USERNAME'), password=env.get('IGNFRANCE_PASSWORD'), referer=env.get('IGNFRANCE_REFERER'), timeout=10 ) cls.delta_exact = 0.2
def setUpClass(cls): cls.delta = 0.04 cls.geocoder = GeocodeFarm( # None api_key will use free tier on GeocodeFarm. api_key=env.get('GEOCODEFARM_KEY'), timeout=10, )
def setUpClass(cls): # setUpClass is still called even if test is skipped. # OpenMapQuest raises ConfigurationError when api_key is empty, # so don't try to create the instance when api_key is empty. if env.get('OPENMAPQUEST_APIKEY'): cls.geocoder = OpenMapQuest(scheme='http', timeout=3, api_key=env['OPENMAPQUEST_APIKEY']) cls.delta = 0.04
def test_params(self): """ Yandex.geocode with lang """ self.geocoder = Yandex(api_key=env.get('YANDEX_KEY'), lang='uk_UA') self.geocode_run( {"query": "площа Леніна Донецьк"}, { "address": "площа Леніна, Донецьк, Україна", "latitude": 48.002104, "longitude": 37.805186 }, )
import unittest from geopy.point import Point from geopy.geocoders import MapQuest from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('MAPQUEST_KEY')), "No MAPQUEST_KEY env variable set") class MapQuestTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = MapQuest(env['MAPQUEST_KEY'], scheme='http', timeout=3) cls.delta = 0.7 def test_geocode(self): """ MapQuest.geocode """ self.geocode_run( {"query": u"435 north michigan ave, chicago il 60611 usa"}, { "latitude": 41.890, "longitude": -87.624 }, ) def test_unicode_name(self): """ MapQuest.geocode unicode """
# -*- coding: utf8 -*- import unittest from geopy.exc import ConfigurationError, GeocoderQueryError from geopy.geocoders import IGNFrance from test.geocoders.util import GeocoderTestBase, env credentials = bool( (env.get('IGNFRANCE_KEY') and env.get('IGNFRANCE_USERNAME') and env.get('IGNFRANCE_PASSWORD')) or ( env.get('IGNFRANCE_KEY') and env.get('IGNFRANCE_REFERER')) ) class IGNFranceTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = IGNFrance( api_key='DUMMYKEY1234', username='******', password='******', user_agent='my_user_agent/1.0' ) self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless( credentials, "One or more of the env variables IGNFRANCE_KEY, IGNFRANCE_USERNAME " "and IGNFRANCE_PASSWORD is not set" )
import unittest from geopy.compat import u from geopy.point import Point from geopy.geocoders import MapBox from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( bool(env.get('MAPBOX_KEY')), "No MAPBOX_KEY env variable set" ) class MapBoxTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = MapBox(api_key=env['MAPBOX_KEY'], timeout=3) def test_geocode(self): self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624}, ) def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}, ) def test_reverse(self): new_york_point = Point(40.75376406311989, -73.98489005863667)
import unittest from geopy.compat import u from geopy.point import Point from geopy.geocoders import Bing from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('BING_KEY')), "No BING_KEY env variable set" ) class BingTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Bing( format_string='%s', scheme='http', api_key=env['BING_KEY'] ) def test_geocode(self): """ Bing.geocode """ res = self._make_request( self.geocoder.geocode, "435 north michigan ave, chicago il 60611 usa", ) if res is None:
import unittest from geopy import exc from geopy.point import Point from geopy.geocoders import ArcGIS from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('ARCGIS_USERNAME')), "No ARCGIS_USERNAME env variable set") class ArcGISTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = ArcGIS(timeout=3) def test_config_error(self): """ ArcGIS.__init__ invalid authentication """ with self.assertRaises(exc.ConfigurationError): ArcGIS(username='******') def test_scheme_config_error(self): """ ArcGIS.__init__ invalid scheme """ with self.assertRaises(exc.ConfigurationError): ArcGIS(username='******', password='******', referer='http://www.example.com', scheme='http')
from geopy.compat import py3k from geopy.geocoders import GeocoderDotUS from test.geocoders.util import GeocoderTestBase, env class GeocoderDotUSTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = GeocoderDotUS( user_agent='my_user_agent/1.0' ) self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('GEOCODERDOTUS_USERNAME')) and \ bool(env.get('GEOCODERDOTUS_PASSWORD')), "No GEOCODERDOTUS_USERNAME and GEOCODERDOTUS_PASSWORD env variables set" ) class GeocoderDotUSTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 @classmethod def setUpClass(cls): cls.geocoder = GeocoderDotUS( username=env['GEOCODERDOTUS_USERNAME'], password=env['GEOCODERDOTUS_PASSWORD'], timeout=3 ) def test_dot_us_auth(self): """
'latitude': 51.5285057, 'longitude': -0.1369635, "delta": 0.3 }, ) assert 'London' in location.address # Russian Moscow address can be reported differently, so # we're querying something more ordinary, like London. # # For example, AzureMaps might return # `Красная площадь, 109012 Moskva` instead of the expected # `Красная площадь, 109012 Москва`, even when language is # specified explicitly as `ru-RU`. And TomTom always returns # the cyrillic variant, even when the `en-US` language is # requested. async def test_geocode_empty(self): await self.geocode_run( {'query': 'sldkfhdskjfhsdkhgflaskjgf'}, {}, expect_failure=True, ) @pytest.mark.skipif(not bool(env.get('TOMTOM_KEY')), reason="No TOMTOM_KEY env variable set") class TestTomTom(BaseTestTomTom): @classmethod def make_geocoder(cls, **kwargs): return TomTom(env['TOMTOM_KEY'], timeout=3, **kwargs)
import unittest from geopy.compat import u from geopy.geocoders import What3Words from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(bool(env.get('WHAT3WORDS_KEY')), "No WHAT3WORDS_KEY env variable set" ) class What3WordsTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = What3Words( env['WHAT3WORDS_KEY'], scheme='http', timeout=3 ) cls.delta = 0.7 def test_geocode(self): """ What3Words.geocode - '3 Words' and 'OneWord' """ self.geocode_run( {"query": u("piped.gains.jangle")}, {"latitude": 53.037611, "longitude": 11.565012}, ) self.geocode_run(
def test_reverse_point(self): """ Baidu.reverse Point """ self.reverse_run( {"query": Point(39.983615544507, 116.32295155093)}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, ) self.reverse_run( {"query": Point(39.983615544507, 116.32295155093), "exactly_one": False}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, ) @unittest.skipUnless( bool(env.get('BAIDU_KEY')), "No BAIDU_KEY env variable set" ) class BaiduTestCase(BaiduQueriesTestCaseMixin, GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Baidu( api_key=env['BAIDU_KEY'], timeout=3, ) def test_invalid_ak(self): self.geocoder = Baidu(api_key='DUMMYKEY1234') with self.assertRaises(GeocoderAuthenticationFailure) as cm: self.geocode_run({"query": u("baidu")}, None)
import unittest from geopy.geocoders import MapQuest from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('MAPQUEST_KEY')), "No MAPQUEST_KEY env variable set" ) class MapQuestTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = MapQuest( env['MAPQUEST_KEY'], scheme='http', timeout=3 ) cls.delta = 0.7 def test_geocode(self): """ MapQuest.geocode """ self.geocode_run( {"query": u"435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624}, )
from test.geocoders.util import GeocoderTestBase, env class HereTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = Here( app_id='DUMMYID1234', app_code='DUMMYCODE1234', user_agent='my_user_agent/1.0' ) self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless( bool(env.get('HERE_APP_ID')), "No HERE_APP_ID env variable set" ) @unittest.skipUnless( bool(env.get('HERE_APP_CODE')), "No HERE_APP_CODE env variable set" ) class HereTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Here( app_id=env['HERE_APP_ID'], app_code=env['HERE_APP_CODE'], timeout=10, )
import unittest from geopy.geocoders import LiveAddress from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('LIVESTREETS_AUTH_KEY')), "No LIVESTREETS_AUTH_KEY env variable set" ) class LiveAddressTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = LiveAddress( auth_token=env['LIVESTREETS_AUTH_KEY'], scheme='http' ) cls.delta = 0.04 def test_geocode(self): """ LiveAddress.geocode """ self.geocode_run( {"query": u"435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624}, )
"longitude": 116.32295155093 }, ) self.reverse_run( { "query": Point(39.983615544507, 116.32295155093), "exactly_one": False }, { "latitude": 39.983615544507, "longitude": 116.32295155093 }, ) @unittest.skipUnless(bool(env.get('BAIDU_KEY')), "No BAIDU_KEY env variable set") class BaiduTestCase(BaiduQueriesTestCaseMixin, GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Baidu( api_key=env['BAIDU_KEY'], timeout=3, ) def test_invalid_ak(self): self.geocoder = Baidu(api_key='DUMMYKEY1234') with self.assertRaises(GeocoderAuthenticationFailure) as cm: self.geocode_run({"query": u("baidu")}, None) self.assertEqual(str(cm.exception), 'Invalid AK')
import unittest from geopy.compat import u from geopy.geocoders import OpenCage from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(bool(env.get("OPENCAGE_KEY")), "No OPENCAGE_KEY env variables set") # pylint: disable=R0904,C0111 class OpenCageTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = OpenCage(api_key=env["OPENCAGE_KEY"], timeout=20) cls.delta_exact = 0.2 def test_geocode(self): """ OpenCage.geocode """ self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624} ) def test_unicode_name(self): """ OpenCage.geocode unicode """ self.geocode_run({"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}) def test_geocode_empty_result(self): """ Empty OpenCage.geocode results should be graciously handled.
from geopy.exc import ConfigurationError from test.geocoders.nominatim import BaseNominatimTestCase from test.geocoders.util import GeocoderTestBase, env import unittest class OpenMapQuestNoNetTestCase(GeocoderTestBase): def test_user_agent_custom(self): geocoder = OpenMapQuest( api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0' ) self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') def test_raises_without_apikey(self): with self.assertRaises(ConfigurationError): OpenMapQuest() @unittest.skipUnless( bool(env.get('OPENMAPQUEST_APIKEY')), "No OPENMAPQUEST_APIKEY env variable set" ) class OpenMapQuestTestCase(BaseNominatimTestCase, GeocoderTestBase): @classmethod def make_geocoder(cls, **kwargs): return OpenMapQuest(api_key=env['OPENMAPQUEST_APIKEY'], timeout=3, **kwargs)
import unittest from geopy.point import Point from geopy.geocoders import YahooPlaceFinder from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('YAHOO_KEY')) and bool(env.get('YAHOO_SECRET')), "YAHOO_KEY and YAHOO_SECRET env variables not set" ) class YahooPlaceFinderTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 @classmethod def setUpClass(cls): cls.geocoder = YahooPlaceFinder( env['YAHOO_KEY'], env['YAHOO_SECRET'] ) def test_geocode(self): """ YahooPlaceFinder.geocode """ self.geocode_run( {"query": u"nyc"}, {"latitude": 40.71455, "longitude": -74.00712}, ) def test_unicode_name(self):
def test_get_headers(self): geocoder = GeocoderDotUS() self.assertDictEqual({}, geocoder._get_headers()) username = '******' password = '******' # echo -n testuser:testpassword | base64 b64 = 'dGVzdHVzZXI6dGVzdHBhc3N3b3Jk' geocoder = GeocoderDotUS(username=username, password=password) self.assertDictEqual({'Authorization': 'Basic %s' % b64}, geocoder._get_headers()) @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('GEOCODERDOTUS_USERNAME')) and \ bool(env.get('GEOCODERDOTUS_PASSWORD')), "No GEOCODERDOTUS_USERNAME and GEOCODERDOTUS_PASSWORD env variables set" ) class GeocoderDotUSTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 @classmethod def setUpClass(cls): cls.geocoder = GeocoderDotUS(username=env['GEOCODERDOTUS_USERNAME'], password=env['GEOCODERDOTUS_PASSWORD'], timeout=3) def test_geocode(self): """ GeocoderDotUS.geocode """ self.geocode_run(
import unittest from geopy.compat import u from geopy.geocoders import MapQuest from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(bool(env.get('MAPQUEST_KEY')), "No MAPQUEST_KEY env variable set") class MapQuestTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = MapQuest(api_key=env['MAPQUEST_KEY'], timeout=3) def test_geocode(self): self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, { "latitude": 41.89036, "longitude": -87.624043 }, ) def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab")}, { "latitude": 25.0968, "longitude": 121.54714 },
def make_geocoder(cls, **kwargs): return Pelias(env.get('PELIAS_DOMAIN'), api_key=env.get('PELIAS_KEY'), **kwargs)
'latitude': 51.5285057, 'longitude': -0.1369635, "delta": 0.3 }, ) self.assertIn('London', location.address) # Russian Moscow address can be reported differently, so # we're querying something more ordinary, like London. # # For example, AzureMaps might return # `Красная площадь, 109012 Moskva` instead of the expected # `Красная площадь, 109012 Москва`, even when language is # specified explicitly as `ru-RU`. And TomTom always returns # the cyrillic variant, even when the `en-US` language is # requested. def test_geocode_empty(self): self.geocode_run( {'query': 'sldkfhdskjfhsdkhgflaskjgf'}, {}, expect_failure=True, ) @unittest.skipUnless(bool(env.get('TOMTOM_KEY')), "No TOMTOM_KEY env variable set") class TomTomTestCase(BaseTomTomTestCase, GeocoderTestBase): @classmethod def make_geocoder(cls, **kwargs): return TomTom(env['TOMTOM_KEY'], timeout=3, **kwargs)
# -*- coding: UTF-8 -*- import unittest from geopy.compat import u from geopy.geocoders import GeoNames from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get("GEONAMES_USERNAME")), "No GEONAMES_USERNAME env variable set" ) class GeoNamesTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.delta = 0.04 def test_unicode_name(self): """ GeoNames.geocode unicode """ # work around ConfigurationError raised in GeoNames init self.geocoder = GeoNames(username=env["GEONAMES_USERNAME"]) self.geocode_run({"query": "Mount Everest, Nepal"}, {"latitude": 27.987, "longitude": 86.925}) def test_reverse(self): """ GeoNames.reverse """ # work around ConfigurationError raised in GeoNames init self.geocoder = GeoNames(username=env["GEONAMES_USERNAME"]) self.reverse_run(
with self.assertRaises(geopy.exc.ConfigurationError): What3Words( api_key=self.dummy_api_key, scheme='http', ) @patch.object(geopy.geocoders.options, 'default_scheme', 'http') def test_default_scheme_is_ignored(self): geocoder = What3Words(api_key=self.dummy_api_key) self.assertEqual(geocoder.scheme, 'https') geocoder = What3Words(api_key=self.dummy_api_key, scheme=None) self.assertEqual(geocoder.scheme, 'https') @unittest.skipUnless( bool(env.get('WHAT3WORDS_KEY')), "No WHAT3WORDS_KEY env variable set" ) class What3WordsTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = What3Words( env['WHAT3WORDS_KEY'], scheme='https', timeout=3 ) cls.delta = 0.7 def test_geocode(self): self.geocode_run(
# -*- coding: utf8 -*- import unittest from geopy.exc import ConfigurationError, GeocoderQueryError from geopy.geocoders import IGNFrance from test.geocoders.util import GeocoderTestBase, env credentials = bool((env.get('IGNFRANCE_KEY') and env.get('IGNFRANCE_USERNAME') and env.get('IGNFRANCE_PASSWORD')) or (env.get('IGNFRANCE_KEY') and env.get('IGNFRANCE_REFERER'))) @unittest.skipUnless( # pylint: disable=R0904,C0111 credentials, "One or more of the env variables IGNFRANCE_KEY, IGNFRANCE_USERNAME \ and IGNFRANCE_PASSWORD is not set" ) class IGNFranceTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): if not credentials: return cls.geocoder = IGNFrance( api_key=env.get('IGNFRANCE_KEY'), username=env.get('IGNFRANCE_USERNAME'), password=env.get('IGNFRANCE_PASSWORD'), referer=env.get('IGNFRANCE_REFERER'), timeout=20 )
import unittest from geopy.point import Point from geopy.geocoders import Baidu from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('BAIDU_KEY')), "No BAIDU_KEY env variable set" ) class BaiduTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Baidu( scheme='http', api_key=env['BAIDU_KEY'] ) cls.delta_exact = 0.02 def test_basic_address(self): """ Baidu.geocode """ self.geocode_run( {"query": ( u"\u5317\u4eac\u5e02\u6d77\u6dc0\u533a" u"\u4e2d\u5173\u6751\u5927\u885727\u53f7" )},
import unittest from geopy import exc from geopy.compat import u from geopy.point import Point from geopy.geocoders import ArcGIS from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('ARCGIS_USERNAME')), "No ARCGIS_USERNAME env variable set" ) class ArcGISTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = ArcGIS(timeout=3) def test_config_error(self): """ ArcGIS.__init__ invalid authentication """ with self.assertRaises(exc.ConfigurationError): ArcGIS(username='******') def test_scheme_config_error(self): """ ArcGIS.__init__ invalid scheme """ with self.assertRaises(exc.ConfigurationError):
from geopy.geocoders import OpenCage from test.geocoders.util import GeocoderTestBase, env class OpenCageTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = OpenCage( api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0' ) self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless( bool(env.get('OPENCAGE_KEY')), "No OPENCAGE_KEY env variables set" ) class OpenCageTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = OpenCage( api_key=env['OPENCAGE_KEY'], timeout=10, ) cls.delta_exact = 0.2 def test_geocode(self): """ OpenCage.geocode
{ "latitude": 40.75376406311989, "longitude": -73.98489005863667 }, ) async def test_reverse_no_result(self): await self.reverse_run( # North Atlantic Ocean {"query": (35.173809, -37.485351)}, {}, expect_failure=True) @pytest.mark.skipif( not (env.get('ARCGIS_USERNAME') is not None or env.get('ARCGIS_PASSWORD') is not None or env.get('ARCGIS_REFERER') is not None), reason= "No ARCGIS_USERNAME or ARCGIS_PASSWORD or ARCGIS_REFERER env variable set") class TestArcGISAuthenticated(BaseTestGeocoder): @classmethod def make_geocoder(cls, **kwargs): return ArcGIS(username=env['ARCGIS_USERNAME'], password=env['ARCGIS_PASSWORD'], referer=env['ARCGIS_REFERER'], timeout=3, **kwargs) async def test_basic_address(self): await self.geocode_run( {"query": "Potsdamer Platz, Berlin, Deutschland"},
def test_boundary_rect(self): self.geocoder = self.make_geocoder( boundary_rect=[[50.1, -130.1], [44.1, -100.9]]) self.geocode_run( {"query": "moscow"}, # Idaho USA {"latitude": 46.7323875, "longitude": -117.0001651}, ) def test_boundary_rect_deprecated(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') self.geocoder = self.make_geocoder( boundary_rect=[-130.1, 44.1, -100.9, 50.1]) self.geocode_run( {"query": "moscow"}, # Idaho USA {"latitude": 46.7323875, "longitude": -117.0001651}, ) self.assertEqual(1, len(w)) @unittest.skipUnless( bool(env.get('PELIAS_DOMAIN')), "No PELIAS_DOMAIN env variable set" ) class PeliasTestCase(BasePeliasTestCase, GeocoderTestBase): def make_geocoder(cls, **kwargs): return Pelias(env.get('PELIAS_DOMAIN'), api_key=env.get('PELIAS_KEY'), **kwargs)
import unittest from geopy.geocoders import AzureMaps from test.geocoders.util import GeocoderTestBase, env from test.geocoders.tomtom import BaseTomTomTestCase @unittest.skipUnless( bool(env.get('AZURE_SUBSCRIPTION_KEY')), "No AZURE_SUBSCRIPTION_KEY env variable set" ) class AzureMapsTestCase(BaseTomTomTestCase, GeocoderTestBase): @classmethod def make_geocoder(cls, **kwargs): return AzureMaps(env['AZURE_SUBSCRIPTION_KEY'], timeout=3, **kwargs)
from mock import patch import unittest from geopy import exc from geopy.geocoders import GeocodeFarm from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( not env.get('GEOCODEFARM_SKIP'), "GEOCODEFARM_SKIP env variable is set" ) class GeocodeFarmTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.delta = 0.04 cls.geocoder = GeocodeFarm( # None api_key will use free tier on GeocodeFarm. api_key=env.get('GEOCODEFARM_KEY'), timeout=10, ) def test_user_agent_custom(self): geocoder = GeocodeFarm( user_agent='my_user_agent/1.0' ) self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') def test_geocode(self):
auth_id=self.dummy_id, auth_token=self.dummy_token, scheme='http', ) @patch.object(geopy.geocoders.options, 'default_scheme', 'http') def test_default_scheme_is_ignored(self): geocoder = LiveAddress(auth_id=self.dummy_id, auth_token=self.dummy_token) self.assertEqual(geocoder.scheme, 'https') geocoder = LiveAddress(auth_id=self.dummy_id, auth_token=self.dummy_token, scheme=None) self.assertEqual(geocoder.scheme, 'https') @unittest.skipUnless( env.get('LIVESTREETS_AUTH_ID') and env.get('LIVESTREETS_AUTH_TOKEN'), "No LIVESTREETS_AUTH_ID AND LIVESTREETS_AUTH_TOKEN env variables set" ) class LiveAddressTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = LiveAddress( auth_id=env['LIVESTREETS_AUTH_ID'], auth_token=env['LIVESTREETS_AUTH_TOKEN'], ) cls.delta = 0.04 def test_geocode(self): """ LiveAddress.geocode
import unittest import types from geopy import exc from geopy.point import Point from geopy.geocoders import GeocodeFarm from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('GEOCODEFARM_KEY')), "GEOCODEFARM_KEY env variable not set" ) class GeocodeFarmTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 @classmethod def setUpClass(cls): cls.delta = 0.04 cls.geocoder = GeocodeFarm( api_key=env['GEOCODEFARM_KEY'], format_string="%s US" ) def test_geocode(self): """ OpenCage.geocode """ self.geocode_run( {"query": u"435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624},
def test_custom_wkid(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') # Custom wkid should be ignored and a warning should be issued. location = self.reverse_run( {"query": Point(40.753898, -73.985071), "wkid": 2000}, {"latitude": 40.75376406311989, "longitude": -73.98489005863667}, ) self.assertIn('New York', location.address) self.assertEqual(1, len(w)) @unittest.skipUnless( (env.get('ARCGIS_USERNAME') is not None or env.get('ARCGIS_PASSWORD') is not None or env.get('ARCGIS_REFERER') is not None), "No ARCGIS_USERNAME or ARCGIS_PASSWORD or ARCGIS_REFERER env variable set" ) class ArcGISAuthenticatedTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = ArcGIS( username=env['ARCGIS_USERNAME'], password=env['ARCGIS_PASSWORD'], referer=env['ARCGIS_REFERER'], timeout=3 )
import unittest from mock import patch from geopy import exc from geopy.geocoders import GeocodeFarm from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(not env.get('GEOCODEFARM_SKIP'), "GEOCODEFARM_SKIP env variable is set") class GeocodeFarmTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.delta = 0.04 cls.geocoder = GeocodeFarm( # None api_key will use free tier on GeocodeFarm. api_key=env.get('GEOCODEFARM_KEY'), timeout=10, ) def test_user_agent_custom(self): geocoder = GeocodeFarm(user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') def test_geocode(self): """ GeocodeFarm.geocode """ location = self.geocode_run(
from geopy.compat import u from geopy.geocoders import Here from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env class HereTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = Here(app_id='DUMMYID1234', app_code='DUMMYCODE1234', user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless(bool(env.get('HERE_APP_ID')), "No HERE_APP_ID env variable set") @unittest.skipUnless(bool(env.get('HERE_APP_CODE')), "No HERE_APP_CODE env variable set") class HereTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Here( app_id=env['HERE_APP_ID'], app_code=env['HERE_APP_CODE'], timeout=10, ) def test_geocode_empty_result(self): """ Here.geocode empty results should be graciously handled.
auth_id=self.dummy_id, auth_token=self.dummy_token, scheme='http', ) @patch.object(geopy.geocoders.options, 'default_scheme', 'http') def test_default_scheme_is_ignored(self): geocoder = LiveAddress(auth_id=self.dummy_id, auth_token=self.dummy_token) assert geocoder.scheme == 'https' geocoder = LiveAddress(auth_id=self.dummy_id, auth_token=self.dummy_token, scheme=None) assert geocoder.scheme == 'https' @unittest.skipUnless( env.get('LIVESTREETS_AUTH_ID') and env.get('LIVESTREETS_AUTH_TOKEN'), "No LIVESTREETS_AUTH_ID AND LIVESTREETS_AUTH_TOKEN env variables set" ) class LiveAddressTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = LiveAddress( auth_id=env['LIVESTREETS_AUTH_ID'], auth_token=env['LIVESTREETS_AUTH_TOKEN'], ) cls.delta = 0.04 def test_geocode(self): self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"},
import unittest from geopy.compat import u from geopy.geocoders import Bing from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env class BingTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = Bing(api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless(bool(env.get('BING_KEY')), "No BING_KEY env variable set") class BingTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Bing(format_string='%s', api_key=env['BING_KEY']) def test_geocode(self): """ Bing.geocode """ self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, { "latitude": 41.890, "longitude": -87.624 }, )
import unittest from geopy.geocoders import Geolake from test.geocoders.util import GeocoderTestBase, env class GeolakeTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = Geolake(api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless(bool(env.get('GEOLAKE_KEY')), "No GEOLAKE_KEY env variables set") class GeolakeTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Geolake( api_key=env['GEOLAKE_KEY'], timeout=10, ) cls.delta_exact = 0.2 def test_geocode(self): self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, { "latitude": 41.890344, "longitude": -87.623234, "address": "Chicago, US"
import unittest from geopy.compat import u from geopy.geocoders import MapBox from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(bool(env.get('MAPBOX_KEY')), "No MAPBOX_KEY env variable set") class MapBoxTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = MapBox(api_key=env['MAPBOX_KEY'], timeout=3) def test_geocode(self): self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, { "latitude": 41.890, "longitude": -87.624 }, ) def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab")}, { "latitude": 39.916, "longitude": 116.390 },
import unittest from geopy.compat import u from geopy.point import Point from geopy.geocoders import Bing from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(bool(env.get("BING_KEY")), "No BING_KEY env variable set") # pylint: disable=R0904,C0111 class BingTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = Bing(format_string="%s", scheme="http", api_key=env["BING_KEY"]) def test_geocode(self): """ Bing.geocode """ self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624} ) def test_unicode_name(self): """ Bing.geocode unicode """ self.geocode_run({"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}) def test_reverse_point(self): """ Bing.reverse using point
# -*- coding: UTF-8 -*- import unittest from geopy.compat import u from geopy.geocoders import GeoNames from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('GEONAMES_USERNAME')), "No GEONAMES_USERNAME env variable set" ) class GeoNamesTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.delta = 0.04 def test_unicode_name(self): """ GeoNames.geocode unicode """ # work around ConfigurationError raised in GeoNames init self.geocoder = GeoNames(username=env['GEONAMES_USERNAME']) self.geocode_run( {"query": u("Mus\xe9e du Louvre")}, {"latitude": 48.8610, "longitude": 2.335}, ) def test_reverse(self): """
result_geocode = await self.geocode_run( {"query": query, "language": "en"}, {} ) assert result_geocode.raw['properties']['country'] == "Austria" async def test_reverse_language_parameter(self): query = "48.198674, 16.348388" result_reverse_de = await self.reverse_run( {"query": query, "language": "de"}, {}, ) assert result_reverse_de.raw['properties']['country'] == "Österreich" result_reverse_en = await self.reverse_run( {"query": query, "language": "en"}, {}, ) assert result_reverse_en.raw['properties']['country'] == "Austria" @pytest.mark.skipif( not bool(env.get('PELIAS_DOMAIN')), reason="No PELIAS_DOMAIN env variable set" ) class TestPelias(BaseTestPelias): @classmethod def make_geocoder(cls, **kwargs): return Pelias(env.get('PELIAS_DOMAIN'), api_key=env.get('PELIAS_KEY'), **kwargs)
import unittest from geopy.compat import u from geopy.geocoders import MapBox from geopy.point import Point from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( bool(env.get('MAPBOX_KEY')), "No MAPBOX_KEY env variable set" ) class MapBoxTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = MapBox(api_key=env['MAPBOX_KEY'], timeout=3) def test_geocode(self): self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624}, ) def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}, ) def test_reverse(self): new_york_point = Point(40.75376406311989, -73.98489005863667)
def setUpClass(cls): cls.geocoder = GoogleV3(api_key=env.get('GOOGLE_KEY'))
import pytest from geopy.geocoders import Geolake from test.geocoders.util import BaseTestGeocoder, env class TestUnitGeolake: def test_user_agent_custom(self): geocoder = Geolake(api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0') assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0' @pytest.mark.skipif(not bool(env.get('GEOLAKE_KEY')), reason="No GEOLAKE_KEY env variables set") class TestGeolake(BaseTestGeocoder): @classmethod def make_geocoder(cls, **kwargs): return Geolake(api_key=env['GEOLAKE_KEY'], timeout=10, **kwargs) async def test_geocode(self): await self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, { "latitude": 41.890344, "longitude": -87.623234, "address": "Chicago, US" }, ) async def test_geocode_country_codes_str(self):
from geopy.compat import u from geopy.geocoders import OpenMapQuest from test.geocoders.util import GeocoderTestBase, env import unittest class OpenMapQuestNoNetTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 def test_user_agent_custom(self): geocoder = OpenMapQuest(api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('OPENMAPQUEST_APIKEY')), "No OPENMAPQUEST_APIKEY env variable set") class OpenMapQuestTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 @classmethod def setUpClass(cls): # setUpClass is still called even if test is skipped. # OpenMapQuest raises ConfigurationError when api_key is empty, # so don't try to create the instance when api_key is empty. if env.get('OPENMAPQUEST_APIKEY'): cls.geocoder = OpenMapQuest(scheme='http', timeout=3, api_key=env['OPENMAPQUEST_APIKEY']) cls.delta = 0.04 def test_geocode(self): """ OpenMapQuest.geocode
import unittest import warnings from geopy.compat import u from geopy.geocoders import OpenCage from test.geocoders.util import GeocoderTestBase, env class OpenCageTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = OpenCage(api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless(bool(env.get('OPENCAGE_KEY')), "No OPENCAGE_KEY env variables set") class OpenCageTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = OpenCage( api_key=env['OPENCAGE_KEY'], timeout=10, ) cls.delta_exact = 0.2 def test_geocode(self): """ OpenCage.geocode """ self.geocode_run(
import unittest import types from geopy import exc from geopy.point import Point from geopy.geocoders import GeocodeFarm from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get("GEOCODEFARM_KEY")), "GEOCODEFARM_KEY env variable not set" ) class GeocodeFarmTestCase(GeocoderTestBase): # pylint: disable=R0904,C0111 @classmethod def setUpClass(cls): cls.delta = 0.04 cls.geocoder = GeocodeFarm(api_key=env["GEOCODEFARM_KEY"], format_string="%s US") def test_geocode(self): """ OpenCage.geocode """ self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"}, {"latitude": 41.890, "longitude": -87.624} ) def test_reverse_string(self): """ GeocodeFarm.reverse string """ self.reverse_run(
import unittest from geopy.compat import u from geopy.geocoders import What3Words from test.geocoders.util import GeocoderTestBase, env @unittest.skipUnless(bool(env.get('WHAT3WORDS_KEY')), "No WHAT3WORDS_KEY env variable set") class What3WordsTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = What3Words(env['WHAT3WORDS_KEY'], scheme='http', timeout=3) cls.delta = 0.7 def test_geocode(self): """ What3Words.geocode - '3 Words' and 'OneWord' """ self.geocode_run( {"query": u("piped.gains.jangle")}, { "latitude": 53.037611, "longitude": 11.565012 }, ) self.geocode_run( {"query": u("*LibertyTech")},
import unittest from geopy.compat import u from geopy.geocoders import OpenCage from test.geocoders.util import GeocoderTestBase, env class OpenCageTestCaseUnitTest(GeocoderTestBase): def test_user_agent_custom(self): geocoder = OpenCage(api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0') @unittest.skipUnless( # pylint: disable=R0904,C0111 bool(env.get('OPENCAGE_KEY')), "No OPENCAGE_KEY env variables set") class OpenCageTestCase(GeocoderTestBase): @classmethod def setUpClass(cls): cls.geocoder = OpenCage( api_key=env['OPENCAGE_KEY'], timeout=10, ) cls.delta_exact = 0.2 def test_geocode(self): """ OpenCage.geocode """ self.geocode_run( {"query": "435 north michigan ave, chicago il 60611 usa"},
class TestUnitWhat3Words: dummy_api_key = 'DUMMYKEY1234' async def test_user_agent_custom(self): geocoder = What3Words(api_key=self.dummy_api_key, user_agent='my_user_agent/1.0') assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0' @patch.object(geopy.geocoders.options, 'default_scheme', 'http') def test_default_scheme_is_ignored(self): geocoder = What3Words(api_key=self.dummy_api_key) assert geocoder.scheme == 'https' @pytest.mark.skipif(not bool(env.get('WHAT3WORDS_KEY')), reason="No WHAT3WORDS_KEY env variable set") class TestWhat3Words(BaseTestGeocoder): @classmethod def make_geocoder(cls, **kwargs): return What3Words(env['WHAT3WORDS_KEY'], timeout=3, **kwargs) async def test_geocode(self): await self.geocode_run( {"query": "piped.gains.jangle"}, { "latitude": 53.037611, "longitude": 11.565012 }, )