7474 import pythonpathsetter
7575
7676from robot import utils
77- from robot .running import TestSuiteBuilder
7877from robot .conf import RobotSettings
79- from robot .parsing import disable_curdir_processing
8078from robot .htmldata import HtmlFileWriter , ModelWriter , JsonWriter , TESTDOC
79+ from robot .parsing import disable_curdir_processing
80+ from robot .running import TestSuiteBuilder
8181
8282
8383class TestDoc (utils .Application ):
@@ -201,11 +201,11 @@ def _convert_for_loop(self, kw):
201201 'type' : 'FOR'
202202 }
203203
204- def _convert_keyword (self , kw , type ):
204+ def _convert_keyword (self , kw , kw_type ):
205205 return {
206206 'name' : self ._escape (self ._get_kw_name (kw )),
207207 'arguments' : self ._escape (', ' .join (kw .args )),
208- 'type' : type
208+ 'type' : kw_type
209209 }
210210
211211 def _get_kw_name (self , kw ):
@@ -215,7 +215,7 @@ def _get_kw_name(self, kw):
215215
216216 def _get_for_loop (self , kw ):
217217 joiner = ' IN RANGE ' if kw .range else ' IN '
218- return ', ' .join (kw .vars ) + joiner + utils .seq2str2 (kw .items )
218+ return ', ' .join (kw .vars ) + joiner + utils .seq2str2 (kw .items )
219219
220220 def _get_timeout (self , timeout ):
221221 if timeout is None :
@@ -229,15 +229,41 @@ def _get_timeout(self, timeout):
229229 return tout
230230
231231
232- def testdoc_cli (args ):
233- """Executes testdoc similarly as from the command line.
232+ def testdoc_cli (arguments ):
233+ """Executes Testdoc similarly as from the command line.
234+
235+ :param arguments: command line arguments as a list of strings.
234236
235- :param args: command line arguments as a list of strings.
237+ For programmatic usage the :func:`testdoc` function is typically better. It
238+ has a better API for that usage and does not call :func:`sys.exit` like
239+ this function.
236240
237241 Example:
238- testdoc_cli(['--title', 'Test Plan', 'mytests', 'plan.html'])
242+
243+ .. code-block:: python
244+
245+ from robot.testdoc import testdoc_cli
246+
247+ testdoc_cli(['--title', 'Test Plan', 'mytests', 'plan.html'])
248+ """
249+ TestDoc ().execute_cli (arguments )
250+
251+
252+ def testdoc (* arguments , ** options ):
253+ """Executes Testdoc programmatically.
254+
255+ Arguments and options have same semantics, and options have same names,
256+ as arguments and options to Testdoc.
257+
258+ Example:
259+
260+ .. code-block:: python
261+
262+ from robot.testdoc import testdoc
263+
264+ testdoc('mytests', 'plan.html', title='Test Plan')
239265 """
240- TestDoc ().execute_cli ( args )
266+ TestDoc ().execute ( * arguments , ** options )
241267
242268
243269if __name__ == '__main__' :
0 commit comments