def test_query_urlencoding(self): location = self.geocode_run( {"query": u("Ry\u016b\u014d")}, {"latitude": 35.65, "longitude": 138.5}, skiptest_on_failure=True, # sometimes the result is empty ) self.assertIn(u("Ry\u016b\u014d"), location.address)
def test_unicode_query(self): """ What3Words.geocode - '3 Words' unicode """ self.geocode_run( { "query": u("\u0070\u0069\u0070\u0065\u0064\u002e\u0067" "\u0061\u0069\u006e\u0073\u002e\u006a\u0061" "\u006e\u0067\u006c\u0065") }, { "latitude": 53.037611, "longitude": 11.565012 }, ) self.geocode_run( { "query": u("\u002a\u004c\u0069\u0062\u0065\u0072\u0074" "\u0079\u0054\u0065\u0063\u0068") }, { "latitude": 51.512573, "longitude": -0.144879 }, )
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")}, {"latitude": 51.512573, "longitude": -0.144879}, )
def test_geocode_language(self): location = self.geocode_run( { "query": u("Z\u00fcrich"), "language": "ja", "proximity": Point(47.3723, 8.5422) }, { "latitude": 47.3723, "longitude": 8.5422, "delta": 1 }, ) assert u("\u30c1\u30e5\u30fc\u30ea\u30c3\u30d2") in location.address
def test_bounded(self): bb = (Point('56.588456', '84.719353'), Point('56.437293', '85.296822')) query = u('\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c ' '\u0442\u043e\u043c\u0441\u043a') self.geocode_run( { "query": query, "viewbox": bb }, { "latitude": 56.4129459, "longitude": 84.847831069814 }, ) self.geocode_run( { "query": query, "viewbox": bb, "bounded": True }, { "latitude": 56.4803224, "longitude": 85.0060457653324 }, )
def test_unicode_name(self): self.geocode_run( {"query": u("Stadelhoferstrasse 8, 8001 Z\u00fcrich")}, { "latitude": 47.36649, "longitude": 8.54855 }, )
def test_unicode_name(self): """ Mapzen.geocode unicode """ self.geocode_run( {"query": u(u'san josé california'.encode('utf8'))}, {"latitude": 37.33939, "longitude": -121.89496}, )
def test_unicode_name(self): self.geocode_run( {"query": u("Barri\u00e8re")}, { "latitude": 51.179, "longitude": -120.123 }, )
def test_unicode_name(self): """ Photon.geocode unicode """ self.geocode_run( {"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}, )
def test_check_query(self): result_check_threeword_query = self.geocoder._check_query( u("\u0066\u0061\u0068\u0072\u0070\u0072" "\u0065\u0069\u0073\u002e\u006c\u00fc" "\u0067\u006e\u0065\u0072\u002e\u006b" "\u0075\u0074\u0073\u0063\u0068\u0065")) assert result_check_threeword_query
def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab")}, { "latitude": 25.0968, "longitude": 121.54714 }, )
def test_point_str_deg(self): """ Point() str degrees, minutes &c """ point = Point(u("UT: N 39\xb020' 0'' / W 74\xb035' 0''")) self.assertEqual(point.latitude, 39.333333333333336) self.assertEqual(point.longitude, -74.58333333333333) self.assertEqual(point.altitude, 0)
def test_unicode_name(self): """ Photon.geocode unicode """ self.geocode_run( {"query": u("\u6545\u5bab")}, {"latitude": 39.917252950000005, "longitude": 116.39077025499873} )
def test_unicode_name(self): """ Bing.geocode unicode """ self.geocode_run( {"query": u("\u043c\u043e\u0441\u043a\u0432\u0430")}, {"latitude": 55.756, "longitude": 37.615}, )
def test_unicode_name(self): """ Photon.geocode unicode """ self.geocode_run({"query": u("\u6545\u5bab")}, { "latitude": 39.917252950000005, "longitude": 116.39077025499873 })
def remove_namespace(doc, namespace): """Remove namespace in the document in place.""" ns = "{%s}" % namespace ns = u(ns) nsl = len(ns) for elem in doc.getiterator(): if elem.tag.startswith(ns): elem.tag = elem.tag[nsl:]
def test_geocode_unicode_name(self): """ Here.geocode unicode in Japanese for Paris. (POIs not included.) """ self.geocode_run({"query": u("\u30d1\u30ea")}, { "latitude": 48.85718, "longitude": 2.34141 })
def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab \u5317\u4eac")}, { "latitude": 39.916, "longitude": 116.390 }, )
def test_geocode(self): self.geocode_run( {"query": u("piped.gains.jangle")}, { "latitude": 53.037611, "longitude": 11.565012 }, )
def test_geocode(self): """ What3Words.geocode - '3 Words' and 'OneWord' """ self.geocode_run( {"query": u("piped.gains.jangle")}, {"latitude": 53.037611, "longitude": 11.565012}, )
def test_geocode_unicode_name(self): """ Here.geocode unicode in Japanese for Paris. (POIs not included.) """ self.geocode_run( {"query": u("\u30d1\u30ea")}, {"latitude": 48.85718, "longitude": 2.34141} )
def test_unicode_name(self): """ GoogleV3.geocode unicode """ self.geocode_run( {"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}, )
def test_unicode_name(self): self.geocode_run( {"query": u("\u043c\u043e\u0441\u043a\u0432\u0430")}, { "latitude": 55.756, "longitude": 37.615 }, )
def remove_namespace(doc, namespace): """Remove namespace in the document in place.""" ns = '{%s}' % namespace ns = u(ns) nsl = len(ns) for elem in doc.getiterator(): if elem.tag.startswith(ns): elem.tag = elem.tag[nsl:]
def test_unicode_name(self): """ YahooPlaceFinder.geocode unicode """ self.geocode_run( {"query": u("\u6545\u5bab")}, {"latitude": 39.916, "longitude": 116.390}, )
def test_unicode_name(self): """ DataBC.geocode unicode """ self.geocode_run( {"query": u("Barri\u00e8re")}, {"latitude": 51.179, "longitude": -120.123}, )
def test_sn_with_peculiar_chars(self): self.geocode_run( {"query": u( "\u5317\u4eac\u5e02\u6d77\u6dc0\u533a" "\u4e2d\u5173\u6751\u5927\u885727\u53f7" " ' & = , ? %" )}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, )
class TimezoneTestCase(unittest.TestCase): timezone_name = u("Europe/Moscow") def test_create_from_timezone_name(self): raw = dict(foo="bar") tz = from_timezone_name(self.timezone_name, raw) self.assertEqual(tz.raw['foo'], 'bar') self.assertIsInstance(tz.pytz_timezone, pytz.tzinfo.BaseTzInfo) def test_create_from_pytz_timezone(self): pytz_timezone = pytz.timezone(self.timezone_name) tz = Timezone(pytz_timezone) self.assertIs(tz.pytz_timezone, pytz_timezone) def test_string(self): raw = dict(foo="bar") tz = from_timezone_name(self.timezone_name, raw) self.assertEqual(str(tz), self.timezone_name) def test_repr(self): raw = dict(foo="bar") pytz_timezone = pytz.timezone(self.timezone_name) tz = Timezone(pytz_timezone, raw) self.assertEqual(repr(tz), "Timezone(%s)" % repr(pytz_timezone)) def test_eq(self): tz = pytz.timezone("Europe/Paris") raw1 = dict(a=1) raw2 = dict(a=1) self.assertEqual(Timezone(tz, raw1), Timezone(tz, raw2)) def test_ne(self): tz1 = pytz.timezone("Europe/Paris") tz2 = pytz.timezone("Europe/Prague") raw = {} self.assertNotEqual(Timezone(tz1, raw), Timezone(tz2, raw)) def test_picklable(self): raw = dict(foo="bar") tz = from_timezone_name(self.timezone_name, raw) # https://docs.python.org/2/library/pickle.html#data-stream-format for protocol in (0, 1, 2, -1): pickled = pickle.dumps(tz, protocol=protocol) tz_unp = pickle.loads(pickled) self.assertEqual(tz, tz_unp) def test_with_unpicklable_raw(self): some_class = type('some_class', (object,), {}) raw_unpicklable = dict(missing=some_class()) del some_class tz_unpicklable = from_timezone_name(self.timezone_name, raw_unpicklable) for protocol in (0, 1, 2, -1): with self.assertRaises((AttributeError, pickle.PicklingError)): pickle.dumps(tz_unpicklable, protocol=protocol)
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")}, { "latitude": 51.512573, "longitude": -0.144879 }, )
def test_unicode_name(self): """ DataBC.geocode unicode """ res = self._make_request( self.geocoder.geocode, u("Barri\u00e8re"), ) self.assertAlmostEqual(res.latitude, 51.179, delta=self.delta) self.assertAlmostEqual(res.longitude, -120.123, delta=self.delta)
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_check_query(self): result_check_oneword_query = self.geocoder._check_query("*LibertyTech") result_check_threeword_query = self.geocoder._check_query( u("\u0066\u0061\u0068\u0072\u0070\u0072" "\u0065\u0069\u0073\u002e\u006c\u00fc" "\u0067\u006e\u0065\u0072\u002e\u006b" "\u0075\u0074\u0073\u0063\u0068\u0065")) self.assertTrue(result_check_oneword_query) self.assertTrue(result_check_threeword_query)
def test_location_repr(self): address = u("22, Ksi\u0119dza Paw\u0142a Po\u015bpiecha, " "Centrum Po\u0142udnie, Zabrze, wojew\xf3dztwo " "\u015bl\u0105skie, 41-800, Polska") point = (0.0, 0.0, 0.0) loc = Location(address, point) if py3k: self.assertEqual(repr(loc), "Location(%s, %r)" % (address, point)) else: self.assertEqual(repr(loc), "Location((%s, %s, %s))" % point)
def test_reverse(self): """ Baidu.reverse address """ self.reverse_run( {"query": u( "\u5317\u4eac\u5e02\u6d77\u6dc0\u533a\u4e2d" "\u5173\u6751\u5927\u885727\u53f7" )}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, )
def test_basic_address(self): """ Baidu.geocode """ self.geocode_run( {"query": u( "\u5317\u4eac\u5e02\u6d77\u6dc0\u533a" "\u4e2d\u5173\u6751\u5927\u885727\u53f7" )}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, )
def test_reverse_address(self): """ Baidu.reverse address """ self.reverse_run( {"query": u( "\u5317\u4eac\u5e02\u6d77\u6dc0\u533a\u4e2d" "\u5173\u6751\u5927\u885727\u53f7" )}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, )
def test_check_query(self): result_check_threeword_query = self.geocoder._check_query( u( "\u0066\u0061\u0068\u0072\u0070\u0072" "\u0065\u0069\u0073\u002e\u006c\u00fc" "\u0067\u006e\u0065\u0072\u002e\u006b" "\u0075\u0074\u0073\u0063\u0068\u0065" ) ) self.assertTrue(result_check_threeword_query)
def test_check_query(self): """ What3Wors.check_query - 'OneWord' and '3 Words' regex """ result_check_oneword_query = self.geocoder.check_query("*LibertyTech") result_check_threeword_query = self.geocoder.check_query(u("\u0066\u0061\u0068\u0072\u0070\u0072" "\u0065\u0069\u0073\u002e\u006c\u00fc" "\u0067\u006e\u0065\u0072\u002e\u006b" "\u0075\u0074\u0073\u0063\u0068\u0065")) self.assertTrue(result_check_oneword_query) self.assertTrue(result_check_threeword_query)
def test_safe_within_signature(self): """ Baidu signature calculation with safe characters """ self.geocode_run( {"query": u( "\u5317\u4eac\u5e02\u6d77\u6dc0\u533a" "\u4e2d\u5173\u6751\u5927\u885727\u53f7" "!*'();:@&=+$,/?[] %" )}, {"latitude": 39.983615544507, "longitude": 116.32295155093}, )
def test_unicode_query(self): self.geocode_run( { "query": u("\u0070\u0069\u0070\u0065\u0064\u002e\u0067" "\u0061\u0069\u006e\u0073\u002e\u006a\u0061" "\u006e\u0067\u006c\u0065") }, { "latitude": 53.037611, "longitude": 11.565012 }, )
def test_unicode_name(self): """ Bing.geocode unicode """ res = self._make_request( self.geocoder.geocode, u("\u6545\u5bab"), ) if res is None: unittest.SkipTest("Bing sometimes returns no result") else: self.assertAlmostEqual(res.latitude, 39.916, delta=self.delta) self.assertAlmostEqual(res.longitude, 116.390, delta=self.delta)
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_check_query(self): """ What3Wors.check_query - 'OneWord' and '3 Words' regex """ result_check_oneword_query = self.geocoder.check_query("*LibertyTech") result_check_threeword_query = self.geocoder.check_query( u("\u0066\u0061\u0068\u0072\u0070\u0072" "\u0065\u0069\u0073\u002e\u006c\u00fc" "\u0067\u006e\u0065\u0072\u002e\u006b" "\u0075\u0074\u0073\u0063\u0068\u0065")) self.assertTrue(result_check_oneword_query) self.assertTrue(result_check_threeword_query)
def test_unicode_query(self): """ What3Words.geocode - '3 Words' unicode """ self.geocode_run( { "query": u( "\u0070\u0069\u0070\u0065\u0064\u002e\u0067" "\u0061\u0069\u006e\u0073\u002e\u006a\u0061" "\u006e\u0067\u006c\u0065" ) }, {"latitude": 53.037611, "longitude": 11.565012}, )
def test_unicode_query(self): """ What3Words.geocode - '3 Words' unicode """ self.geocode_run( { "query": u( "\u0070\u0069\u0070\u0065\u0064\u002e\u0067" "\u0061\u0069\u006e\u0073\u002e\u006a\u0061" "\u006e\u0067\u006c\u0065" ) }, {"latitude": 53.037611, "longitude": 11.565012}, ) self.geocode_run( { "query": u( "\u002a\u004c\u0069\u0062\u0065\u0072\u0074" "\u0079\u0054\u0065\u0063\u0068" ) }, {"latitude": 51.512573, "longitude": -0.144879}, )
def test_bounded(self): bb = (Point('56.588456', '84.719353'), Point('56.437293', '85.296822')) query = u('\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c ' '\u0442\u043e\u043c\u0441\u043a') self.geocoder = self.make_geocoder(view_box=bb) self.geocode_run( {"query": query}, {"latitude": 56.4129459, "longitude": 84.847831069814}, ) self.geocoder = self.make_geocoder(view_box=bb, bounded=True) self.geocode_run( {"query": query}, {"latitude": 56.4803224, "longitude": 85.0060457653324}, )
def test_location_repr(self): """ Location.__repr__ string and unicode """ address = u( "22, Ksi\u0119dza Paw\u0142a Po\u015bpiecha, " "Centrum Po\u0142udnie, Zabrze, wojew\xf3dztwo " "\u015bl\u0105skie, 41-800, Polska" ) point = (0.0, 0.0, 0.0) loc = Location(address, point) if py3k: self.assertEqual( repr(loc), "Location(%s, %r)" % (address, point) ) else: self.assertEqual( repr(loc), "Location((%s, %s, %s))" % point )
def test_unicode_name(self): self.geocode_run( {"query": u("\u6545\u5bab \u5317\u4eac")}, {"latitude": 39.916, "longitude": 116.390}, )
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')
def test_geocode(self): self.geocode_run( {"query": u("piped.gains.jangle")}, {"latitude": 53.037611, "longitude": 11.565012}, )