1515import re
1616import string
1717from datetime import datetime
18-
19- from robot .api import ResultVisitor
18+ from typing import List , Pattern , Optional
2019from urllib .parse import unquote
2120
22- from . import listener
23- from .time_visitor import corrections
24- # noinspection PyUnresolvedReferences
25- from .variables import _variables
21+ from robot .result import ResultVisitor , Result , TestSuite , TestCase , Keyword , Message
2622
23+ from robotframework_reportportal import listener
24+ from robotframework_reportportal .time_visitor import corrections
25+ # noinspection PyUnresolvedReferences
26+ from robotframework_reportportal .variables import _variables
2727
2828listener = listener .listener ()
2929
3030
31- def to_timestamp (time_str ) :
31+ def to_timestamp (time_str : str ) -> Optional [ str ] :
3232 if time_str :
3333 dt = datetime .strptime (time_str , '%Y%m%d %H:%M:%S.%f' )
3434 return str (int (dt .timestamp () * 1000 ))
3535 return None
3636
3737
3838class RobotResultsVisitor (ResultVisitor ):
39- _link_pattern = re .compile ("src=[\" \' ]([^\" \' ]+)[\" \' ]" )
39+ _link_pattern : Pattern = re .compile ("src=[\" \' ]([^\" \' ]+)[\" \' ]" )
4040
41- def start_result (self , result ) :
41+ def start_result (self , result : Result ) -> bool :
4242 if "RP_LAUNCH" not in _variables :
4343 _variables ["RP_LAUNCH" ] = result .suite .name
4444 if "RP_LAUNCH_DOC" not in _variables :
4545 _variables ["RP_LAUNCH_DOC" ] = result .suite .doc
46+ return True
4647
47- def start_suite (self , suite ) :
48+ def start_suite (self , suite : TestSuite ) -> bool :
4849 ts = to_timestamp (suite .starttime if suite .id not in corrections else corrections [suite .id ][0 ])
4950 attrs = {
5051 'id' : suite .id ,
@@ -58,8 +59,9 @@ def start_suite(self, suite):
5859 'starttime' : ts
5960 }
6061 listener .start_suite (suite .name , attrs , ts )
62+ return True
6163
62- def end_suite (self , suite ) :
64+ def end_suite (self , suite : TestSuite ) -> None :
6365 ts = to_timestamp (suite .endtime if suite .id not in corrections else corrections [suite .id ][1 ])
6466 attrs = {
6567 'id' : suite .id ,
@@ -78,7 +80,7 @@ def end_suite(self, suite):
7880 }
7981 listener .end_suite (None , attrs , ts )
8082
81- def start_test (self , test ) :
83+ def start_test (self , test : TestCase ) -> bool :
8284 ts = to_timestamp (test .starttime if test .id not in corrections else corrections [test .id ][0 ])
8385 attrs = {
8486 'id' : test .id ,
@@ -95,8 +97,9 @@ def start_test(self, test):
9597 'starttime' : ts ,
9698 }
9799 listener .start_test (test .name , attrs , ts )
100+ return True
98101
99- def end_test (self , test ) :
102+ def end_test (self , test : TestCase ) -> None :
100103 ts = to_timestamp (test .endtime if test .id not in corrections else corrections [test .id ][1 ])
101104 attrs = {
102105 'id' : test .id ,
@@ -117,7 +120,7 @@ def end_test(self, test):
117120 }
118121 listener .end_test (test .name , attrs , ts )
119122
120- def start_keyword (self , kw ) :
123+ def start_keyword (self , kw : Keyword ) -> bool :
121124 ts = to_timestamp (kw .starttime if kw .id not in corrections else corrections [kw .id ][0 ])
122125 attrs = {
123126 'type' : string .capwords (kw .type ),
@@ -130,8 +133,9 @@ def start_keyword(self, kw):
130133 'starttime' : ts ,
131134 }
132135 listener .start_keyword (kw .name , attrs , ts )
136+ return True
133137
134- def end_keyword (self , kw ) :
138+ def end_keyword (self , kw : Keyword ) -> None :
135139 ts = to_timestamp (kw .endtime if kw .id not in corrections else corrections [kw .id ][1 ])
136140 attrs = {
137141 'type' : string .capwords (kw .type ),
@@ -147,7 +151,7 @@ def end_keyword(self, kw):
147151 }
148152 listener .end_keyword (kw .name , attrs , ts )
149153
150- def start_message (self , msg ) :
154+ def start_message (self , msg : Message ) -> bool :
151155 if msg .message :
152156 message = {
153157 'message' : msg .message ,
@@ -162,8 +166,9 @@ def start_message(self, msg):
162166 try :
163167 listener .log_message (message )
164168 except Exception :
165- pass
169+ return False
170+ return True
166171
167- def parse_message (self , msg ) :
172+ def parse_message (self , msg : str ) -> List [ str ] :
168173 m = self ._link_pattern .search (msg )
169174 return [m .group (), unquote (m .group (1 ))]
0 commit comments