def test_datehelpers(self): from logbook.helpers import format_iso8601, parse_iso8601 now = datetime.now() rv = format_iso8601() self.assertEqual(rv[:4], str(now.year)) self.assertRaises(ValueError, parse_iso8601, 'foo') v = parse_iso8601('2000-01-01T00:00:00.12Z') self.assertEqual(v.microsecond, 120000) v = parse_iso8601('2000-01-01T12:00:00+01:00') self.assertEqual(v.hour, 11) v = parse_iso8601('2000-01-01T12:00:00-01:00') self.assertEqual(v.hour, 13)
def test_datehelpers(): from logbook.helpers import format_iso8601, parse_iso8601 now = datetime.now() rv = format_iso8601() assert rv[:4] == str(now.year) with pytest.raises(ValueError): parse_iso8601('foo') v = parse_iso8601('2000-01-01T00:00:00.12Z') assert v.microsecond == 120000 v = parse_iso8601('2000-01-01T12:00:00+01:00') assert v.hour == 11 v = parse_iso8601('2000-01-01T12:00:00-01:00') assert v.hour == 13
def update_from_dict(self, d): """Like the :meth:`from_dict` classmethod, but will update the instance in place. Helpful for constructors. """ self.__dict__.update(d) for key in self._noned_on_close: setattr(self, key, None) self._information_pulled = True self._channel = None if isinstance(self.time, basestring): self.time = parse_iso8601(self.time) return self
def update_from_dict(self, d): """Like the :meth:`from_dict` classmethod, but will update the instance in place. Helpful for constructors. """ self.__dict__.update(d) for key in self._noned_on_close: setattr(self, key, None) self._information_pulled = True self._channel = None if isinstance(self.time, string_types): self.time = parse_iso8601(self.time) # TODO: Replace the lambda with str when we remove support for python 2` self.extra = defaultdict(lambda: u'', self.extra) return self
def update_from_dict(self, d): """Like the :meth:`from_dict` classmethod, but will update the instance in place. Helpful for constructors. """ self.__dict__.update(d) for key in self._noned_on_close: setattr(self, key, None) self._information_pulled = True self._channel = None if isinstance(self.time, string_types): self.time = parse_iso8601(self.time) # TODO: Replace the lambda with str when we remove support for python 2` self.extra = defaultdict(lambda: u"", self.extra) return self