Esempio n. 1
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
Esempio n. 2
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'])
Esempio n. 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
Esempio n. 4
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)
Esempio n. 5
0
 def _makeAnd(self, *conditions):
     node = self._makeNode(ast.And(), conditions)
     return LogicalAnd('somemodule', '3.1', node, {})
Esempio n. 6
0
 def decode_LogicalAnd(self, d):
     and_ = LogicalAnd(d['modulename'], d['label'],
                       self.decode_Node(d['node']), [])
     and_.conditions = self.decode_conditions(d['conditions'])
     return and_
 def test_constructor(self):
     assert LogicalAnd(self.modulename, self.label, self.node, set())
 def _makeOne(self):
     return LogicalAnd(self.modulename, self.label, self.node, set())