Back to index

python3.2  3.2.2
Public Member Functions | Private Attributes
test.datetimetester.TestTZInfo Class Reference

List of all members.

Public Member Functions

def test_non_abstractness
def test_subclass_must_override
def test_normal
def test_pickling_base
def test_pickling_subclass

Private Attributes

 __offset
 __name

Detailed Description

Definition at line 79 of file datetimetester.py.


Member Function Documentation

Definition at line 81 of file datetimetester.py.

00081 
00082     def test_non_abstractness(self):
00083         # In order to allow subclasses to get pickled, the C implementation
00084         # wasn't able to get away with having __init__ raise
00085         # NotImplementedError.
00086         useless = tzinfo()
00087         dt = datetime.max
00088         self.assertRaises(NotImplementedError, useless.tzname, dt)
00089         self.assertRaises(NotImplementedError, useless.utcoffset, dt)
00090         self.assertRaises(NotImplementedError, useless.dst, dt)

Here is the call graph for this function:

Definition at line 105 of file datetimetester.py.

00105 
00106     def test_normal(self):
00107         fo = FixedOffset(3, "Three")
00108         self.assertIsInstance(fo, tzinfo)
00109         for dt in datetime.now(), None:
00110             self.assertEqual(fo.utcoffset(dt), timedelta(minutes=3))
00111             self.assertEqual(fo.tzname(dt), "Three")
00112             self.assertEqual(fo.dst(dt), timedelta(minutes=42))

Here is the call graph for this function:

Definition at line 113 of file datetimetester.py.

00113 
00114     def test_pickling_base(self):
00115         # There's no point to pickling tzinfo objects on their own (they
00116         # carry no data), but they need to be picklable anyway else
00117         # concrete subclasses can't be pickled.
00118         orig = tzinfo.__new__(tzinfo)
00119         self.assertTrue(type(orig) is tzinfo)
00120         for pickler, unpickler, proto in pickle_choices:
00121             green = pickler.dumps(orig, proto)
00122             derived = unpickler.loads(green)
00123             self.assertTrue(type(derived) is tzinfo)

Here is the call graph for this function:

Definition at line 124 of file datetimetester.py.

00124 
00125     def test_pickling_subclass(self):
00126         # Make sure we can pickle/unpickle an instance of a subclass.
00127         offset = timedelta(minutes=-300)
00128         for otype, args in [
00129             (PicklableFixedOffset, (offset, 'cookie')),
00130             (timezone, (offset,)),
00131             (timezone, (offset, "EST"))]:
00132             orig = otype(*args)
00133             oname = orig.tzname(None)
00134             self.assertIsInstance(orig, tzinfo)
00135             self.assertIs(type(orig), otype)
00136             self.assertEqual(orig.utcoffset(None), offset)
00137             self.assertEqual(orig.tzname(None), oname)
00138             for pickler, unpickler, proto in pickle_choices:
00139                 green = pickler.dumps(orig, proto)
00140                 derived = unpickler.loads(green)
00141                 self.assertIsInstance(derived, tzinfo)
00142                 self.assertIs(type(derived), otype)
00143                 self.assertEqual(derived.utcoffset(None), offset)
00144                 self.assertEqual(derived.tzname(None), oname)

Here is the call graph for this function:

Definition at line 91 of file datetimetester.py.

00091 
00092     def test_subclass_must_override(self):
00093         class NotEnough(tzinfo):
00094             def __init__(self, offset, name):
00095                 self.__offset = offset
00096                 self.__name = name
00097         self.assertTrue(issubclass(NotEnough, tzinfo))
00098         ne = NotEnough(3, "NotByALongShot")
00099         self.assertIsInstance(ne, tzinfo)
00100 
00101         dt = datetime.now()
00102         self.assertRaises(NotImplementedError, ne.tzname, dt)
00103         self.assertRaises(NotImplementedError, ne.utcoffset, dt)
00104         self.assertRaises(NotImplementedError, ne.dst, dt)

Here is the call graph for this function:


Member Data Documentation

Definition at line 95 of file datetimetester.py.

Definition at line 94 of file datetimetester.py.


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