Belle II Software light-2406-ragdoll
test_calculationQueue.py
1
8from unittest import TestCase, main
9
10from hep_ipython_tools.calculation_queue import CalculationQueue, CalculationQueueItem
11from hep_ipython_tools.tests.fixtures import MockQueue
12
13
14# @cond internal_test
15
16class A:
17 pass
18
19
20class TestCalculationQueue(TestCase):
21
22 def setUp(self):
23 self.calculation_queue = CalculationQueue()
24 self.calculation_queue.queue = MockQueue()
25
26 def test_put(self):
27 a = A()
28
29 self.calculation_queue.put("TestItem", "TestContent")
30 self.calculation_queue.put("TestItem2", 2.34)
31 self.calculation_queue.put("TestItem3", a)
32
33 items = self.calculation_queue.queue.internal_storage
34
35 self.assertEqual(len(items), 3)
36 self.assertEqual(items[0], CalculationQueueItem("TestItem", "TestContent"))
37 self.assertEqual(items[1], CalculationQueueItem("TestItem2", 2.34))
38 self.assertEqual(items[2], CalculationQueueItem("TestItem3", a))
39
40 def test_fill_results_no_dubs(self):
41 a = A()
42
43 self.calculation_queue.put("TestItem", "TestContent")
44 self.calculation_queue.put("TestItem2", 2.34)
45 self.calculation_queue.put("TestItem3", a)
46
47 self.calculation_queue.fill_results()
48
49 self.assertEqual(self.calculation_queue.get("TestItem"), "TestContent")
50 self.assertEqual(self.calculation_queue.get("TestItem2"), 2.34)
51 self.assertEqual(self.calculation_queue.get("TestItem3"), a)
52
53 self.assertIn("TestItem", self.calculation_queue.get_keys())
54 self.assertIn("TestItem2", self.calculation_queue.get_keys())
55 self.assertIn("TestItem3", self.calculation_queue.get_keys())
56
57 def test_fill_results_dubs(self):
58 self.calculation_queue.put("TestItem", "TestContent")
59 self.calculation_queue.put("TestItem", 2.34)
60 self.calculation_queue.put("TestItem2", "OtherContent")
61
62 self.calculation_queue.fill_results()
63
64 self.assertEqual(self.calculation_queue.get("TestItem"), 2.34)
65 self.assertEqual(self.calculation_queue.get("TestItem2"), "OtherContent")
66
67 self.assertIn("TestItem", self.calculation_queue.get_keys())
68 self.assertIn("TestItem2", self.calculation_queue.get_keys())
69
70
71if __name__ == "__main__":
72 main()
73# @endcond
Definition: main.py:1