コード例 #1
0
ファイル: test_patterns.py プロジェクト: walkinreeds/workflow
    def test_IF_ELSE03(self):
        we = GenericWorkflowEngine()
        doc = self.getDoc()

        doc[3].append('4')

        def test(v):
            return lambda o, e: v in o

        we.setWorkflow([
            i('add'),
            cf.IF_ELSE(test('three'), [
                a('xxx'),
                cf.IF_ELSE(test('xxx'), [
                    a('6'),
                    cf.IF_ELSE(test('6'), a('six'), (a('only-3s'), a('error')))
                ], a('ok'))
            ], [
                cf.IF_ELSE(
                    test('4'),
                    cf.IF_ELSE(test('four'), [a('44'), [[[a('forty')]]]],
                               a('error')), a('not-four'))
            ]),
            a('end'),
            cf.IF_ELSE(test('error'), a('gosh!'), a('OK'))
        ])
        we.process(doc)

        r = [' '.join(doc[x]) for x in range(len(doc))]

        assert r[0] == 'add one not-four end OK'
        assert r[1] == 'add two not-four end OK'
        assert r[2] == 'add three xxx 6 six end OK'
        assert r[3] == 'add four 4 44 forty end OK'
        assert r[4] == 'add five not-four end OK'
コード例 #2
0
ファイル: test_patterns.py プロジェクト: walkinreeds/workflow
    def test_IF_ELSE02(self):
        we = GenericWorkflowEngine()
        doc = self.getDoc()

        we.setWorkflow([
            i('add'),
            cf.IF_ELSE(lambda o, e: o[1] == 'three', a('3'), a('other'))
        ])
        we.process(doc)

        r = [' '.join(doc[x]) for x in range(len(doc))]

        assert r[0] == 'add one other'
        assert r[1] == 'add two other'
        assert r[2] == 'add three 3'
        assert r[3] == 'add four other'
        assert r[4] == 'add five other'