Example #1
0
    def test_clear(self):
        pm = process_manager
        Chain('one', pm)
        Chain('two', pm)
        Chain('three', pm)

        pm.clear()
        self.assertFalse(pm.n_chains == 3, 'Process manager has chains!')
Example #2
0
    def test_adding_links(self):
        chain = Chain('Chain')
        [chain.add(_) for _ in self.links]

        # Assert that forward/insertion order is maintained.
        self.assertEqual(list(chain), self.links, msg='Links order mismatch!')

        # Assert that the reversed order is maintained.
        self.assertEqual(list(reversed(chain)),
                         list(reversed(self.links)),
                         msg='Links reverse order mismatch!')
Example #3
0
    def test_pop_last_link(self):
        chain = Chain('Chain')
        [chain.add(_) for _ in self.links]

        self.assertEqual(chain.pop(last=True),
                         self.links.pop(),
                         msg='Popped linked is not last link!')

        # Assert that the order and number of elements are maintained.
        self.assertEqual(list(chain),
                         self.links,
                         msg='Links order and number mismatch!')
Example #4
0
    def test_initialize(self):
        pm = process_manager
        one = Chain('1', pm)
        two = Chain('2', pm)
        three = Chain('3', pm)

        status = pm.initialize()

        self.assertEqual(one.prev_chain_name, '')
        self.assertEqual(two.prev_chain_name, '1')
        self.assertEqual(three.prev_chain_name, '2')
        self.assertTrue(status == StatusCode.Success,
                        'Process Manager failed to initialize!')
Example #5
0
    def test_chain(self):
        pm = process_manager
        c = 'dummy'

        with self.assertRaises(TypeError):
            pm.add(c)

        chain = Chain(c, pm)
        with self.assertRaises(KeyError):
            pm.add(chain)
Example #6
0
    def add(self, chain: Chain) -> None:
        """Add a chain to the process manager.

        :param chain: The chain to add to the process manager.
        :type chain: Chain
        :raise TypeError: When the chain is of an incompatible type.
        :raise KeyError: When a chain of the same type and name already exists.
        """
        if not issubclass(type(chain), Chain):
            raise TypeError('Expected (sub-class of) "Chain" and not "{wrong!s}"!'.format(wrong=type(chain)))

        self.logger.debug('Registering chain "{chain}."', chain=chain)

        chain.parent = self
        super().add(chain)
Example #7
0
    def test_execute_status_return(self):
        pm = process_manager
        pm.service(ConfigObject)['analysisName'] = 'test_execute_status_return'

        class Success(Link):
            chains = []

            def execute(self):
                self.chains.append(self.parent.name)
                return StatusCode.Success

        c1 = Chain('1', pm)
        c1.add(Success('1'))
        c2 = Chain('2', pm)
        c2.add(Success('2'))
        c3 = Chain('fail', pm)

        class Fail(Link):
            def execute(self):
                return StatusCode.Failure

        c3.add(Fail('fail'))

        c4 = Chain('4', pm)
        c4.add(Success('4'))

        status = pm.execute()

        self.assertEqual(status, StatusCode.Failure,
                         'Process Manager failed to fail!')
        self.assertEqual(Success.chains, ['1', '2'])

        pm.reset()

        pm.service(
            ConfigObject)['analysisName'] = 'test_execute_all_status_return'

        Success.chains = list()

        c1 = Chain('1', pm)
        c1.add(Success('1'))
        c2 = Chain('2', pm)
        c2.add(Success('2'))
        c3 = Chain('skip')

        class Skip(Link):
            def execute(self):
                return StatusCode.SkipChain

        c3.add(Skip('skip'))

        c4 = Chain('4', pm)
        c4.add(Success('4'))

        status = pm.execute()

        self.assertEqual(status, StatusCode.Success)
        self.assertEqual(Success.chains, ['1', '2', '4'])
Example #8
0
 def test_reset(self):
     pm = process_manager
     Chain('dummy', pm)
     self.assertTrue(pm, 'Process manager has no chains!')
     pm.reset()
     self.assertFalse(pm, 'Process manager has chains!')
Example #9
0
 def test_discard(self):
     pm = process_manager
     one = Chain('one', pm)
     self.assertTrue(pm.n_chains == 1, 'Process manager has no chains!')
     pm.discard(one)
     self.assertTrue(pm.n_chains == 0, 'Process manager has chains!')