Robot Framework
visitor.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 
78 
79 
80 
86 
87 
93  def visit_suite(self, suite):
94  if self.start_suitestart_suite(suite) is not False:
95  if suite.has_setup:
96  suite.setup.visit(self)
97  suite.suites.visit(self)
98  suite.tests.visit(self)
99  if suite.has_teardown:
100  suite.teardown.visit(self)
101  self.end_suiteend_suite(suite)
102 
103 
107  def start_suite(self, suite):
108  pass
109 
110 
111  def end_suite(self, suite):
112  pass
113 
114 
119  def visit_test(self, test):
120  if self.start_teststart_test(test) is not False:
121  if test.has_setup:
122  test.setup.visit(self)
123  test.body.visit(self)
124  if test.has_teardown:
125  test.teardown.visit(self)
126  self.end_testend_test(test)
127 
128 
132  def start_test(self, test):
133  pass
134 
135 
136  def end_test(self, test):
137  pass
138 
139 
145  def visit_keyword(self, kw):
146  if self.start_keywordstart_keyword(kw) is not False:
147  if hasattr(kw, 'body'):
148  kw.body.visit(self)
149  if kw.has_teardown:
150  kw.teardown.visit(self)
151  self.end_keywordend_keyword(kw)
152 
153 
159  def start_keyword(self, keyword):
160  return self.start_body_itemstart_body_item(keyword)
161 
162 
166  def end_keyword(self, keyword):
167  self.end_body_itemend_body_item(keyword)
168 
169 
174  def visit_for(self, for_):
175  if self.start_forstart_for(for_) is not False:
176  for_.body.visit(self)
177  self.end_forend_for(for_)
178 
179 
185  def start_for(self, for_):
186  return self.start_body_itemstart_body_item(for_)
187 
188 
192  def end_for(self, for_):
193  self.end_body_itemend_body_item(for_)
194 
195 
204  def visit_for_iteration(self, iteration):
205  if self.start_for_iterationstart_for_iteration(iteration) is not False:
206  iteration.body.visit(self)
207  self.end_for_iterationend_for_iteration(iteration)
208 
209 
215  def start_for_iteration(self, iteration):
216  return self.start_body_itemstart_body_item(iteration)
217 
218 
222  def end_for_iteration(self, iteration):
223  self.end_body_itemend_body_item(iteration)
224 
225 
233  def visit_if(self, if_):
234  if self.start_ifstart_if(if_) is not False:
235  if_.body.visit(self)
236  self.end_ifend_if(if_)
237 
238 
244  def start_if(self, if_):
245  return self.start_body_itemstart_body_item(if_)
246 
247 
251  def end_if(self, if_):
252  self.end_body_itemend_body_item(if_)
253 
254 
259  def visit_if_branch(self, branch):
260  if self.start_if_branchstart_if_branch(branch) is not False:
261  branch.body.visit(self)
262  self.end_if_branchend_if_branch(branch)
263 
264 
270  def start_if_branch(self, branch):
271  return self.start_body_itemstart_body_item(branch)
272 
273 
277  def end_if_branch(self, branch):
278  self.end_body_itemend_body_item(branch)
279 
280 
285  def visit_try(self, try_):
286  if self.start_trystart_try(try_) is not False:
287  try_.body.visit(self)
288  self.end_tryend_try(try_)
289 
290 
296  def start_try(self, try_):
297  return self.start_body_itemstart_body_item(try_)
298 
299 
303  def end_try(self, try_):
304  self.end_body_itemend_body_item(try_)
305 
306 
307  def visit_try_branch(self, branch):
308  if self.start_try_branchstart_try_branch(branch) is not False:
309  branch.body.visit(self)
310  self.end_try_branchend_try_branch(branch)
311 
312 
318  def start_try_branch(self, branch):
319  return self.start_body_itemstart_body_item(branch)
320 
321 
325  def end_try_branch(self, branch):
326  self.end_body_itemend_body_item(branch)
327 
328 
333  def visit_while(self, while_):
334  if self.start_whilestart_while(while_) is not False:
335  while_.body.visit(self)
336  self.end_whileend_while(while_)
337 
338 
344  def start_while(self, while_):
345  return self.start_body_itemstart_body_item(while_)
346 
347 
351  def end_while(self, while_):
352  self.end_body_itemend_body_item(while_)
353 
354 
363  def visit_while_iteration(self, iteration):
364  if self.start_while_iterationstart_while_iteration(iteration) is not False:
365  iteration.body.visit(self)
366  self.end_while_iterationend_while_iteration(iteration)
367 
368 
374  def start_while_iteration(self, iteration):
375  return self.start_body_itemstart_body_item(iteration)
376 
377 
381  def end_while_iteration(self, iteration):
382  self.end_body_itemend_body_item(iteration)
383 
384 
385  def visit_return(self, return_):
386  if self.start_returnstart_return(return_) is not False:
387  if hasattr(return_, 'body'):
388  return_.body.visit(self)
389  self.end_returnend_return(return_)
390 
391 
397  def start_return(self, return_):
398  return self.start_body_itemstart_body_item(return_)
399 
400 
404  def end_return(self, return_):
405  self.end_body_itemend_body_item(return_)
406 
407 
408  def visit_continue(self, continue_):
409  if self.start_continuestart_continue(continue_) is not False:
410  if hasattr(continue_, 'body'):
411  continue_.body.visit(self)
412  self.end_continueend_continue(continue_)
413 
414 
420  def start_continue(self, continue_):
421  return self.start_body_itemstart_body_item(continue_)
422 
423 
427  def end_continue(self, continue_):
428  self.end_body_itemend_body_item(continue_)
429 
430 
431  def visit_break(self, break_):
432  if self.start_breakstart_break(break_) is not False:
433  if hasattr(break_, 'body'):
434  break_.body.visit(self)
435  self.end_breakend_break(break_)
436 
437 
443  def start_break(self, break_):
444  return self.start_body_itemstart_body_item(break_)
445 
446 
450  def end_break(self, break_):
451  self.end_body_itemend_body_item(break_)
452 
453 
458  def visit_message(self, msg):
459  if self.start_messagestart_message(msg) is not False:
460  self.end_messageend_message(msg)
461 
462 
468  def start_message(self, msg):
469  return self.start_body_itemstart_body_item(msg)
470 
471 
475  def end_message(self, msg):
476  self.end_body_itemend_body_item(msg)
477 
478 
487  def start_body_item(self, item):
488  pass
489 
490 
498  def end_body_item(self, item):
499  pass
Interface to ease traversing through a test suite structure.
Definition: visitor.py:85
def visit_try_branch(self, branch)
Visits individual TRY, EXCEPT, ELSE and FINALLY branches.
Definition: visitor.py:307
def start_if_branch(self, branch)
Called when an IF/ELSE branch starts.
Definition: visitor.py:270
def start_while(self, while_)
Called when a WHILE loop starts.
Definition: visitor.py:344
def visit_keyword(self, kw)
Implements traversing through keywords.
Definition: visitor.py:145
def visit_for(self, for_)
Implements traversing through FOR loops.
Definition: visitor.py:174
def end_body_item(self, item)
Called, by default, when keywords, messages or control structures end.
Definition: visitor.py:498
def visit_continue(self, continue_)
Visits CONTINUE elements.
Definition: visitor.py:408
def visit_test(self, test)
Implements traversing through tests.
Definition: visitor.py:119
def start_return(self, return_)
Called when a RETURN element starts.
Definition: visitor.py:397
def start_break(self, break_)
Called when a BREAK element starts.
Definition: visitor.py:443
def end_try_branch(self, branch)
Called when TRY, EXCEPT, ELSE and FINALLY branches end.
Definition: visitor.py:325
def visit_while(self, while_)
Implements traversing through WHILE loops.
Definition: visitor.py:333
def end_try(self, try_)
Called when a TRY/EXCEPT structure ends.
Definition: visitor.py:303
def visit_if_branch(self, branch)
Implements traversing through single IF/ELSE branch.
Definition: visitor.py:259
def end_test(self, test)
Called when a test ends.
Definition: visitor.py:136
def start_for(self, for_)
Called when a FOR loop starts.
Definition: visitor.py:185
def visit_while_iteration(self, iteration)
Implements traversing through single WHILE loop iteration.
Definition: visitor.py:363
def start_while_iteration(self, iteration)
Called when a WHILE loop iteration starts.
Definition: visitor.py:374
def start_if(self, if_)
Called when an IF/ELSE structure starts.
Definition: visitor.py:244
def end_while(self, while_)
Called when a WHILE loop ends.
Definition: visitor.py:351
def end_while_iteration(self, iteration)
Called when a WHILE loop iteration ends.
Definition: visitor.py:381
def end_suite(self, suite)
Called when a suite ends.
Definition: visitor.py:111
def end_for(self, for_)
Called when a FOR loop ends.
Definition: visitor.py:192
def visit_if(self, if_)
Implements traversing through IF/ELSE structures.
Definition: visitor.py:233
def start_test(self, test)
Called when a test starts.
Definition: visitor.py:132
def start_for_iteration(self, iteration)
Called when a FOR loop iteration starts.
Definition: visitor.py:215
def end_message(self, msg)
Called when a message ends.
Definition: visitor.py:475
def end_keyword(self, keyword)
Called when a keyword ends.
Definition: visitor.py:166
def start_message(self, msg)
Called when a message starts.
Definition: visitor.py:468
def visit_suite(self, suite)
Implements traversing through suites.
Definition: visitor.py:93
def end_return(self, return_)
Called when a RETURN element ends.
Definition: visitor.py:404
def start_body_item(self, item)
Called, by default, when keywords, messages or control structures start.
Definition: visitor.py:487
def visit_message(self, msg)
Implements visiting messages.
Definition: visitor.py:458
def end_continue(self, continue_)
Called when a CONTINUE element ends.
Definition: visitor.py:427
def start_try(self, try_)
Called when a TRY/EXCEPT structure starts.
Definition: visitor.py:296
def visit_for_iteration(self, iteration)
Implements traversing through single FOR loop iteration.
Definition: visitor.py:204
def start_try_branch(self, branch)
Called when TRY, EXCEPT, ELSE or FINALLY branches start.
Definition: visitor.py:318
def end_break(self, break_)
Called when a BREAK element ends.
Definition: visitor.py:450
def start_continue(self, continue_)
Called when a CONTINUE element starts.
Definition: visitor.py:420
def end_for_iteration(self, iteration)
Called when a FOR loop iteration ends.
Definition: visitor.py:222
def visit_return(self, return_)
Visits a RETURN elements.
Definition: visitor.py:385
def visit_try(self, try_)
Implements traversing through TRY/EXCEPT structures.
Definition: visitor.py:285
def start_keyword(self, keyword)
Called when a keyword starts.
Definition: visitor.py:159
def end_if(self, if_)
Called when an IF/ELSE structure ends.
Definition: visitor.py:251
def visit_break(self, break_)
Visits BREAK elements.
Definition: visitor.py:431
def end_if_branch(self, branch)
Called when an IF/ELSE branch ends.
Definition: visitor.py:277
def start_suite(self, suite)
Called when a suite starts.
Definition: visitor.py:107