예제 #1
0
 def assertDuration(self, value, data):
     d = DvDuration(value)
     self.assertEqual(data[0], d.years())
     self.assertEqual(data[1], d.months())
     self.assertEqual(data[2], d.weeks())
     self.assertEqual(data[3], d.days())
     self.assertEqual(data[4], d.hours())
     self.assertEqual(data[5], d.minutes())
     self.assertEqual(data[6], d.seconds())
     self.assertEqual(data[7], (int)(d.fractional_seconds()*1000.0))
예제 #2
0
    def testConstructorTakesIntegers(self):
        datasets = [
            [0, 10, 3, 1, 19, 8, 37, 857], [0, 0, 0, 1, 0, 14, 2, 0],
            [0, 13, 56, 33, 25, 67, 77, 0], [0, -1, -2, 0, -9, 0, 0, 0], 
            [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 10, 9, 0, 0, 0],
        ]
        for i, data in enumerate(datasets):
            d = DvDuration(data)
            self.assertEqual("years", data[ 0 ], d.years())
            self.assertEqual("months", data[ 1 ], d.months())
            self.assertEqual("weeks", data[ 2 ], d.weeks())
            self.assertEqual("days", data[ 3 ], d.days())
            self.assertEqual("hours", data[ 4 ], d.hours())
            self.assertEqual("minutes", data[ 5 ], d.minutes())
            self.assertEqual("seconds", data[ 6 ], d.seconds())
            self.assertEqual("fseconds", data[ 7 ], (int)(d.fractional_seconds()*1000.0))

        fData = [
            [0, 0, 3, 1, 0, 8, 37, 1857], [0, 0, 0, -1, 0, 14, 2, 0],      
        ]
        for i, data in enumerate(fData):
            with self.self.assertRaises(Exception):
                d = DvDuration(data)