Пример #1
0
 def _makeOneWithLiteral(self,
                         op=ast.Eq(),
                         left=ast.Num(n=4),
                         right=ast.Num(n=4)):
     node = ast.Compare(left=left,
                        ops=[op],
                        comparators=[right],
                        col_offset=12,
                        lineno=3)
     construct = Comparison('somemodule', '3.1', node, {})
     return construct
Пример #2
0
 def test_encode_Comparison(self):
     from instrumental.storage import ObjectEncoder as OE
     node = ast.Compare(left=ast.Name(id='a'),
                        ops=[ast.Eq()],
                        comparators=[ast.Num(n=4)],
                        lineno=4)
     construct = Comparison('somemodule', '4.2', node, [])
     construct.conditions = {False: set(), True: set(['X'])}
     result = OE().encode(construct)
     
     expected = {'__python_class__': 'Comparison',
                 'modulename': 'somemodule',
                 'label': '4.2',
                 'node': {'__python_class__': 'Compare',
                          'left': {'__python_class__': 'Name',
                                   'id': 'a'},
                          'ops': [{'__python_class__': 'Eq'}],
                          'comparators': [{'__python_class__': 'Num',
                                           'n': 4}],
                          'lineno': 4,
                          },
                 'conditions': {0: [], 1: ['X']},
                 }
     
     assert result == expected
Пример #3
0
 def test_IfExp_with_literal_orelse_falsy(self):
     from astkit import ast
     test = ast.Name(id='False')
     body = ast.Name(id='b')
     orelse = ast.Num(n=0)
     node = ast.IfExp(test=test, body=body, orelse=orelse)
     expected = set([False])
     yield self._test_node, node, expected
Пример #4
0
 def test_IfExp_with_literal_body_truthy(self):
     from astkit import ast
     test = ast.Name(id='True')
     body = ast.Num(n=4)
     orelse = ast.Name(id='c')
     node = ast.IfExp(test=test, body=body, orelse=orelse)
     expected = set([True])
     yield self._test_node, node, expected
Пример #5
0
 def get_statement_recorder_call(modulename, lineno):
     kall = ast.Call()
     kall.func = ast.Attribute(value=ast.Name(id="_xxx_recorder_xxx_",
                                              ctx=ast.Load()),
                               attr="record_statement",
                               ctx=ast.Load())
     kall.args = [
         ast.Str(s=modulename),
         ast.Num(n=lineno),
     ]
     kall.keywords = []
     kall_stmt = ast.Expr(value=kall)
     return kall_stmt
Пример #6
0
 def add_BoolOp(self, modulename, label, node, pragmas, parent):
     # Now wrap the individual values in recorder calls
     base_call = self.get_recorder_call()
     base_call.args = \
         [ast.Str(s=modulename, lineno=node.lineno, col_offset=node.col_offset),
          ast.Str(s=label, lineno=node.lineno, col_offset=node.col_offset)]
     for i, value in enumerate(node.values):
         recorder_call = deepcopy(base_call)
         recorder_call.args.insert(0, node.values[i])
         recorder_call.args.append(
             ast.copy_location(ast.Num(n=i), node.values[i]))
         node.values[i] = ast.copy_location(recorder_call, node.values[i])
     ast.fix_missing_locations(node)
     return node
Пример #7
0
 def test_encode_Node_with_list_attribute(self):
     from instrumental.storage import ObjectEncoder as OE
     node = ast.Compare(left=ast.Name(id='a'),
                        ops=[ast.Eq()],
                        comparators=[ast.Num(n=4)])
     result = OE().encode_Node(node)
     
     expected = {'__python_class__': 'Compare',
                 'left': {'__python_class__': 'Name',
                          'id': 'a'},
                 'ops': [{'__python_class__': 'Eq'}],
                 'comparators': [{'__python_class__': 'Num',
                                  'n': 4}],
                 }
     
     assert result == expected, (result, expected)
Пример #8
0
 def test_UnaryOp_UAdd(self):
     from astkit import ast
     node = ast.UnaryOp(op=ast.UAdd(), operand=ast.Num(n=4))
     expected = set([True, False])
     yield self._test_node, node, expected