You are not logged in Log in Join
You are here: Home » Members » fdrake » DateTimeWiki » TestCases

Log in
Name

Password

 
 
FrontPage »

TestCases

As a way to capture requirements and understand the assumptions being made by potential users of the new date/time type, we'd like to ask that potential users provide specific test cases that should pass for a working implementation. If possible, please present test cases as "test methods" of a unittest-based test class.

For example, one such test might be:

  def test_basic_attributes(self):
      dt = datetime(2002, 3, 1, 12, 0, 0)
      self.assertEqual(dt.year, 2002)
      self.assertEqual(dt.month, 3)
      self.assertEqual(dt.day, 1)
      self.assertEqual(dt.hour, 12)
      self.assertEqual(dt.minute, 0)
      self.assertEqual(dt.second, 0)

  def test_tz_independent_comparing(self):
      dt1 = datetime(2002, 3, 1, 9, 0, 0, tzoffset=-60)
      dt2 = datetime(2002, 3, 1, 10, 0, 0, tzoffset=-60)
      dt3 = datetime(2002, 3, 1, 10, 0, 0, tzoffset=0)
      self.assertEqual(dt1, dt3)
      self.assert_(dt2 > dt3)

  def test_resolution_info(self):
      self.assert_(isinstance(datetime.min, datetime))
      self.assert_(isinstance(datetime.max, datetime))
      self.assert_(isinstance(datetime.resolution, timedelta))
      self.assert_(datetime.max > datetime.min)

Since instances must be immutable, this test won't work:

  ## def test_normalizing_attributes(self):
  ##     dt = datetime.new(2002, 3, 30, 1, 0, 0)
  ##     dt.hour -= 5
  ##     self.assertEqual(dt.hour, 20)
  ##     self.assertEqual(dt.day, 29)       
  ##     dt.day += 3
  ##     self.assertEqual(dt.day, 1)
  ##     self.assertEqual(dt.month, 4)

SuggestedRequirements contains requirement statements that are not expressed as test code.

Note: I've implemented enough to make the above tests succeed, roughly, in the nondist/sandbox/datetime/ directory of the Python CVS tree. (Guido)


(Guido: removed some outdated comments)

s.keim (Mar 1, 2002 11:37 am; Comment #3)
For immutability this is probably a good way to avoid mess, but I'd like to have a kind of normalization. This could be very helpful for relative duration handling. But since I don't think it would be a good idea to have this in the constructor, I don't know how to express this anymore
Guido's response
The constructor of the current timedelta class supports normalization.