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.

至於爲什麼要這麼設計,怎麼實現靈活性的,明天繼續看。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章