• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybuilder / pybuilder / 16613314016

30 Jul 2025 04:14AM UTC coverage: 84.008% (-0.1%) from 84.146%
16613314016

push

github

arcivanov
Release 0.13.16

2167 of 2671 branches covered (81.13%)

Branch coverage included in aggregate %.

5534 of 6496 relevant lines covered (85.19%)

36.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.88
/src/main/python/pybuilder/plugins/python/_coverage_util.py
1
#   -*- coding: utf-8 -*-
2
#
3
#   This file is part of PyBuilder
4
#
5
#   Copyright 2011-2020 PyBuilder Team
6
#
7
#   Licensed under the Apache License, Version 2.0 (the "License");
8
#   you may not use this file except in compliance with the License.
9
#   You may obtain a copy of the License at
10
#
11
#       http://www.apache.org/licenses/LICENSE-2.0
12
#
13
#   Unless required by applicable law or agreed to in writing, software
14
#   distributed under the License is distributed on an "AS IS" BASIS,
15
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
#   See the License for the specific language governing permissions and
17
#   limitations under the License.
18

19

20
import sys
44✔
21
from os.path import relpath, join as jp, exists, normcase as nc
44✔
22

23
if sys.platform in {"win32", "cygwin", "msys"}:
44✔
24
    from fnmatch import fnmatch
10✔
25
else:
26
    from fnmatch import fnmatchcase as fnmatch
34✔
27

28
files_abs_file = None
44✔
29

30

31
def patched_abs_file(path):
44✔
32
    global files_abs_file
33
    return nc(files_abs_file(path))
44✔
34

35

36
def patch_coverage():
44✔
37
    from coverage import files
44✔
38
    from coverage import control
44✔
39

40
    if files.abs_file == patched_abs_file:
44!
41
        return
×
42
    global files_abs_file
43
    files_abs_file = files.abs_file
44✔
44

45
    files.abs_file = patched_abs_file
44✔
46
    control.abs_file = patched_abs_file
44✔
47

48

49
def save_normalized_coverage(coverage, source_path, omit_patterns, paths=None):
44✔
50
    """This method is NOT a panacea but it's better than nothing
51
    It will produce bullshit relative path on occasion with complex loading plans
52
    or when entries are being removed from sys.path so they cannot be observed post-factum
53
    """
54
    paths = paths or sys.path
×
55
    normalized_paths = []
×
56

57
    processed_paths = set()
×
58
    for path in paths:
×
59
        if path in processed_paths:
×
60
            continue
×
61
        processed_paths.add(path)
×
62

63
        normalized_paths.append(nc(path))
×
64

65
    def file_mapper(path):
×
66
        path = nc(path)
×
67
        best_candidate = None
×
68
        for p in normalized_paths:
×
69
            if path == p:
×
70
                return path
×
71

72
            if path.startswith(p):
×
73
                candidate = relpath(path, p)
×
74
                if not best_candidate or len(candidate) < len(best_candidate):
×
75
                    best_candidate = candidate
×
76

77
        if best_candidate:
×
78
            final_candidate = jp(source_path, best_candidate)
×
79
            if exists(final_candidate):
×
80
                return final_candidate
×
81
            return best_candidate
×
82
        else:
83
            return path
×
84

85
    collector = coverage._collector
×
86
    collector.file_mapper = file_mapper
×
87

88
    def clean_data(data):
×
89
        # Normalize keys/paths on Windows
90
        # Remove all data for files that is not in source_path
91
        # Remove all data in omit_patterns
92

93
        for k in list(data.keys()):
×
94
            delete_key = False
×
95
            new_k = collector.cached_mapped_file(k)
×
96
            if not new_k.startswith(source_path):
×
97
                delete_key = True
×
98
            else:
99
                for omit_pattern in omit_patterns:
×
100
                    if fnmatch(new_k, omit_pattern):
×
101
                        delete_key = True
×
102
                        break
×
103

104
            if delete_key:
×
105
                del data[k]
×
106
            else:
107
                v = data[k]
×
108
                del data[k]
×
109
                data[new_k] = v
×
110

111
    clean_data(collector.data)
×
112
    clean_data(collector.file_tracers)
×
113

114
    coverage.save()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc