Пример #1
0
    def test_conditions_are_ignored(self):
        import re
        from astkit import ast
        from instrumental.constructs import LogicalAnd
        from instrumental.pragmas import no_cond
        from instrumental.pragmas import PragmaNoCondition
        node = ast.BoolOp(values=[ast.Name(id="x"),
                                  ast.Name(id="y")],
                          op=ast.And(),
                          lineno=17,
                          col_offset=1)
        match = re.match(no_cond, 'no cond(T F,F *)')
        pragma = PragmaNoCondition(match)
        construct = LogicalAnd('<string>', '17.1', node, set([pragma]))
        assert '(x and y)' == construct.source
        assert 3 == construct.number_of_conditions(False)
        assert "T T" == construct.description(0)
        assert "F *" == construct.description(1)
        assert "T F" == construct.description(2)

        # T T
        construct.record(True, 0, '*')
        construct.record(True, 1, '*')

        assert not construct.conditions_missed(False)
        assert construct.conditions[0] == set(['*'])
        assert construct.conditions[1] == set(['P'])
        assert construct.conditions[2] == set(['P'])
Пример #2
0
 def test_encode_LogicalAnd(self):
     from instrumental.storage import ObjectEncoder as OE
     node = ast.BoolOp(op=ast.And(),
                       values=[ast.Name(id='a'), ast.Name(id='b')],
                       lineno=4)
     construct = LogicalAnd('somemodule', '4.2', node, [])
     construct.conditions = {0: set(), 1: set(['X']), 
                             2: set([UnreachableCondition])}
     result = OE().encode(construct)
     
     expected = {'__python_class__': 'LogicalAnd',
                 'modulename': 'somemodule',
                 'label': '4.2',
                 'node': {'__python_class__': 'BoolOp',
                          'op': {'__python_class__': 'And'},
                          'values': [{'__python_class__': 'Name',
                                      'id': 'a'},
                                     {'__python_class__': 'Name',
                                      'id': 'b'}],
                          'lineno': 4,
                          },
                 'conditions': {0: [], 1: ['X'], 2: ['__unreachable__']},
                 }
     
     assert result == expected
Пример #3
0
 def _makeOne(self, selector='3.1', pragmas=[]):
     node = ast.BoolOp(values=[ast.Name(id='a'),
                               ast.Name(id='b')],
                       op=ast.And(),
                       col_offset=12,
                       lineno=3)
     construct = LogicalAnd('somemodule', selector, node, pragmas)
     return construct
Пример #4
0
 def test_BoolOp_2_pin_and_without_literals(self):
     from astkit import ast
     node = ast.BoolOp(
         op=ast.And(),
         values=[
             ast.Name(id='a'),
             ast.Name(id='b'),
         ],
     )
     expected = set([True, False])
     yield self._test_node, node, expected
Пример #5
0
 def test_BoolOp_3_pin_and_with_1_literal_False(self):
     from astkit import ast
     node = ast.BoolOp(
         op=ast.And(),
         values=[
             ast.Name(id='a'),
             ast.Name(id='False'),
             ast.Name(id='c'),
         ],
     )
     expected = set([False])
     yield self._test_node, node, expected
Пример #6
0
    def test_serialize_BooleanDecision(self):
        from instrumental.constructs import BooleanDecision

        node = ast.BoolOp(op=ast.And(),
                          values=[ast.Name(id="a"),
                                  ast.Name(id="b")],
                          lineno=4)
        construct = BooleanDecision('somemodule', '4.2', node, [])

        serializer = self._makeOne()
        actual = serializer.dump(construct)
        expected = "BooleanDecision|somemodule|4.2|BoolOp'4'And'Name{a}'Name{b}||False:;True:"
        assert actual == expected, (actual, expected)
Пример #7
0
    def test_serialize_LogicalBoolean_And(self):
        from instrumental.constructs import LogicalAnd

        node = ast.BoolOp(op=ast.And(),
                          values=[ast.Name(id="a"),
                                  ast.Name(id="b")],
                          lineno=4)
        construct = LogicalAnd('somemodule', '4.2', node, [])

        serializer = self._makeOne()
        actual = serializer.dump(construct)
        expected = "LogicalAnd|somemodule|4.2|BoolOp'4'And'Name{a}'Name{b}||0:;1:;2:"
        assert actual == expected, (actual, expected)
Пример #8
0
 def _makeAnd(self, *conditions):
     node = self._makeNode(ast.And(), conditions)
     return LogicalAnd('somemodule', '3.1', node, {})