18
18
19
19
from wcmatch import fnmatch as wcfnmatch # python -m pip install wcmatch
20
20
21
- from coverage .results import Numbers # Note: an internal class!
21
+ from coverage .results import Numbers # Note: an internal class!
22
22
23
23
24
- def get_data ():
25
- with open ("coverage.json" ) as j :
26
- return json .load (j )
27
-
28
24
def select_files (files , pat ):
29
25
flags = wcfnmatch .NEGATE | wcfnmatch .NEGATEALL
30
26
selected = [f for f in files if wcfnmatch .fnmatch (f , pat , flags = flags )]
@@ -38,30 +34,35 @@ def total_for_files(data, files):
38
34
n_statements = sel_summ ["num_statements" ],
39
35
n_excluded = sel_summ ["excluded_lines" ],
40
36
n_missing = sel_summ ["missing_lines" ],
41
- n_branches = sel_summ [ "num_branches" ] ,
42
- n_partial_branches = sel_summ [ "num_partial_branches" ] ,
43
- n_missing_branches = sel_summ [ "missing_branches" ] ,
37
+ n_branches = sel_summ . get ( "num_branches" , 0 ) ,
38
+ n_partial_branches = sel_summ . get ( "num_partial_branches" , 0 ) ,
39
+ n_missing_branches = sel_summ . get ( "missing_branches" , 0 ) ,
44
40
)
45
41
46
42
return total
47
43
48
44
def main (argv ):
49
- parser = argparse .ArgumentParser (__doc__ )
45
+ parser = argparse .ArgumentParser (description = __doc__ )
50
46
parser .add_argument ("--file" , "-f" , action = "store_true" , help = "Check each file individually" )
51
47
parser .add_argument ("--group" , "-g" , action = "store_true" , help = "Check a group of files" )
52
48
parser .add_argument ("--verbose" , "-v" , action = "store_true" , help = "Be chatty about what's happening" )
53
49
parser .add_argument ("goal" , type = float , help = "Coverage goal" )
54
50
parser .add_argument ("pattern" , type = str , nargs = "+" , help = "Patterns to check" )
55
51
args = parser .parse_args (argv )
56
52
53
+ print ("** Note: this is a proof-of-concept. Support is not promised. **" )
54
+ print ("Read more: https://nedbatchelder.com/blog/202111/coverage_goals.html" )
55
+ print ("Feedback is appreciated: https://github.com/nedbat/coveragepy/issues/691" )
56
+
57
57
if args .file and args .group :
58
58
print ("Can't use --file and --group together" )
59
59
return 1
60
60
if not (args .file or args .group ):
61
61
print ("Need either --file or --group" )
62
62
return 1
63
63
64
- data = get_data ()
64
+ with open ("coverage.json" ) as j :
65
+ data = json .load (j )
65
66
all_files = list (data ["files" ].keys ())
66
67
selected = select_files (all_files , args .pattern )
67
68
0 commit comments