def setUp(self): """Set up test case.""" xmlelement = ET.fromstring(procdsc) self.root = Process('', xmlelement, 'fake-id', Context()) self.root.state = 'active' self.ch = Mock()
def __init__(self, parent_id, element, fei, context): """Constructor.""" self.fe_name = self.__class__.__name__.lower() LOG.debug("Creating %s", self.fe_name) self.state = 'ready' self.id = fei self.parent_id = parent_id self.children = [] self.faults = None if self.is_ctx_allowed: self.context = Context(context) else: self.context = context el_index = 0 for child in element: if child.tag in self.allowed_child_types: fexpr = _create_fe_from_element(self.id, child, "%s_%d" % (fei, el_index), self.context) self.children.append(fexpr) el_index = el_index + 1 else: self._parse_non_child(child)
def setUp(self): """Set up SUT.""" xml_element = ET.fromstring(procdsc) self.procexpr = Process('', xml_element, 'fake-id', Context()) self.seqexpr = self.procexpr.children[0] self.whileexpr = self.seqexpr.children[0] self.allexpr = self.whileexpr.children[1]
def setUp(self): """Set up test case.""" xmlelement = ET.fromstring(procdsc) self.root = Process('', xmlelement, 'fake-id', Context()) self.seq = self.root.children[0] self.faults = self.seq.faults self.ch = Mock()
def setUp(self): """Set up test case.""" self.ch = Mock() self.old_tag2class_map = \ bureaucrat.flowexpression._create_fe_from_element bureaucrat.flowexpression._create_fe_from_element = tag2class_map self.root = ComplexExpression('', ET.fromstring(procdsc), 'fake-id', Context())
def test_constructor_no_children(self): """Test FlowExpression.__init__() for simple expression.""" def fake_iterator(parent): while False: yield None self.xml_element.__iter__ = fake_iterator fexpr = FlowExpression('fake-id', self.xml_element, 'fake-id_0', Context()) self.assertTrue(fexpr.id == 'fake-id_0')
def restart(): self.context = Context(self._parent_ctx) for child in self._element: if child.tag == 'context': self.context.parse(child) break self.reset_children() channel.send( Message(name='start', target=self.children[0].id, origin=self.id))
def test_constructor(self): """Test FlowExpression.__init__() for complex expression.""" self.xml_element.__iter__ = fake_et_iterator self.xml_element.tag = 'complexexpression' with patch('bureaucrat.flowexpression._create_fe_from_element') as t2cmap: t2cmap = tag2class_map fexpr = ComplexExpression('fake-id', self.xml_element, 'fake-id_0', Context()) self.assertTrue(fexpr.id == 'fake-id_0') self.assertTrue(len(fexpr.children) == 1)
def load(process_id): """Return existing workflow instance loaded from storage.""" LOG.debug("Load a process definition from %s", process_id) storage = Storage.instance() pdef = storage.load("definition", process_id) xmlelement = ET.fromstring(pdef) assert xmlelement.tag == 'process' parent_id = '' if "parent" in xmlelement.attrib: parent_id = xmlelement.attrib["parent"] process = Process(parent_id, xmlelement, process_id, Context()) process.reset_state(json.loads(storage.load("process", process.id))) return Workflow(process)
def restart(): iteration = self.context.get('inst:iteration') selection = self.context.get('inst:selection') self.context = Context(self._parent_ctx) for child in self._element: if child.tag == 'context': self.context.parse(child) break self.reset_children() self.context.set('inst:iteration', iteration + 1) self.context.set('inst:current', selection[iteration]) self.context.set('inst:selection', selection) channel.send( Message(name='start', target=self.children[0].id, origin=self.id))
def create_from_string(pdef, pid): """Create Workflow instance from process definition string.""" LOG.debug("Creating workflow instance from string.") xmlelement = ET.fromstring(pdef) assert xmlelement.tag == 'process' Storage.instance().save("definition", pid, pdef) parent_id = '' if "parent" in xmlelement.attrib: parent_id = xmlelement.attrib["parent"] process = Process(parent_id, xmlelement, pid, Context()) workflow = Workflow(process) workflow.save() return workflow
def setUp(self): xml_element = ET.fromstring(self.processdsc) self.fexpr = While('fake-id', xml_element, 'fake-id_0', Context()) self.ch = Mock()
def setUp(self): xml_element = ET.fromstring(processdsc) self.fexpr = Process('', xml_element, 'fake-id', Context()) self.ch = Mock()
def setUp(self): xml_element = ET.fromstring(processdsc) self.fexpr = All('fake-id', xml_element, 'fake-id_0', Context()) self.ch = Mock() self.ch.send = Mock()
def setUp(self): """Set up SUT.""" xml_element = ET.fromstring(processdsc) self.fexpr = Delay('fake-id', xml_element, 'fake-id_0', Context()) self.ch = Mock()