ATLAS Offline Software
Loading...
Searching...
No Matches
python.coverage Namespace Reference

Classes

class  Coverage

Functions

 _find_LINENO_from_code_22 (code)
 _find_LINENO_from_code_23 (code)
 _find_LINENO (code)
 find_executable_linenos (filename)

Variables

int running_coverage = 0
 _find_LINENO_from_code = _find_LINENO_from_code_22

Function Documentation

◆ _find_LINENO()

python.coverage._find_LINENO ( code)
protected
return all of the SET_LINENO information from a code object

Definition at line 112 of file coverage.py.

112def _find_LINENO(code):
113 """return all of the SET_LINENO information from a code object"""
114 import types
115
116 # get all of the lineno information from the code of this scope level
117 #linenos = _find_LINENO_from_string(code.co_code)
118 linenos = _find_LINENO_from_code(code)
119
120 # and check the constants for references to other code objects
121 for c in code.co_consts:
122 if isinstance(c, types.CodeType):
123 # find another code object, so recurse into it
124 linenos.update(_find_LINENO(c))
125 return linenos
126

◆ _find_LINENO_from_code_22()

python.coverage._find_LINENO_from_code_22 ( code)
protected
return all of the SET_LINENO information from a code block

Definition at line 70 of file coverage.py.

70def _find_LINENO_from_code_22(code):
71 """return all of the SET_LINENO information from a code block"""
72 co_code = code.co_code
73 linenos = {}
74
75 # This code was filched from the `dis' module then modified
76 n = len(co_code)
77 i = 0
78 prev_op = None
79 prev_lineno = 0
80 while i < n:
81 c = co_code[i]
82 op = ord(c)
83 if op == dis.SET_LINENO:
84 if prev_op == op:
85 # two SET_LINENO in a row, so the previous didn't
86 # indicate anything. This occurs with triple
87 # quoted strings (?). Remove the old one.
88 del linenos[prev_lineno]
89 prev_lineno = ord(co_code[i+1]) + ord(co_code[i+2])*256
90 linenos[prev_lineno] = 1
91 if op >= dis.HAVE_ARGUMENT:
92 i = i + 3
93 else:
94 i = i + 1
95 prev_op = op
96 return linenos
97
98
99# This works from python 2.3 on.

◆ _find_LINENO_from_code_23()

python.coverage._find_LINENO_from_code_23 ( code)
protected

Definition at line 100 of file coverage.py.

100def _find_LINENO_from_code_23 (code):
101 linenos = {}
102 for (o, l) in dis.findlinestarts (code):
103 linenos[l] = 1
104 return linenos
105
106# Choose the appropriate version.

◆ find_executable_linenos()

python.coverage.find_executable_linenos ( filename)
return a dict of the line numbers from executable statements in a file

Works by finding all of the code-like objects in the module then searching
the byte code for 'SET_LINENO' terms (so this won't work one -O files).

Definition at line 127 of file coverage.py.

127def find_executable_linenos(filename):
128 """return a dict of the line numbers from executable statements in a file
129
130 Works by finding all of the code-like objects in the module then searching
131 the byte code for 'SET_LINENO' terms (so this won't work one -O files).
132
133 """
134
135 prog = open(filename).read()
136 code = compile (prog, filename, 'exec')
137
138 # The only way I know to find line numbers is to look for the
139 # SET_LINENO instructions. Isn't there some way to get it from
140 # the AST?
141
142 return _find_LINENO(code)
143
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)

Variable Documentation

◆ _find_LINENO_from_code

python.coverage._find_LINENO_from_code = _find_LINENO_from_code_22
protected

Definition at line 108 of file coverage.py.

◆ running_coverage

int python.coverage.running_coverage = 0

Definition at line 65 of file coverage.py.