8from unittest
import TestCase, main
14class TestCalculationList(TestCase):
16 def test_create_every_parameter_combination(self):
18 parameter_names = [
"A",
"B",
"C"]
25 every_parameter_combination = create_every_parameter_combination(parameter_names,
28 self.assertEqual(len(every_parameter_combination), 8)
30 self.assertIn({
"A": 1,
"B":
"a",
"C":
"("}, every_parameter_combination)
31 self.assertIn({
"A": 1,
"B":
"a",
"C":
")"}, every_parameter_combination)
32 self.assertIn({
"A": 1,
"B":
"b",
"C":
"("}, every_parameter_combination)
33 self.assertIn({
"A": 1,
"B":
"b",
"C":
")"}, every_parameter_combination)
34 self.assertIn({
"A": 2,
"B":
"a",
"C":
"("}, every_parameter_combination)
35 self.assertIn({
"A": 2,
"B":
"a",
"C":
")"}, every_parameter_combination)
36 self.assertIn({
"A": 2,
"B":
"b",
"C":
"("}, every_parameter_combination)
37 self.assertIn({
"A": 2,
"B":
"b",
"C":
")"}, every_parameter_combination)
39 def test_create_all_calculations_no_queue(self):
40 def creator_function(x, y):
41 return {
"a": 2 * x,
"b": y + 1}
43 all_calculation_kwargs, all_queues, every_parameter_combination = create_all_calculations(creator_function,
46 all_calculation_kwargs = list(all_calculation_kwargs)
47 all_queues = list(all_queues)
48 every_parameter_combination = list(every_parameter_combination)
50 self.assertEqual(len(all_calculation_kwargs), 4)
51 self.assertEqual(len(all_queues), 4)
52 self.assertEqual(len(every_parameter_combination), 4)
54 self.assertIn({
"x": 1,
"y": 3}, every_parameter_combination)
55 self.assertIn({
"x": 1,
"y": 4}, every_parameter_combination)
56 self.assertIn({
"x": 2,
"y": 3}, every_parameter_combination)
57 self.assertIn({
"x": 2,
"y": 4}, every_parameter_combination)
59 for combination
in [{
"x": 1,
"y": 3}, {
"x": 1,
"y": 4}, {
"x": 2,
"y": 3}, {
"x": 2,
"y": 4}]:
60 index = every_parameter_combination.index(combination)
63 self.assertEqual(all_calculation_kwargs[index], {
"a": 2 * x,
"b": y + 1})
65 def test_create_all_calculations_queue(self):
66 def creator_function(x, y, queue):
67 return {
"a": 2 * x,
"b": y + 1,
"queue": queue}
69 all_calculation_kwargs, all_queues, every_parameter_combination = create_all_calculations(creator_function,
72 all_calculation_kwargs = list(all_calculation_kwargs)
73 all_queues = list(all_queues)
74 every_parameter_combination = list(every_parameter_combination)
76 self.assertEqual(len(all_calculation_kwargs), 4)
77 self.assertEqual(len(all_queues), 4)
78 self.assertEqual(len(every_parameter_combination), 4)
80 self.assertIn({
"x": 1,
"y": 3}, every_parameter_combination)
81 self.assertIn({
"x": 1,
"y": 4}, every_parameter_combination)
82 self.assertIn({
"x": 2,
"y": 3}, every_parameter_combination)
83 self.assertIn({
"x": 2,
"y": 4}, every_parameter_combination)
85 for combination
in [{
"x": 1,
"y": 3}, {
"x": 1,
"y": 4}, {
"x": 2,
"y": 3}, {
"x": 2,
"y": 4}]:
86 index = every_parameter_combination.index(combination)
89 self.assertEqual(all_calculation_kwargs[index], {
"a": 2 * x,
"b": y + 1,
"queue": all_queues[index]})
91 def test_create_all_calculations_none(self):
92 def creator_function(x, y):
95 return {
"a": 2 * x,
"b": y + 1}
97 all_calculation_kwargs, all_queues, every_parameter_combination = create_all_calculations(creator_function,
99 all_calculation_kwargs = list(all_calculation_kwargs)
100 all_queues = list(all_queues)
101 every_parameter_combination = list(every_parameter_combination)
103 self.assertEqual(len(all_calculation_kwargs), 4)
104 self.assertEqual(len(all_queues), 4)
105 self.assertEqual(len(every_parameter_combination), 4)
107 self.assertIn({
"a": 2,
"b": 4}, all_calculation_kwargs)
108 self.assertIn({
"a": 2,
"b": 5}, all_calculation_kwargs)
109 self.assertNotIn({
"a": 4,
"b": 4}, all_calculation_kwargs)
110 self.assertNotIn({
"a": 4,
"b": 5}, all_calculation_kwargs)
112 for combination
in [{
"x": 1,
"y": 3}, {
"x": 1,
"y": 4}, {
"x": 2,
"y": 3}, {
"x": 2,
"y": 4}]:
113 index = every_parameter_combination.index(combination)
118 self.assertEqual(all_calculation_kwargs[index], {
"a": 2 * x,
"b": y + 1})
120 self.assertEqual(all_calculation_kwargs[index],
None)
123if __name__ ==
"__main__":