Skip to content

Commit 770ecea

Browse files
committed
testdoc: added testdoc() entry point, enhanced apidocs, little code cleanup
1 parent 549a1d8 commit 770ecea

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/robot/testdoc.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@
7474
import pythonpathsetter
7575

7676
from robot import utils
77-
from robot.running import TestSuiteBuilder
7877
from robot.conf import RobotSettings
79-
from robot.parsing import disable_curdir_processing
8078
from robot.htmldata import HtmlFileWriter, ModelWriter, JsonWriter, TESTDOC
79+
from robot.parsing import disable_curdir_processing
80+
from robot.running import TestSuiteBuilder
8181

8282

8383
class 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

243269
if __name__ == '__main__':

src/robot/utils/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _parse_arguments(self, cli_args):
7070

7171
def execute(self, *arguments, **options):
7272
with self._logging():
73-
return self._execute(arguments, options)
73+
return self._execute(list(arguments), options)
7474

7575
def _execute(self, arguments, options):
7676
try:

0 commit comments

Comments
 (0)