devtools/__init__.py
branchtls-sprint
changeset 1016 26387b836099
parent 937 491dbd818f9b
child 1802 d628defebc17
equal deleted inserted replaced
1014:4792a1bb72a9 1016:26387b836099
     1 """Test tools for cubicweb
     1 """Test tools for cubicweb
     2 
     2 
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 import os
     9 import os
    10 import logging
    10 import logging
       
    11 from datetime import timedelta
    11 from os.path import (abspath, join, exists, basename, dirname, normpath, split,
    12 from os.path import (abspath, join, exists, basename, dirname, normpath, split,
    12                      isfile, isabs)
    13                      isfile, isabs)
    13 
    14 
    14 from mx.DateTime import strptime, DateTimeDelta
       
    15 
       
    16 from cubicweb import CW_SOFTWARE_ROOT, ConfigurationError
    15 from cubicweb import CW_SOFTWARE_ROOT, ConfigurationError
       
    16 from cubicweb.utils import strptime
    17 from cubicweb.toolsutils import read_config
    17 from cubicweb.toolsutils import read_config
    18 from cubicweb.cwconfig import CubicWebConfiguration, merge_options
    18 from cubicweb.cwconfig import CubicWebConfiguration, merge_options
    19 from cubicweb.server.serverconfig import ServerConfiguration
    19 from cubicweb.server.serverconfig import ServerConfiguration
    20 from cubicweb.etwist.twconfig import TwistedConfiguration
    20 from cubicweb.etwist.twconfig import TwistedConfiguration
    21 
    21 
   269                 found_date = False
   269                 found_date = False
   270                 for row, rowdesc in zip(rset, rset.description):
   270                 for row, rowdesc in zip(rset, rset.description):
   271                     for cellindex, (value, vtype) in enumerate(zip(row, rowdesc)):
   271                     for cellindex, (value, vtype) in enumerate(zip(row, rowdesc)):
   272                         if vtype in ('Date', 'Datetime') and type(value) is unicode:
   272                         if vtype in ('Date', 'Datetime') and type(value) is unicode:
   273                             found_date = True
   273                             found_date = True
       
   274                             value = value.rsplit('.', 1)[0]
   274                             try:
   275                             try:
   275                                 row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S')
   276                                 row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S')
   276                             except:
   277                             except:
   277                                 row[cellindex] = strptime(value, '%Y-%m-%d')
   278                                 row[cellindex] = strptime(value, '%Y-%m-%d')
   278                         if vtype == 'Time' and type(value) is unicode:
   279                         if vtype == 'Time' and type(value) is unicode:
   282                             except:
   283                             except:
   283                                 # DateTime used as Time?
   284                                 # DateTime used as Time?
   284                                 row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S')
   285                                 row[cellindex] = strptime(value, '%Y-%m-%d %H:%M:%S')
   285                         if vtype == 'Interval' and type(value) is int:
   286                         if vtype == 'Interval' and type(value) is int:
   286                             found_date = True
   287                             found_date = True
   287                             row[cellindex] = DateTimeDelta(0, 0, 0, value)
   288                             row[cellindex] = timedelta(0, value, 0) # XXX value is in number of seconds?
   288                     if not found_date:
   289                     if not found_date:
   289                         break
   290                         break
   290             return rset
   291             return rset
   291         return new_execute
   292         return new_execute
   292     querier.__class__.execute = wrap_execute(querier.__class__.execute)
   293     querier.__class__.execute = wrap_execute(querier.__class__.execute)