Beispiel #1
0
    def test_luid(self, mocked_init):

        s = Stage()
        s._p_pipeline = {'uid': 'pipe.0000', 'name': None}
        s._uid = 'stage.0000'
        s._name = None

        self.assertEqual(s.luid, 'pipe.0000.stage.0000')

        s = Stage()
        s._p_pipeline = {'uid': 'pipe.0000', 'name': 'test_pipe'}
        s._uid = 'stage.0000'
        s._name = None

        self.assertEqual(s.luid, 'test_pipe.stage.0000')

        s = Stage()
        s._p_pipeline = {'uid': 'pipe.0000', 'name': None}
        s._uid = 'stage.0000'
        s._name = 'test_stage'

        self.assertEqual(s.luid, 'pipe.0000.test_stage')

        s = Stage()
        s._p_pipeline = {'uid': 'pipe.0000', 'name': 'test_pipe'}
        s._uid = 'stage.0000'
        s._name = 'test_stage'

        self.assertEqual(s.luid, 'test_pipe.test_stage')
Beispiel #2
0
    def test_stage_task_addition(self, mocked_init):

        s = Stage()
        s._p_pipeline = {'uid': None, 'name': None}
        s._uid = 'stage.0000'
        s._name = None
        s._tasks = set()
        t1 = mock.MagicMock(spec=Task)
        t2 = mock.MagicMock(spec=Task)
        s.add_tasks(set([t1, t2]))

        self.assertIsInstance(s.tasks, set)
        self.assertEqual(s._task_count, 2)
        self.assertIn(t1, s.tasks)
        self.assertIn(t2, s.tasks)

        s = Stage()
        s._uid = 'stage.0000'
        s._name = None
        s._p_pipeline = {'uid': None, 'name': None}
        s._tasks = set()
        t1 = mock.MagicMock(spec=Task)
        t2 = mock.MagicMock(spec=Task)
        s.add_tasks([t1, t2])

        self.assertIsInstance(s.tasks, set)
        self.assertEqual(s._task_count, 2)
        self.assertIn(t1, s.tasks)
        self.assertIn(t2, s.tasks)
Beispiel #3
0
    def test_stage_state_assignment(self, mocked_init, t, l, i, b):

        s = Stage()
        s._uid = 'test_stage'

        data_type = [l, i, b]

        for data in data_type:
            with self.assertRaises(TypeError):
                s.state = data

        if isinstance(t, str):
            with self.assertRaises(ValueError):
                s.state = t

        s = Stage()
        s._uid = 'test_stage'
        s._state = None
        s._state_history = list()
        state_history = list()
        states_list = list(states._stage_state_values.keys())
        shuffle(states_list)
        for val in states_list:
            s.state = val
            if val != states.SUSPENDED:
                state_history.append(val)
            self.assertEqual(s._state, val)
            self.assertEqual(s._state_history, state_history)
Beispiel #4
0
    def test_stage_from_dict(self, mocked_init):

        d = {
            'uid': 're.Stage.0000',
            'name': 's1',
            'state': states.DONE,
            'state_history': [states.INITIAL, states.DONE],
            'parent_pipeline': {
                'uid': 'p1',
                'name': 'pipe1'
            }
        }

        s = Stage()
        s._uid = None
        s._name = None
        s._state = None
        s._state_history = None
        s._p_pipeline = None
        s.from_dict(d)

        self.assertEqual(s._uid, d['uid'])
        self.assertEqual(s._name, d['name'])
        self.assertEqual(s._state, d['state'])
        self.assertEqual(s._state_history, d['state_history'])
        self.assertEqual(s._p_pipeline, d['parent_pipeline'])
Beispiel #5
0
    def test_stage_check_complete(self, mocked_init):

        s = Stage()
        s._uid = 'stage.0000'
        t1 = mock.MagicMock(spec=Task)
        t2 = mock.MagicMock(spec=Task)
        s._tasks = set([t1, t2])

        self.assertFalse(s._check_stage_complete())
        for t in s._tasks:
            t.state = states.DONE
        self.assertTrue(s._check_stage_complete())
