示例#1
0
    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)
        self.assertIsInstance(tz.pytz_timezone, datetime.tzinfo)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
    def _parse_json_timezone(self, response):
        self._raise_for_error(response)

        timezone_id = response.get("timezoneId")
        if timezone_id is None:
            # Sometimes (e.g. for Antarctica) GeoNames doesn't return
            # a `timezoneId` value, but it returns GMT offsets.
            # Apparently GeoNames always returns these offsets -- for
            # every single point on the globe.
            raw_offset = response["rawOffset"]
            return from_fixed_gmt_offset(raw_offset, raw=response)
        else:
            return from_timezone_name(timezone_id, raw=response)
示例#5
0
    def _parse_json_timezone(self, response):
        status = response.get('status')
        if status != 'OK':
            self._check_status(status)

        timezone_id = response.get("timeZoneId")
        if timezone_id is None:
            # Google returns `status: ZERO_RESULTS` for uncovered
            # points (e.g. for Antarctica), so there's nothing
            # meaningful to be returned as the `raw` response,
            # hence we return `None`.
            return None
        return from_timezone_name(timezone_id, raw=response)
示例#6
0
 def test_string(self):
     raw = dict(foo="bar")
     tz = from_timezone_name(self.timezone_name, raw)
     self.assertEqual(str(tz), self.timezone_name)
示例#7
0
 def _parse_json_timezone(self, response):
     return from_timezone_name(response["timeZoneId"], raw=response)