Projet

Général

Profil

0001-workflows-add-details-to-workflow-action-__repr__-ou.patch

Frédéric Péters, 14 novembre 2021 15:09

Télécharger (3,38 ko)

Voir les différences:

Subject: [PATCH] workflows: add details to workflow action __repr__ output
 (#20849)

 tests/workflow/test_all.py | 28 ++++++++++++++++++++++++++++
 wcs/workflows.py           | 18 +++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)
tests/workflow/test_all.py
165 165
    assert root['statuses'][1]['endpoint'] is True
166 166

  
167 167

  
168
def test_action_repr(pub):
169
    workflow = Workflow(name='wftest')
170
    st1 = workflow.add_status('Status1', 'st1')
171
    jump = JumpWorkflowStatusItem()
172
    assert repr(jump)  # no crash when not attached to status
173
    jump.id = '_jump'
174
    jump.by = ['_submitter', '_receiver']
175
    jump.timeout = 0.1
176
    jump.status = 'st2'
177
    st1.items.append(jump)
178
    jump.parent = st1
179

  
180
    action = workflow.add_global_action('Timeout')
181
    criticality = action.append_item('modify_criticality')
182
    workflow.store()
183
    with open(workflow.get_object_filename(), 'rb') as fd:
184
        # make sure parent relations are not stored in pickles
185
        assert b'parent' not in fd.read()
186

  
187
    for wf in (workflow, Workflow.get(workflow.id)):
188
        action = wf.possible_status[0].items[0]
189
        assert 'Status1' in repr(action)
190
        assert 'wftest' in repr(action)
191
        action = wf.global_actions[0].items[0]
192
        assert 'Timeout' in repr(criticality)
193
        assert 'wftest' in repr(criticality)
194

  
195

  
168 196
def test_variable_compute(pub):
169 197
    FormDef.wipe()
170 198
    formdef = FormDef()
wcs/workflows.py
1654 1654
        self.name = name
1655 1655
        self.items = []
1656 1656

  
1657
    def __getstate__(self):
1658
        odict = self.__dict__.copy()
1659
        if 'parent' in odict:
1660
            del odict['parent']
1661
        return odict
1662

  
1657 1663
    def append_item(self, type):
1658 1664
        for klass in item_classes:
1659 1665
            if klass.key == type:
......
1662 1668
                    o.id = str(max(lax_int(x.id) for x in self.items) + 1)
1663 1669
                else:
1664 1670
                    o.id = '1'
1671
                o.parent = self
1665 1672
                self.items.append(o)
1666 1673
                return o
1667 1674
        raise KeyError()
......
2586 2593
            yield upload
2587 2594

  
2588 2595
    def __repr__(self):
2589
        return '<%s %s>' % (self.__class__.__name__, self.id)
2596
        parent = getattr(self, 'parent', None)  # status or global action
2597
        parts = [self.__class__.__name__, str(self.id)]
2598
        if isinstance(parent, WorkflowGlobalAction):
2599
            parts.append('in global action "%s" (%s)' % (parent.name, parent.id))
2600
        elif isinstance(parent, WorkflowStatus):
2601
            parts.append('in status "%s" (%s)' % (parent.name, parent.id))
2602
        workflow = getattr(parent, 'parent', None)
2603
        if workflow:
2604
            parts.append('in workflow "%s" (%s)' % (workflow.name, workflow.id))
2605
        return '<%s>' % ' '.join(parts)
2590 2606

  
2591 2607

  
2592 2608
class WorkflowStatusJumpItem(WorkflowStatusItem):
2593
-