繼續填坑,之前從代碼邏輯上走了一圈,沒啥太深印象,看來需要花個圖看看
這個visit_suite貌似比較複雜,代碼裏專門描述了算法:
Visitor algorithm
All suite, test, keyword and message objects have a visit()
method
that accepts a visitor instance. These methods will then call the correct visitor method visit_suite()
, visit_test()
,visit_keyword()
or visit_message()
,
depending on the instance where the visit()
method
exists.
The recommended and definitely easiest way to implement a visitor is extending the SuiteVisitor
base
class. The default implementation of its visit_x()
methods
take care of traversing child elements of the object x
recursively.
A visit_x()
method
first calls a corresponding start_x()
method
(e.g. visit_suite()
calls start_suite()
),
then calls visit()
for
all child objects of the x
object,
and finally calls the corresponding end_x()
method.
The default implementations of start_x()
and end_x()
do
nothing.
Visitors extending the SuiteVisitor
can
stop visiting at a certain level either by overriding suitable visit_x()
method
or by returning an explicit False
from
any start_x()
method.