示例#1
0
    def test_make_context(self):
        from screp.anchor import Anchor
        from screp.term import Term
        from screp.termactions import (
                AnchorTermAction,
                GenericTermAction,
                )

        factory = self.make_factory([('a1', 't1')])

        factory.add_anchor(Anchor('a2', Term([
            AnchorTermAction('a1', 't1'),
            GenericTermAction(lambda x: x + 'b', in_type='t1', out_type='t2'),
            ])))

        factory.add_anchor(Anchor('a1', Term([
            AnchorTermAction('a1', 't1'),
            GenericTermAction(lambda x: x + 'c', in_type='t1', out_type='t3'),
            GenericTermAction(lambda x: x + 'd', in_type='t3', out_type='t4'),
            ])))

        factory.add_anchor(Anchor('a3', Term([
            AnchorTermAction('a1', 't4'),
            GenericTermAction(lambda x: x + 'e', in_type='t4', out_type='t5'),
            ])))

        context = factory.make_context({'a1': 'a'})

        assert context.get_anchor('a1') == 'acd'

        assert context.get_anchor('a2') == 'ab'

        assert context.get_anchor('a3') == 'acde'
示例#2
0
    def test_add_anchor(self):
        context = self.make_context({'a1': 1, 'a2': 2})

        context.add_anchor('a3', 3)

        assert context.get_anchor('a3') == 3

        assert context.get_anchor('a1') == 1

        context.add_anchor('a1', 4)

        assert context.get_anchor('a1') == 4
示例#3
0
    def test_get_anchor_not_found(self):
        context = self.make_context({'a1': 1, 'a2': 2})

        with pytest.raises(Exception):
            context.get_anchor('a3')
示例#4
0
    def test_get_anchor(self):
        context = self.make_context({'a1': 1, 'a2': 2})

        assert context.get_anchor('a1') == 1

        assert context.get_anchor('a2') == 2