Commit 39dedc8a authored by Stefan Behnel's avatar Stefan Behnel

coverage test: find correct source file for a Cython module in Py3 (which uses...

coverage test: find correct source file for a Cython module in Py3 (which uses platform suffixes for the file names)
parent 2c9c2399
......@@ -70,6 +70,7 @@ def main_func(int x): # 11
######## coverage_test.py ########
import re
import os.path
try:
# io.StringIO in Py2.x cannot handle str ...
......@@ -89,6 +90,15 @@ for module in [coverage_test_py, coverage_test_pyx, coverage_test_include_pyx]:
module.__file__
def source_file_for(module):
module_name = module.__name__
path, ext = os.path.splitext(module.__file__)
platform_suffix = re.search(r'[.]cpython-[0-9]+[a-z]*$', path, re.I)
if platform_suffix:
path = path[:platform_suffix.start()]
return path + '.' + module_name.rsplit('_', 1)[-1]
def run_coverage(module):
module_name = module.__name__
module_path = module_name.replace('.', os.path.sep) + '.' + module_name.rsplit('_', 1)[-1]
......@@ -108,8 +118,7 @@ def run_coverage(module):
assert any(module_path in line for line in lines), "'%s' not found in coverage report:\n\n%s" % (
module_path, out.getvalue())
mod_file, exec_lines, excl_lines, missing_lines, _ = cov.analysis2(
os.path.splitext(module.__file__)[0] + '.' + module_name.rsplit('_', 1)[-1])
mod_file, exec_lines, excl_lines, missing_lines, _ = cov.analysis2(source_file_for(module))
assert module_path in mod_file
if '_include_' in module_name:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment