- # def test_Process_steps(self) -> None:
- # """Test addition, nesting, and non-recursion of ProcessSteps"""
- # # pylint: disable=too-many-locals
- # # pylint: disable=too-many-statements
- # p1, p2, p3 = self.three_processes()
- # assert isinstance(p1.id_, int)
- # assert isinstance(p2.id_, int)
- # assert isinstance(p3.id_, int)
- # steps_p1: list[ProcessStep] = []
- # # add step of process p2 as first (top-level) step to p1
- # s_p2_to_p1 = ProcessStep(None, p1.id_, p2.id_, None)
- # steps_p1 += [s_p2_to_p1]
- # p1.set_steps(self.db_conn, steps_p1)
- # p1_dict: dict[int, ProcessStepsNode] = {}
- # p1_dict[1] = ProcessStepsNode(p2, None, True, {})
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # add step of process p3 as second (top-level) step to p1
- # s_p3_to_p1 = ProcessStep(None, p1.id_, p3.id_, None)
- # steps_p1 += [s_p3_to_p1]
- # p1.set_steps(self.db_conn, steps_p1)
- # p1_dict[2] = ProcessStepsNode(p3, None, True, {})
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # add step of process p3 as first (top-level) step to p2,
- # steps_p2: list[ProcessStep] = []
- # s_p3_to_p2 = ProcessStep(None, p2.id_, p3.id_, None)
- # steps_p2 += [s_p3_to_p2]
- # p2.set_steps(self.db_conn, steps_p2)
- # # expect it as implicit sub-step of p1's second (p3) step
- # p2_dict = {3: ProcessStepsNode(p3, None, False, {})}
- # p1_dict[1].steps[3] = p2_dict[3]
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # add step of process p2 as explicit sub-step to p1's second sub-step
- # s_p2_to_p1_first = ProcessStep(None, p1.id_, p2.id_, s_p3_to_p1.id_)
- # steps_p1 += [s_p2_to_p1_first]
- # p1.set_steps(self.db_conn, steps_p1)
- # seen_3 = ProcessStepsNode(p3, None, False, {}, False)
- # p1_dict[1].steps[3].seen = True
- # p1_dict[2].steps[4] = ProcessStepsNode(p2, s_p3_to_p1.id_, True,
- # {3: seen_3})
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # add step of process p3 as explicit sub-step to non-existing p1
- # # sub-step (of id=999), expect it to become another p1 top-level step
- # s_p3_to_p1_999 = ProcessStep(None, p1.id_, p3.id_, 999)
- # steps_p1 += [s_p3_to_p1_999]
- # p1.set_steps(self.db_conn, steps_p1)
- # p1_dict[5] = ProcessStepsNode(p3, None, True, {})
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # add step of process p3 as explicit sub-step to p1's implicit p3
- # # sub-step, expect it to become another p1 top-level step
- # s_p3_to_p1_impl_p3 = ProcessStep(None, p1.id_, p3.id_,
- # s_p3_to_p2.id_)
- # steps_p1 += [s_p3_to_p1_impl_p3]
- # p1.set_steps(self.db_conn, steps_p1)
- # p1_dict[6] = ProcessStepsNode(p3, None, True, {})
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # self.assertEqual(p1.used_as_step_by(self.db_conn), [])
- # self.assertEqual(p2.used_as_step_by(self.db_conn), [p1])
- # self.assertEqual(p3.used_as_step_by(self.db_conn), [p1, p2])
- # # # add step of process p3 as explicit sub-step to p1's first
- # # # sub-step, expect it to eliminate implicit p3 sub-step
- # # s_p3_to_p1_first_explicit = ProcessStep(None, p1.id_, p3.id_,
- # # s_p2_to_p1.id_)
- # # p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {})}
- # # p1_dict[2].steps[4].steps[3].seen = False
- # # steps_p1 += [s_p3_to_p1_first_explicit]
- # # p1.set_steps(self.db_conn, steps_p1)
- # # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # ensure implicit steps non-top explicit steps are shown
- # s_p3_to_p2_first = ProcessStep(None, p2.id_, p3.id_, s_p3_to_p2.id_)
- # steps_p2 += [s_p3_to_p2_first]
- # p2.set_steps(self.db_conn, steps_p2)
- # p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {},
- # True)
- # p1_dict[2].steps[4].steps[3].steps[7] = ProcessStepsNode(
- # p3, 3, False, {}, False)
- # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
- # # ensure suppressed step nodes are hidden
- # assert isinstance(s_p3_to_p2.id_, int)
- # p1.set_step_suppressions(self.db_conn, [s_p3_to_p2.id_])
- # p1_dict[1].steps[3].steps = {}
- # p1_dict[1].steps[3].is_suppressed = True
- # p1_dict[2].steps[4].steps[3].steps = {}
- # p1_dict[2].steps[4].steps[3].is_suppressed = True
- # self.assertEqual(p1.get_steps(self.db_conn), p1_dict)
-
- def test_Process_conditions(self) -> None:
- """Test setting Process.conditions/enables/disables."""
- p = Process(None)
- p.save(self.db_conn)
- targets = ['conditions', 'blockers', 'enables', 'disables']
- for i, target in enumerate(targets):
- c1, c2 = Condition(None), Condition(None)
- c1.save(self.db_conn)
- c2.save(self.db_conn)
- assert isinstance(c1.id_, int)
- assert isinstance(c2.id_, int)
- args: list[list[int]] = [[], [], [], []]
- args[i] = []
- p.set_condition_relations(self.db_conn, *args)
- self.assertEqual(getattr(p, target), [])
- args[i] = [c1.id_]
- p.set_condition_relations(self.db_conn, *args)
- self.assertEqual(getattr(p, target), [c1])
- args[i] = [c2.id_]
- p.set_condition_relations(self.db_conn, *args)
- self.assertEqual(getattr(p, target), [c2])
- args[i] = [c1.id_, c2.id_]
- p.set_condition_relations(self.db_conn, *args)
- self.assertEqual(getattr(p, target), [c1, c2])
+ def test_Process_steps(self) -> None:
+ """Test addition, nesting, and non-recursion of ProcessSteps"""
+ # pylint: disable=too-many-locals
+ # pylint: disable=too-many-statements
+ p1, p2, p3 = self.three_processes()
+ assert isinstance(p1.id_, int)
+ assert isinstance(p2.id_, int)
+ assert isinstance(p3.id_, int)
+ steps_p1: list[ProcessStep] = []
+ # # add step of process p2 as first (top-level) step to p1
+ # s_p2_to_p1 = ProcessStep(None, p1.id_, p2.id_, None)
+ # steps_p1 += [s_p2_to_p1]
+ # p1.set_steps(self.db_conn, steps_p1)
+ # p1_dict: dict[int, ProcessStepsNode] = {}
+ # p1_dict[1] = ProcessStepsNode(p2, None, True, {})
+ # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # # add step of process p3 as second (top-level) step to p1
+ # s_p3_to_p1 = ProcessStep(None, p1.id_, p3.id_, None)
+ # steps_p1 += [s_p3_to_p1]
+ # p1.set_steps(self.db_conn, steps_p1)
+ # p1_dict[2] = ProcessStepsNode(p3, None, True, {})
+ # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # # add step of process p3 as first (top-level) step to p2,
+ # steps_p2: list[ProcessStep] = []
+ # s_p3_to_p2 = ProcessStep(None, p2.id_, p3.id_, None)
+ # steps_p2 += [s_p3_to_p2]
+ # p2.set_steps(self.db_conn, steps_p2)
+ # # expect it as implicit sub-step of p1's second (p3) step
+ # p2_dict = {3: ProcessStepsNode(p3, None, False, {})}
+ # p1_dict[1].steps[3] = p2_dict[3]
+ # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # # add step of process p2 as explicit sub-step to p1's second sub-step
+ # s_p2_to_p1_first = ProcessStep(None, p1.id_, p2.id_, s_p3_to_p1.id_)
+ # steps_p1 += [s_p2_to_p1_first]
+ # p1.set_steps(self.db_conn, steps_p1)
+ # seen_3 = ProcessStepsNode(p3, None, False, {}, False)
+ # p1_dict[1].steps[3].seen = True
+ # p1_dict[2].steps[4] = ProcessStepsNode(p2, s_p3_to_p1.id_, True,
+ # {3: seen_3})
+ # self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+
+ # add step of process p3 as explicit sub-step to non-existing p1
+ # sub-step (of id=999), expect it to become another p1 top-level step
+ s_p3_to_p1_999 = ProcessStep(None, p1.id_, p3.id_, 999)
+ steps_p1 += [s_p3_to_p1_999]
+ p1.set_steps(self.db_conn, steps_p1)
+ p1_dict[5] = ProcessStepsNode(p3, None, True, {})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # add step of process p3 as explicit sub-step to p1's implicit p3
+ # sub-step, expect it to become another p1 top-level step
+ s_p3_to_p1_impl_p3 = ProcessStep(None, p1.id_, p3.id_,
+ s_p3_to_p2.id_)
+ steps_p1 += [s_p3_to_p1_impl_p3]
+ p1.set_steps(self.db_conn, steps_p1)
+ p1_dict[6] = ProcessStepsNode(p3, None, True, {})
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ self.assertEqual(p1.used_as_step_by(self.db_conn), [])
+ self.assertEqual(p2.used_as_step_by(self.db_conn), [p1])
+ self.assertEqual(p3.used_as_step_by(self.db_conn), [p1, p2])
+ # add step of process p3 as explicit sub-step to p1's first
+ # sub-step, expect it to eliminate implicit p3 sub-step
+ s_p3_to_p1_first_explicit = ProcessStep(None, p1.id_, p3.id_,
+ s_p2_to_p1.id_)
+ p1_dict[1].steps = {7: ProcessStepsNode(p3, 1, True, {})}
+ p1_dict[2].steps[4].steps[3].seen = False
+ steps_p1 += [s_p3_to_p1_first_explicit]
+ p1.set_steps(self.db_conn, steps_p1)
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # ensure implicit steps non-top explicit steps are shown
+ s_p3_to_p2_first = ProcessStep(None, p2.id_, p3.id_, s_p3_to_p2.id_)
+ steps_p2 += [s_p3_to_p2_first]
+ p2.set_steps(self.db_conn, steps_p2)
+ p1_dict[1].steps[3].steps[7] = ProcessStepsNode(p3, 3, False, {},
+ True)
+ p1_dict[2].steps[4].steps[3].steps[7] = ProcessStepsNode(
+ p3, 3, False, {}, False)
+ self.assertEqual(p1.get_steps(self.db_conn, None), p1_dict)
+ # ensure suppressed step nodes are hidden
+ assert isinstance(s_p3_to_p2.id_, int)
+ p1.set_step_suppressions(self.db_conn, [s_p3_to_p2.id_])
+ p1_dict[1].steps[3].steps = {}
+ p1_dict[1].steps[3].is_suppressed = True
+ p1_dict[2].steps[4].steps[3].steps = {}
+ p1_dict[2].steps[4].steps[3].is_suppressed = True
+ self.assertEqual(p1.get_steps(self.db_conn), p1_dict)