~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/regressiontests/utils/tzinfo.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import copy
2
 
import datetime
3
 
import os
4
 
import pickle
5
 
import time
6
 
from django.utils.tzinfo import FixedOffset, LocalTimezone
7
 
from django.utils import unittest
8
 
 
9
 
class TzinfoTests(unittest.TestCase):
10
 
 
11
 
    @classmethod
12
 
    def setUpClass(cls):
13
 
        cls.old_TZ = os.environ.get('TZ')
14
 
        os.environ['TZ'] = 'US/Eastern'
15
 
 
16
 
        try:
17
 
            # Check if a timezone has been set
18
 
            time.tzset()
19
 
            cls.tz_tests = True
20
 
        except AttributeError:
21
 
            # No timezone available. Don't run the tests that require a TZ
22
 
            cls.tz_tests = False
23
 
 
24
 
    @classmethod
25
 
    def tearDownClass(cls):
26
 
        if cls.old_TZ is None:
27
 
            del os.environ['TZ']
28
 
        else:
29
 
            os.environ['TZ'] = cls.old_TZ
30
 
 
31
 
        # Cleanup - force re-evaluation of TZ environment variable.
32
 
        if cls.tz_tests:
33
 
            time.tzset()
34
 
 
35
 
    def test_fixedoffset(self):
36
 
        self.assertEqual(repr(FixedOffset(0)), '+0000')
37
 
        self.assertEqual(repr(FixedOffset(60)), '+0100')
38
 
        self.assertEqual(repr(FixedOffset(-60)), '-0100')
39
 
        self.assertEqual(repr(FixedOffset(280)), '+0440')
40
 
        self.assertEqual(repr(FixedOffset(-280)), '-0440')
41
 
        self.assertEqual(repr(FixedOffset(-78.4)), '-0118')
42
 
        self.assertEqual(repr(FixedOffset(78.4)), '+0118')
43
 
        self.assertEqual(repr(FixedOffset(-5.5*60)), '-0530')
44
 
        self.assertEqual(repr(FixedOffset(5.5*60)), '+0530')
45
 
        self.assertEqual(repr(FixedOffset(-.5*60)), '-0030')
46
 
        self.assertEqual(repr(FixedOffset(.5*60)), '+0030')
47
 
 
48
 
    def test_16899(self):
49
 
        if not self.tz_tests:
50
 
            return
51
 
        ts = 1289106000
52
 
        # Midnight at the end of DST in US/Eastern: 2010-11-07T05:00:00Z
53
 
        dt = datetime.datetime.utcfromtimestamp(ts)
54
 
        # US/Eastern -- we force its representation to "EST"
55
 
        tz = LocalTimezone(dt + datetime.timedelta(days=1))
56
 
        self.assertEqual(
57
 
                repr(datetime.datetime.fromtimestamp(ts - 3600, tz)),
58
 
                'datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST)')
59
 
        self.assertEqual(
60
 
                repr(datetime.datetime.fromtimestamp(ts, tz)),
61
 
                'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
62
 
        self.assertEqual(
63
 
                repr(datetime.datetime.fromtimestamp(ts + 3600, tz)),
64
 
                'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
65
 
 
66
 
    def test_copy(self):
67
 
        now = datetime.datetime.now()
68
 
        self.assertIsInstance(copy.copy(FixedOffset(90)), FixedOffset)
69
 
        self.assertIsInstance(copy.copy(LocalTimezone(now)), LocalTimezone)
70
 
 
71
 
    def test_deepcopy(self):
72
 
        now = datetime.datetime.now()
73
 
        self.assertIsInstance(copy.deepcopy(FixedOffset(90)), FixedOffset)
74
 
        self.assertIsInstance(copy.deepcopy(LocalTimezone(now)), LocalTimezone)
75
 
 
76
 
    def test_pickling_unpickling(self):
77
 
        now = datetime.datetime.now()
78
 
        self.assertIsInstance(pickle.loads(pickle.dumps(FixedOffset(90))), FixedOffset)
79
 
        self.assertIsInstance(pickle.loads(pickle.dumps(LocalTimezone(now))), LocalTimezone)