Exemple #1
0
 def test_has(self):
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             )
     assert cs.count == 1
     assert cs.has_task('a')
     assert not cs.has_task('foo')
Exemple #2
0
    def dp_init_sequence(self) -> CallSequence:
        """Debug Port init sequence modification function.

        This function allows miss the Connect action for J-LINK probes, because the J-Link DLL
        do some additional unwanted actions that are not welcomed by DAT.

        :return: Debug Port initialization call sequence
        :raises SPSDKDebugProbeNotOpenError: The PyOCD probe is NOT opened
        """
        if self.pyocd_session is None:
            raise SPSDKDebugProbeNotOpenError(
                "The PyOCD debug probe is not opened yet")

        debug_probe = self.pyocd_session.target.dp
        probe = debug_probe.probe

        if isinstance(probe, JLinkProbe):
            return CallSequence(
                ("get_probe_capabilities",
                 debug_probe._get_probe_capabilities),
                ("connect", self._connect_jlink),
                ("clear_sticky_err", debug_probe.clear_sticky_err),
                ("power_up_debug", debug_probe.power_up_debug),
                ("check_version", debug_probe._check_version),
            )

        return CallSequence(
            ("get_probe_capabilities", debug_probe._get_probe_capabilities),
            ("connect", debug_probe._connect),
            ("clear_sticky_err", debug_probe.clear_sticky_err),
            ("power_up_debug", debug_probe.power_up_debug),
            ("check_version", debug_probe._check_version),
        )
Exemple #3
0
 def test_clear(self):
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', lambda : results.append('b ran')),
             )
     assert cs.count == 2
     cs.clear()
     assert cs.count == 0
Exemple #4
0
 def test_a(self):
     results = []
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', lambda : results.append('b ran')),
             )
     assert cs.count == 2
     cs.invoke()
     assert results == ['a ran', 'b ran']
Exemple #5
0
 def test_replace(self):
     results = []
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', lambda : results.append('b ran')),
             )
     assert cs.count == 2
     cs.replace_task('b', lambda : results.append('wheee'))
     cs()
     assert results == ['a ran', 'wheee']
Exemple #6
0
 def test_get(self):
     results = []
     def task_a():
         results.append('a ran')
     cs = CallSequence(
             ('a', task_a),
             )
     assert cs.count == 1
     assert cs.get_task('a') == task_a
     with pytest.raises(KeyError):
         cs.get_task('foo')
Exemple #7
0
 def test_insert_after_2(self):
     results = []
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', lambda : results.append('b ran')),
             )
     assert cs.count == 2
     cs.insert_after('a', ('c', lambda : results.append('c ran')))
     assert cs.count == 3
     cs()
     assert results == ['a ran', 'c ran', 'b ran']
Exemple #8
0
 def test_insert_before_3(self):
     results = []
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', lambda : results.append('b ran')),
             )
     assert cs.count == 2
     cs.insert_before('a', ('c', lambda : results.append('c ran')),
                           ('d', lambda : results.append('d ran')))
     assert cs.count == 4
     cs()
     assert results == ['c ran', 'd ran', 'a ran', 'b ran']
Exemple #9
0
 def test_wrap(self):
     results = []
     def task_b():
         results.append('b ran')
         return "task b result"
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', task_b),
             )
     assert cs.count == 2
     def wrapper(t):
         assert t == "task b result"
         results.append('wrapper ran')
     cs.wrap_task('b', wrapper)
     cs()
     assert results == ['a ran', 'b ran', 'wrapper ran']
Exemple #10
0
 def discover(self) -> CallSequence:
     """Setup list of calls to perform the components discovery."""
     #pylint: disable=bad-whitespace
     return CallSequence(('find_aps', self._find_aps),
                         ('create_aps', self._create_aps),
                         ('find_components', self._find_components),
                         ('create_cores', self._create_cores))
Exemple #11
0
 def discover(self) -> CallSequence:
     """Setup list of calls to perform the components discovery."""
     return CallSequence(
         ("find_aps", self._find_aps),
         ("create_aps", self._create_aps),
         ("find_components", self._find_components),
         ("create_cores", self._create_cores),
     )
Exemple #12
0
 def task_b():
     results.append('b ran')
     cs2 = CallSequence(
             ('x', lambda : results.append('x ran')),
             ('y', lambda : results.append('y ran')),
             )
     assert cs2.count == 2
     return cs2
Exemple #13
0
 def test_iter(self):
     results = []
     def task_a():
         results.append('a ran')
     def task_b():
         results.append('b ran')
     cs = CallSequence(
             ('a', task_a),
             ('b', task_b),
             )
     assert cs.count == 2
     it = iter(cs)
     print("it=",repr(it),dir(it))
     assert six.next(it) == ('a', task_a)
     assert six.next(it) == ('b', task_b)
     with pytest.raises(StopIteration):
         six.next(it)
Exemple #14
0
 def test_returned_seq(self):
     results = []
     def task_b():
         results.append('b ran')
         cs2 = CallSequence(
                 ('x', lambda : results.append('x ran')),
                 ('y', lambda : results.append('y ran')),
                 )
         assert cs2.count == 2
         return cs2
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', task_b),
             ('c', lambda : results.append('c ran')),
             )
     assert cs.count == 3
     cs()
     assert results == ['a ran', 'b ran', 'x ran', 'y ran', 'c ran']
Exemple #15
0
 def test_remove_1(self):
     results = []
     cs = CallSequence(
             ('a', lambda : results.append('a ran')),
             ('b', lambda : results.append('b ran')),
             )
     assert cs.count == 2
     
     cs.remove_task('b')
     assert cs.count == 1
     
     cs.invoke()
     assert results == ['a ran']
Exemple #16
0
 def test_insert_after_4(self):
     cs = CallSequence()
     with pytest.raises(KeyError):
         cs.insert_after('z', ('c', lambda : results.append('c ran')))
Exemple #17
0
 def discover(self) -> CallSequence:
     """Setup list of calls to perform the components discovery."""
     return CallSequence(
         ("find_root_components", self._find_root_components), )
Exemple #18
0
 def test_empty(self):
     cs = CallSequence()
     assert cs.count == 0