gacks handle test case
[sfa.git] / tests / testGacksHandle.py
1 import unittest
2 import xmlrpclib
3 from gackshandle import *
4
5 class TestGacksHandle(unittest.TestCase):
6    def setUp(self):
7        pass
8
9    def testCreate(self):
10        h = GacksHandle("cpu", 10, 15, 20, 25)
11        self.assertEqual(h.id, "cpu")
12        self.assertEqual(h.unitStart, 10)
13        self.assertEqual(h.unitStop, 15)
14        self.assertEqual(h.timeStart, 20)
15        self.assertEqual(h.timeStop, 25)
16
17    def testAsString(self):
18        h = GacksHandle("cpu", 10, 15, 20, 25)
19        s = h.as_string()
20        self.assertEqual(s, "cpu#10-15#20-25")
21
22    def testLoadFromString(self):
23        h = GacksHandle("cpu", 10, 15, 20, 25)
24        s = h.as_string()
25        h2 = GacksHandle(string=s)
26        self.assertEqual(h.id, h2.id)
27        self.assertEqual(h.unitStart, h2.unitStart)
28        self.assertEqual(h.unitStop, h2.unitStop)
29        self.assertEqual(h.timeStart, h2.timeStart)
30        self.assertEqual(h.timeStop, h2.timeStop)
31
32    def testGetQuantity(self):
33        h = GacksHandle("cpu", 10, 15, 20, 25)
34        self.assertEqual(h.get_quantity(), 5)
35
36    def testGetDuration(self):
37        h = GacksHandle("cpu", 10, 15, 20, 25)
38        self.assertEqual(h.get_duration(), 5)
39
40    def testClone(self):
41        h = GacksHandle("cpu", 10, 15, 20, 25)
42        h2 = h.clone()
43        self.assertEqual(h.id, h2.id)
44        self.assertEqual(h.unitStart, h2.unitStart)
45        self.assertEqual(h.unitStop, h2.unitStop)
46        self.assertEqual(h.timeStart, h2.timeStart)
47        self.assertEqual(h.timeStop, h2.timeStop)
48
49    def testSplit(self):
50        h = GacksHandle("cpu", 10, 15, 20, 25)
51        (h1, h2) = h.split(12,23)
52
53        self.assertEqual(h1.id, "cpu")
54        self.assertEqual(h1.unitStart, 10)
55        self.assertEqual(h1.unitStop, 12)
56        self.assertEqual(h1.timeStart, 20)
57        self.assertEqual(h1.timeStop, 23)
58
59        self.assertEqual(h2.id, "cpu")
60        self.assertEqual(h2.unitStart, 12)
61        self.assertEqual(h2.unitStop, 15)
62        self.assertEqual(h2.timeStart, 23)
63        self.assertEqual(h2.timeStop, 25)
64
65 class TestGacksRecord(unittest.TestCase):
66    def setUp(self):
67        pass
68
69    def testCreate(self):
70        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
71        self.assertEqual(r.id, "cpu")
72        self.assertEqual(r.unitStart, 10)
73        self.assertEqual(r.unitStop, 15)
74        self.assertEqual(r.timeStart, 20)
75        self.assertEqual(r.timeStop, 25)
76        self.assertEqual(r.allocatorHRNs, ["foo", "bar"])
77        self.assertEqual(r.consumerHRN, "slice1")
78
79    def testClone(self):
80        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
81        r2 = r.clone()
82
83        self.assertEqual(r.id, r2.id)
84        self.assertEqual(r.unitStart, r2.unitStart)
85        self.assertEqual(r.unitStop, r2.unitStop)
86        self.assertEqual(r.timeStart, r2.timeStart)
87        self.assertEqual(r.timeStop, r2.timeStop)
88        self.assertEqual(r.allocatorHRNs, r2.allocatorHRNs)
89        self.assertEqual(r.consumerHRN, r2.consumerHRN)
90
91    def testSetAllocator(self):
92        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
93        r.set_allocator("bar", "bob", -1, 1)
94        self.assertEqual(r.allocatorHRNs, ["foo", "bar", "bob"])
95
96        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
97        r.set_allocator("bar", "bob", -1, 0)
98        self.assertEqual(r.allocatorHRNs, ["foo", "bob"])
99
100        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar","foo","bar"], "slice1")
101        r.set_allocator("bar", "bob", 0, 0)
102        self.assertEqual(r.allocatorHRNs, ["foo", "bob"])
103
104        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar","foo","bar"], "slice1")
105        r.set_allocator("bar", "bob", 1, 0)
106        self.assertEqual(r.allocatorHRNs, ["foo", "bar", "foo", "bob"])
107
108    def testGetAllocator(self):
109        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
110        self.assertEqual(r.get_allocators(), ["foo", "bar"])
111
112    def testSetConsumer(self):
113        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
114        r.set_consumer("slice2")
115        self.assertEqual(r.get_consumer(), "slice2")
116
117    def testGetConsumer(self):
118        r = GacksRecord("cpu", 10, 15, 20, 25, ["foo","bar"], "slice1")
119        self.assertEqual(r.get_consumer(), "slice1")
120
121
122
123 if __name__ == "__main__":
124     unittest.main()