Esempio n. 1
0
 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)
Esempio n. 2
0
    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
            },
        )
Esempio n. 3
0
 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)
Esempio n. 4
0
    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},
        )
Esempio n. 5
0
 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
Esempio n. 6
0
    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
            },
        )
Esempio n. 7
0
 def test_unicode_name(self):
     self.geocode_run(
         {"query": u("Stadelhoferstrasse 8, 8001 Z\u00fcrich")},
         {
             "latitude": 47.36649,
             "longitude": 8.54855
         },
     )
Esempio n. 8
0
 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},
     )
Esempio n. 9
0
 def test_unicode_name(self):
     self.geocode_run(
         {"query": u("Barri\u00e8re")},
         {
             "latitude": 51.179,
             "longitude": -120.123
         },
     )
Esempio n. 10
0
 def test_unicode_name(self):
     """
     Photon.geocode unicode
     """
     self.geocode_run(
         {"query": u("\u6545\u5bab")},
         {"latitude": 39.916, "longitude": 116.390},
     )
Esempio n. 11
0
    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
Esempio n. 12
0
 def test_unicode_name(self):
     self.geocode_run(
         {"query": u("\u6545\u5bab")},
         {
             "latitude": 25.0968,
             "longitude": 121.54714
         },
     )
Esempio n. 13
0
 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)
Esempio n. 14
0
File: photon.py Progetto: mthh/geopy
 def test_unicode_name(self):
     """
     Photon.geocode unicode
     """
     self.geocode_run(
         {"query": u("\u6545\u5bab")},
         {"latitude": 39.917252950000005, "longitude": 116.39077025499873}
     )
Esempio n. 15
0
File: bing.py Progetto: jmb/geopy
 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},
     )
Esempio n. 16
0
 def test_unicode_name(self):
     """
     Photon.geocode unicode
     """
     self.geocode_run({"query": u("\u6545\u5bab")}, {
         "latitude": 39.917252950000005,
         "longitude": 116.39077025499873
     })
Esempio n. 17
0
 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:]
Esempio n. 18
0
 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
     })
Esempio n. 19
0
 def test_unicode_name(self):
     self.geocode_run(
         {"query": u("\u6545\u5bab \u5317\u4eac")},
         {
             "latitude": 39.916,
             "longitude": 116.390
         },
     )
Esempio n. 20
0
 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)
Esempio n. 21
0
 def test_geocode(self):
     self.geocode_run(
         {"query": u("piped.gains.jangle")},
         {
             "latitude": 53.037611,
             "longitude": 11.565012
         },
     )
Esempio n. 22
0
 def test_geocode(self):
     """
     What3Words.geocode - '3 Words' and 'OneWord'
     """
     self.geocode_run(
         {"query": u("piped.gains.jangle")},
         {"latitude": 53.037611, "longitude": 11.565012},
     )
Esempio n. 23
0
File: here.py Progetto: jmb/geopy
 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}
     )
Esempio n. 24
0
 def test_unicode_name(self):
     """
     GoogleV3.geocode unicode
     """
     self.geocode_run(
         {"query": u("\u6545\u5bab")},
         {"latitude": 39.916, "longitude": 116.390},
     )
Esempio n. 25
0
 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:]
Esempio n. 27
0
 def test_unicode_name(self):
     """
     YahooPlaceFinder.geocode unicode
     """
     self.geocode_run(
         {"query": u("\u6545\u5bab")},
         {"latitude": 39.916, "longitude": 116.390},
     )
Esempio n. 28
0
File: databc.py Progetto: jmb/geopy
 def test_unicode_name(self):
     """
     DataBC.geocode unicode
     """
     self.geocode_run(
         {"query": u("Barri\u00e8re")},
         {"latitude": 51.179, "longitude": -120.123},
     )
Esempio n. 29
0
File: baidu.py Progetto: yeyan/geopy
 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},
     )
Esempio n. 30
0
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)
Esempio n. 31
0
    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
            },
        )
Esempio n. 32
0
 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)
Esempio n. 33
0
 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},
     )
Esempio n. 34
0
    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)
Esempio n. 35
0
 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)
Esempio n. 36
0
 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)
Esempio n. 37
0
 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},
     )
Esempio n. 38
0
File: baidu.py Progetto: yeyan/geopy
 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},
     )
Esempio n. 39
0
 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},
     )
Esempio n. 40
0
 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},
     )
Esempio n. 41
0
    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)
Esempio n. 42
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)
Esempio n. 43
0
 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},
     )
Esempio n. 44
0
 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
         },
     )
Esempio n. 45
0
 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)
Esempio n. 46
0
 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))
Esempio n. 47
0
 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))
Esempio n. 48
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)
Esempio n. 49
0
 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},
     )
Esempio n. 50
0
    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},
        )
Esempio n. 51
0
    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},
        )
Esempio n. 52
0
 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
         )
Esempio n. 53
0
 def test_unicode_name(self):
     self.geocode_run(
         {"query": u("\u6545\u5bab \u5317\u4eac")},
         {"latitude": 39.916, "longitude": 116.390},
     )
Esempio n. 54
0
File: baidu.py Progetto: jmb/geopy
 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')
Esempio n. 55
0
 def test_geocode(self):
     self.geocode_run(
         {"query": u("piped.gains.jangle")},
         {"latitude": 53.037611, "longitude": 11.565012},
     )