Beispiel #6
0
    def test_stage_validate(self, mocked_init):

        s = Stage()
        s._uid = 'stage.0000'
        s._state = 'test'
        with self.assertRaises(ValueError):
            s._validate()

        s = Stage()
        s._uid = 'stage.0000'
        s._state = states.INITIAL
        s._tasks = None
        with self.assertRaises(MissingError):
            s._validate()

        s = Stage()
        s._uid = 'stage.0000'
        t = mock.MagicMock(spec=Stage)
        t._validate = mock.MagicMock(return_value=True)
        s._tasks = set([t])
        s._state = states.INITIAL
        s._validate()
Beispiel #7
0
    def test_stage_set_tasks_state(self, mocked_init):

        s = Stage()
        s._uid = 'stage.0000'
        t1 = mock.MagicMock(spec=Task)
        t2 = mock.MagicMock(spec=Task)
        s._tasks = set([t1, t2])

        with self.assertRaises(ValueError):
            s._set_tasks_state(2)

        s._set_tasks_state(states.DONE)
        self.assertEqual(t1.state, states.DONE)
        self.assertEqual(t2.state, states.DONE)
Beispiel #8
0
    def test_stage_to_dict(self, mocked_init):

        s = Stage()
        s._uid = 'stage.0000'
        s._name = 'test_stage'
        s._state = states.INITIAL
        s._state_history = [states.INITIAL]
        s._p_pipeline = {'uid': 'pipeline.0000', 'name': 'parent'}

        self.assertEqual(
            s.to_dict(), {
                'uid': 'stage.0000',
                'name': 'test_stage',
                'state': states.INITIAL,
                'state_history': [states.INITIAL],
                'parent_pipeline': {
                    'uid': 'pipeline.0000',
                    'name': 'parent'
                }
            })
def test_stage_pass_uid():

    s = Stage()
    s._uid = 's'
    s.name = 's1'
    s.parent_pipeline['uid'] = 'p'
    s.parent_pipeline['name'] = 'p1'

    t1 = Task()
    t2 = Task()
    s.add_tasks([t1,t2])

    s._pass_uid()

    assert t1.parent_stage['uid'] == s.uid
    assert t1.parent_stage['name'] == s.name
    assert t1.parent_pipeline['uid'] == s.parent_pipeline['uid']
    assert t1.parent_pipeline['name'] == s.parent_pipeline['name']

    assert t2.parent_stage['uid'] == s.uid
    assert t2.parent_stage['name'] == s.name
    assert t2.parent_pipeline['uid'] == s.parent_pipeline['uid']
    assert t2.parent_pipeline['name'] == s.parent_pipeline['name']
Beispiel #10
0
def test_stage_pass_uid():

    s = Stage()
    s._uid = 's'
    s.name = 's1'
    s.parent_pipeline['uid'] = 'p'
    s.parent_pipeline['name'] = 'p1'

    t1 = Task()
    t2 = Task()
    s.add_tasks([t1, t2])

    s._pass_uid()

    assert t1.parent_stage['uid'] == s.uid
    assert t1.parent_stage['name'] == s.name
    assert t1.parent_pipeline['uid'] == s.parent_pipeline['uid']
    assert t1.parent_pipeline['name'] == s.parent_pipeline['name']

    assert t2.parent_stage['uid'] == s.uid
    assert t2.parent_stage['name'] == s.name
    assert t2.parent_pipeline['uid'] == s.parent_pipeline['uid']
    assert t2.parent_pipeline['name'] == s.parent_pipeline['name']
Beispiel #11
0
    def test_stage_post_exec_assignment(self, mocked_init, l, d):

        s = Stage()
        s._uid = 'test_stage'

        def func():
            return True

        with self.assertRaises(TypeError):
            s.post_exec = l

        with self.assertRaises(TypeError):
            s.post_exec = d

        s.post_exec = func
        self.assertEqual(s._post_exec, func)

        class Tmp(object):
            def func(self):
                return True

        tmp = Tmp()
        s.post_exec = tmp.func
        self.assertEqual(s._post_exec, tmp.func)
Beispiel #12
0
    def test_stage_assign_uid(self, mocked_init):

        s = Stage()
        s._uid = 'stage.0000'
        self.assertEqual(s.uid, 'stage.0000')