source: geniuswebcore/test/geniusweb/progress/ProgressTimeTest.py@ 88

Last change on this file since 88 was 88, checked in by Bart Vastenhouw, 3 years ago

Added python SimpleRunner GUI

File size: 2.0 KB
Line 
1
2from datetime import datetime
3import unittest
4
5from pyson.ObjectMapper import ObjectMapper
6
7from geniusweb.progress.Progress import Progress
8from geniusweb.progress.ProgressRounds import ProgressRounds
9from geniusweb.progress.ProgressTime import ProgressTime
10
11
12class ProgressTimeTest(unittest.TestCase):
13 pyson=ObjectMapper()
14 progress = ProgressTime(1999, datetime.fromtimestamp(100000.9))
15 progress1 = ProgressTime(1999, datetime.fromtimestamp(100000.9))
16 progress2 = ProgressTime(999, datetime.fromtimestamp(100000.9))
17 progress3 = ProgressTime(1999, datetime.fromtimestamp(100001.9))
18 progresjson = {"ProgressTime":{"duration":1999, 'start':100000900}}
19
20 def testDeserialization(self):
21 self.assertEqual(self.progress, self.pyson.parse(self.progresjson, Progress))
22
23 def testSerialization(self):
24 print(self.pyson.toJson(self.progress))
25 self.assertEqual(self.progresjson, self.pyson.toJson(self.progress))
26
27 def testRepr(self):
28 self.assertEqual("ProgressTime[100000.9 , 1999ms]", repr(self.progress))
29
30 def testEqual(self):
31 self.assertEqual(self.progress, self.progress1)
32 self.assertNotEqual(self.progress, self.progress2)
33 self.assertNotEqual(self.progress, self.progress3)
34 self.assertEqual(hash(self.progress), hash(self.progress1))
35 self.assertNotEqual(hash(self.progress), hash(self.progress2))
36 self.assertNotEqual(hash(self.progress), hash(self.progress3))
37
38 def testPastDeadline(self):
39 self.assertFalse(self.progress.isPastDeadline(100000900+1999))
40 self.assertTrue(self.progress.isPastDeadline(100000900+1999+1))
41
42 def testTerminationTime(self):
43 self.assertEqual(datetime.fromtimestamp((100000900+1999)/1000), self.progress.getTerminationTime())
44
45 def testGet(self):
46 self.assertEqual(0, self.progress.get(100000.9))
47 self.assertEqual(1, self.progress.get(100000.9+1999))
48 self.assertEqual(0.5, self.progress.get(100000.9+1999/2))
Note: See TracBrowser for help on using the repository browser.