~jaap.karssenberg/zim/pyzim-gtk3

« back to all changes in this revision

Viewing changes to tests/datetimetz.py

  • Committer: Jaap Karssenberg
  • Date: 2014-03-08 11:47:43 UTC
  • mfrom: (668.1.49 pyzim-refactor)
  • Revision ID: jaap.karssenberg@gmail.com-20140308114743-fero6uvy9zirbb4o
Merge branch with refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright 2014 Jaap Karssenberg <jaap.karssenberg@gmail.com>
 
4
 
 
5
 
 
6
from __future__ import with_statement
 
7
 
 
8
import tests
 
9
 
 
10
import warnings
 
11
 
 
12
import zim.datetimetz as datetime
 
13
 
 
14
 
 
15
class TestDateTimeZ(tests.TestCase):
 
16
 
 
17
        # FIXME would be better to test correctness of results
 
18
        #       but first check functions do not give errors
 
19
 
 
20
        def setUp(self):
 
21
                with warnings.catch_warnings():
 
22
                        warnings.simplefilter("ignore")
 
23
                        try:
 
24
                                import babel
 
25
                        except ImportError:
 
26
                                pass
 
27
 
 
28
        def runTest(self):
 
29
                # now()
 
30
                dt = datetime.now()
 
31
                s = dt.isoformat()
 
32
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
33
 
 
34
                s = dt.strftime("%z")
 
35
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
36
 
 
37
                s = dt.strftime("%Z")
 
38
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
39
 
 
40
                # strftime
 
41
                s = datetime.strftime('%a', dt)
 
42
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
43
 
 
44
                s = datetime.strftime('%%', dt)
 
45
                self.assertEqual(s, '%')
 
46
 
 
47
                s = datetime.strftime('%u', dt)
 
48
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
49
 
 
50
                s = datetime.strftime('%V', dt)
 
51
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
52
 
 
53
                # strfcal
 
54
                s = datetime.strfcal('%w', dt)
 
55
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
56
 
 
57
                s = datetime.strfcal('%W', dt)
 
58
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
59
 
 
60
                s = datetime.strfcal('%Y', dt)
 
61
                self.assertTrue(isinstance(s, basestring) and len(s) > 0)
 
62
 
 
63
                s = datetime.strfcal('%%', dt)
 
64
                self.assertEqual(s, '%')
 
65
 
 
66
                # weekcalendar
 
67
                year, week, weekday = datetime.weekcalendar(dt)
 
68
                self.assertTrue(isinstance(year, int) and 1900 < year and 3000 > year)
 
69
                self.assertTrue(isinstance(week, int) and 1 <= week and 53 >= week)
 
70
                self.assertTrue(isinstance(weekday, int) and 1 <= weekday and 7 >= weekday)
 
71
 
 
72
                # dates_for_week
 
73
                start, end = datetime.dates_for_week(year, week)
 
74
                self.assertTrue(isinstance(start, datetime.date))
 
75
                self.assertTrue(isinstance(end, datetime.date))
 
76
                self.assertTrue(start <= dt.date() and end >= dt.date())