[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.57,1.58 datetime.py,1.92,1.93 test_both.py,1.58,1.59

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Wed, 11 Dec 2002 13:47:41 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv8566

Modified Files:
	datetime.c datetime.py test_both.py 
Log Message:
Started added timetz tests to test_both.
Changed the Python timetz to default all arguments to 0.
Changed the C internals so that a uctoffset() call returning None can
be distinguished from a call returning 0.


Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** datetime.c	11 Dec 2002 21:29:56 -0000	1.57
--- datetime.c	11 Dec 2002 21:47:38 -0000	1.58
***************
*** 697,707 ****
  /* Call tzinfo.utcoffset(tzinfoarg), and extract an integer from the
   * result.  tzinfo must be an instance of the tzinfo class.  If utcoffset()
!  * returns None, get_utcoffset returns 0.  If uctoffset() doesn't return
!  * a Python int or long, TypeError is raised and this returns -1.  If
!  * utcoffset() returns an int outside the legitimate range for a UTC offset,
!  * ValueError is raised and this returns -1.
   */
  static long
! get_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
  {
  	PyObject *u;
--- 697,708 ----
  /* Call tzinfo.utcoffset(tzinfoarg), and extract an integer from the
   * result.  tzinfo must be an instance of the tzinfo class.  If utcoffset()
!  * returns None, get_utcoffset returns 0 and sets *none to 1.  If uctoffset()
!  & doesn't return a Python int or long, TypeError is raised and this
!  * returns -1.  If utcoffset() returns an int outside the legitimate range
!  * for a UTC offset, ValueError is raised and this returns -1.  Else
!  * *none is set to 0 and the offset is returned.
   */
  static long
! get_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg, int *none)
  {
  	PyObject *u;
***************
*** 712,715 ****
--- 713,717 ----
  	assert(tzinfoarg != NULL);
  
+ 	*none = 0;
  	u = PyObject_CallMethod(tzinfo, "utcoffset", "O", tzinfoarg);
  	if (u == NULL)
***************
*** 718,721 ****
--- 720,724 ----
  	if (u == Py_None) {
  		result = 0;
+ 		*none = 1;
  		goto Done;
  	}
***************
*** 762,769 ****
  	long minutes;
  	char sign;
  
! 	offset = get_utcoffset(tzinfo, tzinfoarg);
  	if (offset == -1 && PyErr_Occurred())
  		return -1;
  	sign = '+';
  	if (offset < 0) {
--- 765,775 ----
  	long minutes;
  	char sign;
+ 	int none;
  
! 	offset = get_utcoffset(tzinfo, tzinfoarg, &none);
  	if (offset == -1 && PyErr_Occurred())
  		return -1;
+ 	if (none)
+ 		return 0;
  	sign = '+';
  	if (offset < 0) {

Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.92
retrieving revision 1.93
diff -C2 -d -r1.92 -r1.93
*** datetime.py	10 Dec 2002 20:44:23 -0000	1.92
--- datetime.py	11 Dec 2002 21:47:38 -0000	1.93
***************
*** 892,896 ****
      """
  
!     def __init__(self, hour, minute, second=0, microsecond=0, tzinfo=None):
          """Constructor.
  
--- 892,896 ----
      """
  
!     def __init__(self, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
          """Constructor.
  

Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -C2 -d -r1.58 -r1.59
*** test_both.py	11 Dec 2002 01:47:20 -0000	1.58
--- test_both.py	11 Dec 2002 21:47:39 -0000	1.59
***************
*** 42,45 ****
--- 42,46 ----
  time = datetime.time
  tzinfo = datetime.tzinfo
+ timetz = datetime.timetz
  MINYEAR = datetime.MINYEAR
  MAXYEAR = datetime.MAXYEAR
***************
*** 1439,1442 ****
--- 1440,1457 ----
          self.failUnless(not cls())
  
+ 
+ class TestTimeTZ(unittest.TestCase):
+ 
+     theclass = timetz
+ 
+     def test_empty(self):
+         t = self.theclass()
+         self.assertEqual(t.hour, 0)
+         self.assertEqual(t.minute, 0)
+         self.assertEqual(t.second, 0)
+         self.assertEqual(t.microsecond, 0)
+         self.assertEqual(t.tzinfo, None)
+ 
+ 
  def test_suite():
      allsuites = [unittest.makeSuite(klass, 'test')
***************
*** 1448,1451 ****
--- 1463,1467 ----
                                 TestDateTime,
                                 TestTime,
+                                TestTimeTZ,
                                )
                  ]