DatetimeModuleTest.py :  » Ajax » pyjamas » src » examples » libtest » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » libtest » DatetimeModuleTest.py
# Testing datetime module

import sys
import UnitTest
import datetime


class DatetimeModuleTest(UnitTest.UnitTest):

    def testDate(self):
        d = datetime.date(2010, 4, 9)
        self.assertEqual(d.year, 2010)
        self.assertEqual(d.month, 4)
        self.assertEqual(d.day, 9)
        self.assertEqual(d.weekday(), 4)

    def testTime(self):
        t = datetime.time(9, 45, 11, 95000)
        self.assertEqual(t.hour, 9)
        self.assertEqual(t.minute, 45)
        self.assertEqual(t.second, 11)
        self.assertEqual(t.microsecond, 95000)

    def testTimestamp(self):
        d = datetime.date.fromtimestamp(1270804609)
        self.assertEqual(str(d), '2010-04-09')
        dt = datetime.datetime.fromtimestamp(1270804609.95)
        self.assertEqual(str(dt), '2010-04-09 11:16:49.950000')

    def testCtime(self):
        d = datetime.date(2010, 4, 9)
        self.assertEqual(d.ctime(), "Fri Apr  9 00:00:00 2010")
        dt = datetime.datetime(2010, 4, 9, 10, 57, 32)
        self.assertEqual(dt.ctime(), "Fri Apr  9 10:57:32 2010")

    def testIsoCalendar(self):
        d = datetime.date(2010, 4, 9)
        self.assertEqual(d.isocalendar(), (2010, 14, 5))
        d1 = datetime.date(2007, 12, 31)
        self.assertEqual(d1.isocalendar(), (2008, 1, 1))

    def testIsoFormat(self):
        d = datetime.date(2010, 4, 9)
        self.assertEqual(d.isoformat(), '2010-04-09')
        dt = datetime.datetime(2010, 4, 9, 10, 57, 32)
        self.assertEqual(dt.isoformat(), '2010-04-09T10:57:32')
        dt2 = datetime.datetime(2010, 4, 9, 10, 57, 32, 95000)
        self.assertEqual(dt2.isoformat(), '2010-04-09T10:57:32.095000')

    def testOrdinal(self):
        d = datetime.date.fromordinal(1)
        self.assertEqual(str(d), '0001-01-01')
        d1 = datetime.date.fromordinal(733871)
        self.assertEqual(str(d1), '2010-04-09')
        self.assertEqual(d1.toordinal(), 733871)

    def testReplace(self):
        d = datetime.date(2010, 4, 9).replace(month=6, day=13)
        self.assertEqual(str(d), '2010-06-13')
        t = datetime.time(23, 59, 59).replace(minute=45, microsecond=95000)
        self.assertEqual(str(t), '23:45:59.095000')
        dt = datetime.datetime(2010, 4, 9, 10, 57, 32).replace(month=6, day=13, hour=12, minute=0, second=0)
        self.assertEqual(str(dt), '2010-06-13 12:00:00')

    def testTimetuple(self):
        tm = datetime.date(2010, 4, 9).timetuple()
        self.assertEqual(tm.tm_year, 2010)
        self.assertEqual(tm.tm_mon, 4)
        self.assertEqual(tm.tm_mday, 9)
        self.assertEqual(tm.tm_hour, 0)
        self.assertEqual(tm.tm_min, 0)
        self.assertEqual(tm.tm_sec, 0)
        self.assertEqual(tm.tm_wday, 4)
        self.assertEqual(tm.tm_yday, 99)

    def testStrftime(self):
        d = datetime.date(2010, 4, 9)
        self.assertEqual(d.strftime("%d/%m/%y"), "09/04/10")

    def testComparision(self):
        d1 = datetime.date(2010, 6, 8)
        d2 = datetime.date(2010, 6, 8)
        d3 = datetime.date(2010, 4, 9)
        self.assertTrue(d1 == d2, "d1 and d2 differ")
        self.assertTrue(d1 > d3, "d1 is not later than d3")
        self.assertTrue(d3 < d1, "d3 is not earlier than d1")

    def testOperations(self):
        d1 = datetime.date(2010, 4, 9)
        d2 = datetime.date(2010, 6, 13)
        diff = d2 - d1
        self.assertEqual(diff.days, 65)
        self.assertEqual(str(d1 + diff), "2010-06-13")
        self.assertEqual(str(d1 - diff), "2010-02-03")

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.