Back to index

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

List of all members.

Public Member Functions

def setUp
def test_str
def test_repr
def test_class_members
def test_constructor
def test_inheritance
def test_utcoffset
def test_dst
def test_tzname
def test_fromutc
def test_comparison
def test_aware_datetime

Public Attributes

 ACDT
 EST
 DT

Detailed Description

Definition at line 145 of file datetimetester.py.


Member Function Documentation

Definition at line 147 of file datetimetester.py.

00147 
00148     def setUp(self):
00149         self.ACDT = timezone(timedelta(hours=9.5), 'ACDT')
00150         self.EST = timezone(-timedelta(hours=5), 'EST')
00151         self.DT = datetime(2010, 1, 1)

Here is the caller graph for this function:

Definition at line 239 of file datetimetester.py.

00239 
00240     def test_aware_datetime(self):
00241         # test that timezone instances can be used by datetime
00242         t = datetime(1, 1, 1)
00243         for tz in [timezone.min, timezone.max, timezone.utc]:
00244             self.assertEqual(tz.tzname(t),
00245                              t.replace(tzinfo=tz).tzname())
00246             self.assertEqual(tz.utcoffset(t),
00247                              t.replace(tzinfo=tz).utcoffset())
00248             self.assertEqual(tz.dst(t),
00249                              t.replace(tzinfo=tz).dst())

Here is the call graph for this function:

Definition at line 166 of file datetimetester.py.

00166 
00167     def test_class_members(self):
00168         limit = timedelta(hours=23, minutes=59)
00169         self.assertEqual(timezone.utc.utcoffset(None), ZERO)
00170         self.assertEqual(timezone.min.utcoffset(None), -limit)
00171         self.assertEqual(timezone.max.utcoffset(None), limit)
00172 

Here is the call graph for this function:

Definition at line 232 of file datetimetester.py.

00232 
00233     def test_comparison(self):
00234         self.assertNotEqual(timezone(ZERO), timezone(HOUR))
00235         self.assertEqual(timezone(HOUR), timezone(HOUR))
00236         self.assertEqual(timezone(-5 * HOUR), timezone(-5 * HOUR, 'EST'))
00237         with self.assertRaises(TypeError): timezone(ZERO) < timezone(ZERO)
00238         self.assertIn(timezone(ZERO), {timezone(ZERO)})

Here is the call graph for this function:

Definition at line 173 of file datetimetester.py.

00173 
00174     def test_constructor(self):
00175         self.assertIs(timezone.utc, timezone(timedelta(0)))
00176         self.assertIsNot(timezone.utc, timezone(timedelta(0), 'UTC'))
00177         self.assertEqual(timezone.utc, timezone(timedelta(0), 'UTC'))
00178         # invalid offsets
00179         for invalid in [timedelta(microseconds=1), timedelta(1, 1),
00180                         timedelta(seconds=1), timedelta(1), -timedelta(1)]:
00181             self.assertRaises(ValueError, timezone, invalid)
00182             self.assertRaises(ValueError, timezone, -invalid)
00183 
00184         with self.assertRaises(TypeError): timezone(None)
00185         with self.assertRaises(TypeError): timezone(42)
00186         with self.assertRaises(TypeError): timezone(ZERO, None)
00187         with self.assertRaises(TypeError): timezone(ZERO, 42)
00188         with self.assertRaises(TypeError): timezone(ZERO, 'ABC', 'extra')

Here is the call graph for this function:

Definition at line 204 of file datetimetester.py.

00204 
00205     def test_dst(self):
00206         self.assertIsNone(timezone.utc.dst(self.DT))
00207 
00208         with self.assertRaises(TypeError): self.EST.dst('')
00209         with self.assertRaises(TypeError): self.EST.dst(5)

Here is the call graph for this function:

Definition at line 220 of file datetimetester.py.

00220 
00221     def test_fromutc(self):
00222         with self.assertRaises(ValueError):
00223             timezone.utc.fromutc(self.DT)
00224         with self.assertRaises(TypeError):
00225             timezone.utc.fromutc('not datetime')
00226         for tz in [self.EST, self.ACDT, Eastern]:
00227             utctime = self.DT.replace(tzinfo=tz)
00228             local = tz.fromutc(utctime)
00229             self.assertEqual(local - utctime, tz.utcoffset(local))
00230             self.assertEqual(local,
00231                              self.DT.replace(tzinfo=timezone.utc))

Here is the call graph for this function:

Definition at line 189 of file datetimetester.py.

00189 
00190     def test_inheritance(self):
00191         self.assertIsInstance(timezone.utc, tzinfo)
00192         self.assertIsInstance(self.EST, tzinfo)

Here is the call graph for this function:

Definition at line 157 of file datetimetester.py.

00157 
00158     def test_repr(self):
00159         datetime = datetime_module
00160         for tz in [self.ACDT, self.EST, timezone.utc,
00161                    timezone.min, timezone.max]:
00162             # test round-trip
00163             tzrep = repr(tz)
00164             self.assertEqual(tz, eval(tzrep))
00165 

Here is the call graph for this function:

Definition at line 152 of file datetimetester.py.

00152 
00153     def test_str(self):
00154         for tz in [self.ACDT, self.EST, timezone.utc,
00155                    timezone.min, timezone.max]:
00156             self.assertEqual(str(tz), tz.tzname(None))

Here is the call graph for this function:

Definition at line 210 of file datetimetester.py.

00210 
00211     def test_tzname(self):
00212         self.assertEqual('UTC+00:00', timezone(ZERO).tzname(None))
00213         self.assertEqual('UTC-05:00', timezone(-5 * HOUR).tzname(None))
00214         self.assertEqual('UTC+09:30', timezone(9.5 * HOUR).tzname(None))
00215         self.assertEqual('UTC-00:01', timezone(timedelta(minutes=-1)).tzname(None))
00216         self.assertEqual('XYZ', timezone(-5 * HOUR, 'XYZ').tzname(None))
00217 
00218         with self.assertRaises(TypeError): self.EST.tzname('')
00219         with self.assertRaises(TypeError): self.EST.tzname(5)

Here is the call graph for this function:

Definition at line 193 of file datetimetester.py.

00193 
00194     def test_utcoffset(self):
00195         dummy = self.DT
00196         for h in [0, 1.5, 12]:
00197             offset = h * HOUR
00198             self.assertEqual(offset, timezone(offset).utcoffset(dummy))
00199             self.assertEqual(-offset, timezone(-offset).utcoffset(dummy))
00200 
00201         with self.assertRaises(TypeError): self.EST.utcoffset('')
00202         with self.assertRaises(TypeError): self.EST.utcoffset(5)
00203 

Here is the call graph for this function:


Member Data Documentation

Definition at line 148 of file datetimetester.py.

Definition at line 150 of file datetimetester.py.

Definition at line 149 of file datetimetester.py.


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