Back to index

python3.2  3.2.2
Public Member Functions
test.datetimetester.Oddballs Class Reference

List of all members.

Public Member Functions

def test_bug_1028306

Detailed Description

Definition at line 3642 of file datetimetester.py.


Member Function Documentation

Definition at line 3644 of file datetimetester.py.

03644 
03645     def test_bug_1028306(self):
03646         # Trying to compare a date to a datetime should act like a mixed-
03647         # type comparison, despite that datetime is a subclass of date.
03648         as_date = date.today()
03649         as_datetime = datetime.combine(as_date, time())
03650         self.assertTrue(as_date != as_datetime)
03651         self.assertTrue(as_datetime != as_date)
03652         self.assertTrue(not as_date == as_datetime)
03653         self.assertTrue(not as_datetime == as_date)
03654         self.assertRaises(TypeError, lambda: as_date < as_datetime)
03655         self.assertRaises(TypeError, lambda: as_datetime < as_date)
03656         self.assertRaises(TypeError, lambda: as_date <= as_datetime)
03657         self.assertRaises(TypeError, lambda: as_datetime <= as_date)
03658         self.assertRaises(TypeError, lambda: as_date > as_datetime)
03659         self.assertRaises(TypeError, lambda: as_datetime > as_date)
03660         self.assertRaises(TypeError, lambda: as_date >= as_datetime)
03661         self.assertRaises(TypeError, lambda: as_datetime >= as_date)
03662 
03663         # Neverthelss, comparison should work with the base-class (date)
03664         # projection if use of a date method is forced.
03665         self.assertEqual(as_date.__eq__(as_datetime), True)
03666         different_day = (as_date.day + 1) % 20 + 1
03667         as_different = as_datetime.replace(day= different_day)
03668         self.assertEqual(as_date.__eq__(as_different), False)
03669 
03670         # And date should compare with other subclasses of date.  If a
03671         # subclass wants to stop this, it's up to the subclass to do so.
03672         date_sc = SubclassDate(as_date.year, as_date.month, as_date.day)
03673         self.assertEqual(as_date, date_sc)
03674         self.assertEqual(date_sc, as_date)
03675 
03676         # Ditto for datetimes.
03677         datetime_sc = SubclassDatetime(as_datetime.year, as_datetime.month,
03678                                        as_date.day, 0, 0, 0)
03679         self.assertEqual(as_datetime, datetime_sc)
03680         self.assertEqual(datetime_sc, as_datetime)

Here is the call graph for this function:


The documentation for this class was generated from the following file: