Changeset 849 for trunk/tests


Ignore:
Timestamp:
Feb 9, 2016, 8:14:26 AM (3 years ago)
Author:
cito
Message:

Make timetz and timestamptz work properly with Python 2

Python 2 has no concrete timezone class, therefore we had so far returned only
naive datetimes in this case. This patch adds a simple concrete timezone class,
so we can return timetz and timestamptz with timezones in Python 2 as well.

Location:
trunk/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_classic_dbwrapper.py

    r833 r849  
    35733573        timezones = dict(CET=1, EET=2, EST=-5, UTC=0)
    35743574        for timezone in sorted(timezones):
    3575             offset = timezones[timezone]
     3575            tz = '%+03d00' % timezones[timezone]
    35763576            try:
    3577                 tzinfo = datetime.strptime('%+03d00' % offset, '%z').tzinfo
    3578             except ValueError:  # Python < 3.3
    3579                 tzinfo = None
     3577                tzinfo = datetime.strptime(tz, '%z').tzinfo
     3578            except ValueError:  # Python < 3.2
     3579                tzinfo = pg._get_timezone(tz)
    35803580            self.db.set_parameter('timezone', timezone)
    35813581            d = time(15, 9, 26, tzinfo=tzinfo)
     
    36283628        timezones = dict(CET=1, EET=2, EST=-5, UTC=0)
    36293629        for timezone in sorted(timezones):
    3630             offset = timezones[timezone]
     3630            tz = '%+03d00' % timezones[timezone]
    36313631            try:
    3632                 tzinfo = datetime.strptime('%+03d00' % offset, '%z').tzinfo
    3633             except ValueError:  # Python < 3.3
    3634                 tzinfo = None
     3632                tzinfo = datetime.strptime(tz, '%z').tzinfo
     3633            except ValueError:  # Python < 3.2
     3634                tzinfo = pg._get_timezone(tz)
    36353635            self.db.set_parameter('timezone', timezone)
    36363636            for datestyle in ('ISO', 'Postgres, MDY', 'Postgres, DMY',
  • trunk/tests/test_dbapi20.py

    r848 r849  
    3131from datetime import date, time, datetime, timedelta
    3232from uuid import UUID as Uuid
    33 
    34 try:
    35     from datetime import timezone
    36 except ImportError:  # Python < 3.2
    37     timezone = None
    3833
    3934try:
     
    579574                values = [dt.date(), dt.time(), dt,
    580575                    dt.time(), dt]
    581                 if timezone:
    582                     values[3] = values[3].replace(tzinfo=timezone.utc)
    583                     values[4] = values[4].replace(tzinfo=timezone.utc)
     576                values[3] = values[3].replace(tzinfo=pgdb.timezone.utc)
     577                values[4] = values[4].replace(tzinfo=pgdb.timezone.utc)
    584578                if n == 0:  # input as objects
    585579                    params = values
     
    589583                    d = (dt.year, dt.month, dt.day)
    590584                    t = (dt.hour, dt.minute, dt.second, dt.microsecond)
    591                     z = (timezone.utc,) if timezone else ()
     585                    z = (pgdb.timezone.utc,)
    592586                    params = [pgdb.Date(*d), pgdb.Time(*t),
    593587                            pgdb.Timestamp(*(d + t)), pgdb.Time(*(t + z)),
Note: See TracChangeset for help on using the changeset viewer.