9
9
import sys
10
10
import time
11
11
from functools import partial
12
+ from typing import Callable
13
+ from typing import Dict
14
+ from typing import List
15
+ from typing import Mapping
16
+ from typing import Optional
17
+ from typing import Set
12
18
13
19
import attr
14
20
import pluggy
@@ -195,8 +201,8 @@ class WarningReport:
195
201
file system location of the source of the warning (see ``get_location``).
196
202
"""
197
203
198
- message = attr .ib ()
199
- nodeid = attr .ib (default = None )
204
+ message = attr .ib (type = str )
205
+ nodeid = attr .ib (type = Optional [ str ], default = None )
200
206
fslocation = attr .ib (default = None )
201
207
count_towards_summary = True
202
208
@@ -240,7 +246,7 @@ def __init__(self, config, file=None):
240
246
self .reportchars = getreportopt (config )
241
247
self .hasmarkup = self ._tw .hasmarkup
242
248
self .isatty = file .isatty ()
243
- self ._progress_nodeids_reported = set ()
249
+ self ._progress_nodeids_reported = set () # type: Set[str]
244
250
self ._show_progress_info = self ._determine_show_progress_info ()
245
251
self ._collect_report_last_write = None
246
252
@@ -619,7 +625,7 @@ def _printcollecteditems(self, items):
619
625
# because later versions are going to get rid of them anyway
620
626
if self .config .option .verbose < 0 :
621
627
if self .config .option .verbose < - 1 :
622
- counts = {}
628
+ counts = {} # type: Dict[str, int]
623
629
for item in items :
624
630
name = item .nodeid .split ("::" , 1 )[0 ]
625
631
counts [name ] = counts .get (name , 0 ) + 1
@@ -750,7 +756,9 @@ def getreports(self, name):
750
756
751
757
def summary_warnings (self ):
752
758
if self .hasopt ("w" ):
753
- all_warnings = self .stats .get ("warnings" )
759
+ all_warnings = self .stats .get (
760
+ "warnings"
761
+ ) # type: Optional[List[WarningReport]]
754
762
if not all_warnings :
755
763
return
756
764
@@ -763,7 +771,9 @@ def summary_warnings(self):
763
771
if not warning_reports :
764
772
return
765
773
766
- reports_grouped_by_message = collections .OrderedDict ()
774
+ reports_grouped_by_message = (
775
+ collections .OrderedDict ()
776
+ ) # type: collections.OrderedDict[str, List[WarningReport]]
767
777
for wr in warning_reports :
768
778
reports_grouped_by_message .setdefault (wr .message , []).append (wr )
769
779
@@ -900,11 +910,11 @@ def summary_stats(self):
900
910
else :
901
911
self .write_line (msg , ** main_markup )
902
912
903
- def short_test_summary (self ):
913
+ def short_test_summary (self ) -> None :
904
914
if not self .reportchars :
905
915
return
906
916
907
- def show_simple (stat , lines ) :
917
+ def show_simple (stat , lines : List [ str ]) -> None :
908
918
failed = self .stats .get (stat , [])
909
919
if not failed :
910
920
return
@@ -914,7 +924,7 @@ def show_simple(stat, lines):
914
924
line = _get_line_with_reprcrash_message (config , rep , termwidth )
915
925
lines .append (line )
916
926
917
- def show_xfailed (lines ) :
927
+ def show_xfailed (lines : List [ str ]) -> None :
918
928
xfailed = self .stats .get ("xfailed" , [])
919
929
for rep in xfailed :
920
930
verbose_word = rep ._get_verbose_word (self .config )
@@ -924,15 +934,15 @@ def show_xfailed(lines):
924
934
if reason :
925
935
lines .append (" " + str (reason ))
926
936
927
- def show_xpassed (lines ) :
937
+ def show_xpassed (lines : List [ str ]) -> None :
928
938
xpassed = self .stats .get ("xpassed" , [])
929
939
for rep in xpassed :
930
940
verbose_word = rep ._get_verbose_word (self .config )
931
941
pos = _get_pos (self .config , rep )
932
942
reason = rep .wasxfail
933
943
lines .append ("{} {} {}" .format (verbose_word , pos , reason ))
934
944
935
- def show_skipped (lines ) :
945
+ def show_skipped (lines : List [ str ]) -> None :
936
946
skipped = self .stats .get ("skipped" , [])
937
947
fskips = _folded_skips (skipped ) if skipped else []
938
948
if not fskips :
@@ -958,9 +968,9 @@ def show_skipped(lines):
958
968
"S" : show_skipped ,
959
969
"p" : partial (show_simple , "passed" ),
960
970
"E" : partial (show_simple , "error" ),
961
- }
971
+ } # type: Mapping[str, Callable[[List[str]], None]]
962
972
963
- lines = []
973
+ lines = [] # type: List[str]
964
974
for char in self .reportchars :
965
975
action = REPORTCHAR_ACTIONS .get (char )
966
976
if action : # skipping e.g. "P" (passed with output) here.
@@ -1084,8 +1094,8 @@ def build_summary_stats_line(stats):
1084
1094
return parts , main_color
1085
1095
1086
1096
1087
- def _plugin_nameversions (plugininfo ):
1088
- values = []
1097
+ def _plugin_nameversions (plugininfo ) -> List [ str ] :
1098
+ values = [] # type: List[str]
1089
1099
for plugin , dist in plugininfo :
1090
1100
# gets us name and version!
1091
1101
name = "{dist.project_name}-{dist.version}" .format (dist = dist )
@@ -1099,7 +1109,7 @@ def _plugin_nameversions(plugininfo):
1099
1109
return values
1100
1110
1101
1111
1102
- def format_session_duration (seconds ) :
1112
+ def format_session_duration (seconds : float ) -> str :
1103
1113
"""Format the given seconds in a human readable manner to show in the final summary"""
1104
1114
if seconds < 60 :
1105
1115
return "{:.2f}s" .format (seconds )
0 commit comments