mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 01:14:09 +03:00
Fixed repr for FixedOffsetTimezone for offsets west of UTC (negative)
The offset displayed was always positive and somewhat confusing. The offset displayed now is the offset that the instance was created with. Also added some tests for initialisation.
This commit is contained in:
parent
35ff2def34
commit
1469a56512
|
@ -50,8 +50,9 @@ class FixedOffsetTimezone(datetime.tzinfo):
|
|||
self._name = name
|
||||
|
||||
def __repr__(self):
|
||||
offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60
|
||||
return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \
|
||||
% (self._offset.seconds // 60, self._name)
|
||||
% (offset_mins, self._name)
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self._offset
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
import math
|
||||
import unittest
|
||||
import psycopg2
|
||||
from psycopg2.tz import FixedOffsetTimezone
|
||||
from psycopg2.tz import FixedOffsetTimezone, ZERO
|
||||
from testconfig import dsn
|
||||
|
||||
class CommonDatetimeTestsMixin:
|
||||
|
@ -513,6 +513,25 @@ class FromTicksTestCase(unittest.TestCase):
|
|||
time(0, 11, 59, 999920))
|
||||
|
||||
|
||||
class FixedOffsetTimezoneTests(unittest.TestCase):
|
||||
|
||||
def test_init_with_no_args(self):
|
||||
tzinfo = FixedOffsetTimezone()
|
||||
self.assert_(tzinfo._offset is ZERO)
|
||||
self.assert_(tzinfo._name is None)
|
||||
|
||||
def test_repr_with_positive_offset(self):
|
||||
tzinfo = FixedOffsetTimezone(5 * 60)
|
||||
self.assertEqual(repr(tzinfo), "psycopg2.tz.FixedOffsetTimezone(offset=300, name=None)")
|
||||
|
||||
def test_repr_with_negative_offset(self):
|
||||
tzinfo = FixedOffsetTimezone(-5 * 60)
|
||||
self.assertEqual(repr(tzinfo), "psycopg2.tz.FixedOffsetTimezone(offset=-300, name=None)")
|
||||
|
||||
def test_repr_with_name(self):
|
||||
tzinfo = FixedOffsetTimezone(name="FOO")
|
||||
self.assertEqual(repr(tzinfo), "psycopg2.tz.FixedOffsetTimezone(offset=0, name='FOO')")
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user