继续填坑,之前从代码逻辑上走了一圈,没啥太深印象,看来需要花个图看看Robot Framework 源代码阅读笔记 之三

这个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 SuiteVisitorbase 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 xobject, 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.

至于为什么要这么设计,怎么实现灵活性的,明天继续看。


相关文章: