Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
d5f4a5a4
Commit
d5f4a5a4
authored
Oct 01, 2017
by
scoder
Committed by
GitHub
Oct 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1900 from MaxBo/MaxBo-patch-1
Update Coverage.py
parents
19f9dbbb
4ef6bb83
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
12 deletions
+74
-12
Cython/Coverage.py
Cython/Coverage.py
+5
-4
tests/run/coverage_api.srctree
tests/run/coverage_api.srctree
+68
-7
tests/run/coverage_cmd.srctree
tests/run/coverage_cmd.srctree
+1
-1
No files found.
Cython/Coverage.py
View file @
d5f4a5a4
...
...
@@ -12,6 +12,7 @@ import sys
from
collections
import
defaultdict
from
coverage.plugin
import
CoveragePlugin
,
FileTracer
,
FileReporter
# requires coverage.py 4.0+
from
coverage.files
import
canonical_filename
from
.Utils
import
find_root_package_dir
,
is_package_dir
,
open_source_file
...
...
@@ -41,8 +42,8 @@ def _find_dep_file_path(main_file, file_path):
for
sys_path
in
sys
.
path
:
test_path
=
os
.
path
.
realpath
(
os
.
path
.
join
(
sys_path
,
file_path
))
if
os
.
path
.
exists
(
test_path
):
return
test_path
return
abs_path
return
canonical_filename
(
test_path
)
return
canonical_filename
(
abs_path
)
class
Plugin
(
CoveragePlugin
):
...
...
@@ -63,7 +64,7 @@ class Plugin(CoveragePlugin):
if
filename
.
startswith
(
'<'
)
or
filename
.
startswith
(
'memory:'
):
return
None
c_file
=
py_file
=
None
filename
=
os
.
path
.
abspath
(
filename
)
filename
=
canonical_filename
(
os
.
path
.
abspath
(
filename
)
)
if
self
.
_c_files_map
and
filename
in
self
.
_c_files_map
:
c_file
=
self
.
_c_files_map
[
filename
][
0
]
...
...
@@ -91,7 +92,7 @@ class Plugin(CoveragePlugin):
# from coverage.python import PythonFileReporter
# return PythonFileReporter(filename)
filename
=
os
.
path
.
abspath
(
filename
)
filename
=
canonical_filename
(
os
.
path
.
abspath
(
filename
)
)
if
self
.
_c_files_map
and
filename
in
self
.
_c_files_map
:
c_file
,
rel_file_path
,
code
=
self
.
_c_files_map
[
filename
]
else
:
...
...
tests/run/coverage_api.srctree
View file @
d5f4a5a4
...
...
@@ -2,7 +2,7 @@
# tag: coverage,trace
"""
PYTHON -c
'import shutil; shutil.copy("pkg/coverage_test_pyx.pyx", "pkg/coverage_test_pyx.pxi")'
PYTHON -c
"import shutil; shutil.copy('pkg/coverage_test_pyx.pyx', 'pkg/coverage_test_pyx.pxi')"
PYTHON setup.py build_ext -i
PYTHON coverage_test.py
"""
...
...
@@ -14,7 +14,8 @@ from Cython.Build import cythonize
setup(ext_modules = cythonize([
'coverage_test_*.py*',
'pkg/coverage_test_*.py*'
'pkg/coverage_test_*.py*',
'Package2/CoverageTest_*.py*'
]))
...
...
@@ -68,6 +69,52 @@ def main_func(int x): # 11
return cfunc1(x) + func1(x, 4) + func2(x) # 12
######## Package2/__init__.py ########
# Add MixedCase package and filenames to test if the files are found
######## Package2/CoverageTest_py.py ########
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE=1
def func1(a, b):
x = 1 # 5
c = func2(a) + b # 6
return x + c # 7
def func2(a):
return a * 2 # 11
######## Package2/CoverageTest_pyx.pyx ########
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE=1
def func1(int a, int b):
cdef int x = 1 # 5
c = func2(a) + b # 6
return x + c # 7
def func2(int a):
return a * 2 # 11
######## coverage_test_include_pyx.pyx ########
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE=1
cdef int x = 5 # 4
cdef int cfunc1(int x): # 6
return x * 3 # 7
include "pkg/coverage_test_pyx.pxi" # 9
def main_func(int x): # 11
return cfunc1(x) + func1(x, 4) + func2(x) # 12
######## coverage_test.py ########
import re
...
...
@@ -84,8 +131,12 @@ from pkg import coverage_test_py
from pkg import coverage_test_pyx
import coverage_test_include_pyx
# test the MixedCase Files and packages
from Package2 import CoverageTest_py
from Package2 import CoverageTest_pyx
for module in [coverage_test_py, coverage_test_pyx, coverage_test_include_pyx]:
for module in [coverage_test_py, coverage_test_pyx, coverage_test_include_pyx,
CoverageTest_py, CoverageTest_pyx]:
assert not any(module.__file__.endswith(ext) for ext in '.py .pyc .pyo .pyw .pyx .pxi'.split()), \
module.__file__
...
...
@@ -93,10 +144,18 @@ for module in [coverage_test_py, coverage_test_pyx, coverage_test_include_pyx]:
def source_file_for(module):
module_name = module.__name__
path, ext = os.path.splitext(module.__file__)
platform_suffix = re.search(r'[.](?:cpython|pypy)-[0-9]+[^.]*$', path, re.I)
if platform_suffix:
path = path[:platform_suffix.start()]
return path + '.' + module_name.rsplit('_', 1)[-1]
if ext == '.so':
# Linux/Unix/Mac extension module
platform_suffix = re.search(r'[.](?:cpython|pypy)-[0-9]+[-_a-z0-9]*$', path, re.I)
if platform_suffix:
path = path[:platform_suffix.start()]
elif ext == '.pyd':
# Windows extension module
platform_suffix = re.search(r'[.]cp[0-9]+-win[_a-z0-9]*$', path, re.I)
if platform_suffix:
path = path[:platform_suffix.start()]
source_filepath = path + '.' + module_name.rsplit('_', 1)[-1]
return source_filepath
def run_coverage(module):
...
...
@@ -137,3 +196,5 @@ if __name__ == '__main__':
run_coverage(coverage_test_py)
run_coverage(coverage_test_pyx)
run_coverage(coverage_test_include_pyx)
run_coverage(CoverageTest_py)
run_coverage(CoverageTest_pyx)
tests/run/coverage_cmd.srctree
View file @
d5f4a5a4
...
...
@@ -2,7 +2,7 @@
# tag: coverage,trace
"""
PYTHON -c
'import shutil; shutil.copy("pkg/coverage_test_pyx.pyx", "pkg/coverage_test_pyx.pxi")'
PYTHON -c
"import shutil; shutil.copy('pkg/coverage_test_pyx.pyx', 'pkg/coverage_test_pyx.pxi')"
PYTHON setup.py build_ext -i
PYTHON -m coverage run coverage_test.py
PYTHON collect_coverage.py
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment