robot.parsing package

Implements test data parsing.

Classes TestCaseFile, TestDataDirectory and ResourceFile represented parsed test data. Objects of these classes can be modified and saved back to disk. In addition, a convenience factory function TestData() can be used to parse a test case file or directory to a corresponding object.

Aforementioned classes and functions are part of the public API. It is recommended that they are imported through the robot.api package like in the example below.

This package is likely to change radically in Robot Framework 2.9. The main motivation for the planned changes is making the data easier to use for external tools that use these modules.

Example

import sys
from robot.api import TestData

def print_suite(suite):
    print 'Suite:', suite.name
    for test in suite.testcase_table:
        print '-', test.name
    for child in suite.children:
        print_suite(child)

suite = TestData(source=sys.argv[1])
print_suite(suite)
robot.parsing.disable_curdir_processing(method)[source]

Decorator to disable processing ${CURDIR} variable.

Submodules

robot.parsing.comments module

class robot.parsing.comments.CommentCache[source]

Bases: object

add(comment)[source]
consume_with(function)[source]
class robot.parsing.comments.Comments[source]

Bases: object

add(row)[source]
value
class robot.parsing.comments.Comment(comment_data)[source]

Bases: object

as_list()[source]

robot.parsing.datarow module

class robot.parsing.datarow.DataRow(cells)[source]

Bases: object

head
tail
all
data
dedent()[source]
starts_for_loop()[source]
starts_test_or_user_keyword_setting()[source]
test_or_user_keyword_setting_name()[source]
is_indented()[source]
is_continuing()[source]
is_commented()[source]

robot.parsing.htmlreader module

class robot.parsing.htmlreader.HtmlReader[source]

Bases: HTMLParser.HTMLParser

IGNORE = 0
INITIAL = 1
PROCESS = 2
read(htmlfile, populator)[source]
handle_starttag(tag, attrs)[source]
handle_endtag(tag)[source]
handle_data(data)[source]
handle_entityref(name)[source]
handle_charref(number)[source]
unknown_decl(data)[source]
table_start(attrs=None)[source]
table_end()[source]
tr_start(attrs=None)[source]
tr_end()[source]
td_start(attrs=None)[source]
td_end()[source]
br_start(attrs=None)[source]
meta_start(attrs)[source]
handle_pi(data)[source]
CDATA_CONTENT_ELEMENTS = ('script', 'style')
check_for_whole_start_tag(i)
clear_cdata_mode()
close()

Handle any buffered data.

entitydefs = None
error(message)
feed(data)

Feed data to the parser.

Call this as often as you want, with as little or as much text as you want (may include ‘n’).

get_starttag_text()

Return full source of start tag: ‘<...>’.

getpos()

Return current line number and offset.

goahead(end)
handle_comment(data)
handle_decl(decl)
handle_startendtag(tag, attrs)
parse_bogus_comment(i, report=1)
parse_comment(i, report=1)
parse_declaration(i)
parse_endtag(i)
parse_html_declaration(i)
parse_marked_section(i, report=1)
parse_pi(i)
parse_starttag(i)
reset()

Reset this instance. Loses all unprocessed data.

set_cdata_mode(elem)
unescape(s)
updatepos(i, j)

robot.parsing.model module

robot.parsing.model.TestData(parent=None, source=None, include_suites=None, warn_on_skipped=False, extensions=None)[source]

Parses a file or directory to a corresponding model object.

Parameters:
  • parent – Optional parent to be used in creation of the model object.
  • source – Path where test data is read from.
  • warn_on_skipped – Boolean to control warning about skipped files.
  • extensions – List/set of extensions to parse. If None, all files supported by Robot Framework are parsed when searching test cases.
Returns:

TestDataDirectory if source is a directory, TestCaseFile otherwise.

class robot.parsing.model.TestCaseFile(parent=None, source=None)[source]

Bases: robot.parsing.model._TestData

The parsed test case file object.

Parameters:
  • parent – parent object to be used in creation of the model object.
  • source – path where test data is read from.
populate()[source]
has_tests()[source]
imports
keywords
name
report_invalid_syntax(message, level='ERROR')
save(**options)

Writes this datafile to disk.

Parameters:options – Configuration for writing. These are passed to WritingContext as keyword arguments.

See also robot.writer.datafilewriter.DataFileWriter

start_table(header_row)
class robot.parsing.model.ResourceFile(source=None)[source]

Bases: robot.parsing.model._TestData

The parsed resource file object.

Parameters:source – path where resource file is read from.
populate()[source]
imports
keywords
name
report_invalid_syntax(message, level='ERROR')
save(**options)

Writes this datafile to disk.

Parameters:options – Configuration for writing. These are passed to WritingContext as keyword arguments.

See also robot.writer.datafilewriter.DataFileWriter

start_table(header_row)
class robot.parsing.model.TestDataDirectory(parent=None, source=None)[source]

Bases: robot.parsing.model._TestData

The parsed test data directory object. Contains hiearchical structure of other TestDataDirectory and TestCaseFile objects.

Parameters:
  • parent – parent object to be used in creation of the model object.
  • source – path where test data is read from.
populate(include_suites=None, warn_on_skipped=False, extensions=None, recurse=True)[source]
add_child(path, include_suites, extensions=None, warn_on_skipped=False)[source]
has_tests()[source]
imports
keywords
name
report_invalid_syntax(message, level='ERROR')
save(**options)

Writes this datafile to disk.

Parameters:options – Configuration for writing. These are passed to WritingContext as keyword arguments.

See also robot.writer.datafilewriter.DataFileWriter

start_table(header_row)
class robot.parsing.model.TestCaseFileSettingTable(parent)[source]

Bases: robot.parsing.model._SettingTable

add_library(name, args=None, comment=None)
add_metadata(name, value='', comment=None)
add_resource(name, invalid_args=None, comment=None)
add_variables(name, args=None, comment=None)
directory
get_setter(setting_name)
header
is_setting(setting_name)
name
normalize(setting)
report_invalid_syntax(message, level='ERROR')
set_header(header)
source
type = 'setting'
class robot.parsing.model.ResourceFileSettingTable(parent)[source]

Bases: robot.parsing.model._SettingTable

add_library(name, args=None, comment=None)
add_metadata(name, value='', comment=None)
add_resource(name, invalid_args=None, comment=None)
add_variables(name, args=None, comment=None)
directory
get_setter(setting_name)
header
is_setting(setting_name)
name
normalize(setting)
report_invalid_syntax(message, level='ERROR')
set_header(header)
source
type = 'setting'
class robot.parsing.model.InitFileSettingTable(parent)[source]

Bases: robot.parsing.model._SettingTable

add_library(name, args=None, comment=None)
add_metadata(name, value='', comment=None)
add_resource(name, invalid_args=None, comment=None)
add_variables(name, args=None, comment=None)
directory
get_setter(setting_name)
header
is_setting(setting_name)
name
normalize(setting)
report_invalid_syntax(message, level='ERROR')
set_header(header)
source
type = 'setting'
class robot.parsing.model.VariableTable(parent)[source]

Bases: robot.parsing.model._Table

type = 'variable'
add(name, value, comment=None)[source]
directory
header
name
report_invalid_syntax(message, level='ERROR')
set_header(header)
source
class robot.parsing.model.TestCaseTable(parent)[source]

Bases: robot.parsing.model._Table

type = 'test case'
add(name)[source]
is_started()[source]
directory
header
name
report_invalid_syntax(message, level='ERROR')
set_header(header)
source
class robot.parsing.model.KeywordTable(parent)[source]

Bases: robot.parsing.model._Table

type = 'keyword'
add(name)[source]
directory
header
name
report_invalid_syntax(message, level='ERROR')
set_header(header)
source
class robot.parsing.model.Variable(parent, name, value, comment=None)[source]

Bases: object

as_list()[source]
is_set()[source]
is_for_loop()[source]
has_data()[source]
report_invalid_syntax(message, level='ERROR')[source]
class robot.parsing.model.TestCase(parent, name)[source]

Bases: robot.parsing.model._WithSteps, robot.parsing.model._WithSettings

source
directory
add_for_loop(declaration, comment=None)[source]
report_invalid_syntax(message, level='ERROR')[source]
settings
add_step(content, comment=None)
copy(name)
get_setter(setting_name)
is_setting(setting_name)
normalize(setting)
class robot.parsing.model.UserKeyword(parent, name)[source]

Bases: robot.parsing.model.TestCase

settings
add_for_loop(declaration, comment=None)
add_step(content, comment=None)
copy(name)
directory
get_setter(setting_name)
is_setting(setting_name)
normalize(setting)
report_invalid_syntax(message, level='ERROR')
source
class robot.parsing.model.ForLoop(declaration, comment=None)[source]

Bases: robot.parsing.model._WithSteps

The parsed representation of a for-loop.

Parameters:
  • declaration (list) – The literal cell values that declare the loop (excluding ”:FOR”).
  • comment (str) – A comment, default None.
Variables:
  • flavor (str) – The value of the ‘IN’ item, uppercased. Typically ‘IN’, ‘IN RANGE’, ‘IN ZIP’, or ‘IN ENUMERATE’.
  • vars (list) – Variables set per-iteration by this loop.
  • items (list) – Loop values that come after the ‘IN’ item.
  • comment (str) – A comment, or None.
  • steps (list) – A list of steps in the loop.
is_comment()[source]
is_for_loop()[source]
as_list(indent=False, include_comment=True)[source]
is_set()[source]
add_step(content, comment=None)
copy(name)
class robot.parsing.model.Step(content, comment=None)[source]

Bases: object

is_comment()[source]
is_for_loop()[source]
is_set()[source]
as_list(indent=False, include_comment=True)[source]
class robot.parsing.model.OldStyleSettingAndVariableTableHeaderMatcher[source]

Bases: object

match(header)[source]
class robot.parsing.model.OldStyleTestAndKeywordTableHeaderMatcher[source]

Bases: object

match(header)[source]

robot.parsing.populators module

class robot.parsing.populators.FromFilePopulator(datafile)[source]

Bases: object

populate(path)[source]
start_table(header)[source]
eof()[source]
add(row)[source]
class robot.parsing.populators.FromDirectoryPopulator[source]

Bases: object

ignored_prefixes = ('_', '.')
ignored_dirs = ('CVS',)
populate(path, datadir, include_suites=None, warn_on_skipped=False, include_extensions=None, recurse=True)[source]

robot.parsing.restreader module

robot.parsing.restreader.RestReader()[source]

robot.parsing.restsupport module

class robot.parsing.restsupport.CaptureRobotData(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]

Bases: docutils.parsers.rst.directives.body.CodeBlock

run()[source]
add_name(node)

Append self.options[‘name’] to node[‘names’] if it exists.

Also normalize the name string and register it as explicit target.

assert_has_content()

Throw an ERROR-level DirectiveError if the directive doesn’t have contents.

debug(message)
directive_error(level, message)

Return a DirectiveError suitable for being thrown as an exception.

Call “raise self.directive_error(level, message)” from within a directive implementation to return one single system message at level level, which automatically gets the directive block and the line number added.

Preferably use the debug, info, warning, error, or severe wrapper methods, e.g. self.error(message) to generate an ERROR-level directive error.

error(message)
final_argument_whitespace = False
has_content = True
info(message)
option_spec = {'number-lines': <function unchanged at 0x7f4bce68c668>, 'class': <function class_option at 0x7f4bce68ca28>, 'name': <function unchanged at 0x7f4bce68c668>}
optional_arguments = 1
required_arguments = 0
severe(message)
warning(message)
class robot.parsing.restsupport.RobotDataStorage(doctree)[source]

Bases: object

add_data(rows)[source]
get_data()[source]
has_data()[source]

robot.parsing.settings module

class robot.parsing.settings.Setting(setting_name, parent=None, comment=None)[source]

Bases: object

reset()[source]
source
directory
populate(value, comment=None)[source]

Mainly used at parsing time, later attributes can be set directly.

is_set()[source]
is_for_loop()[source]
report_invalid_syntax(message, level='ERROR')[source]
as_list()[source]
class robot.parsing.settings.StringValueJoiner(separator)[source]

Bases: object

join_string_with_value(string, value)[source]
string_value(value)[source]
class robot.parsing.settings.Documentation(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

as_list()
directory
is_for_loop()
is_set()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Template(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

is_set()[source]
is_active()[source]
as_list()
directory
is_for_loop()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Fixture(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

keyword
is_comment()[source]
is_set()[source]
is_active()[source]
as_list()
directory
is_for_loop()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Timeout(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

is_set()[source]
as_list()
directory
is_for_loop()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Tags(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

is_set()[source]
as_list()
directory
is_for_loop()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Arguments(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

as_list()
directory
is_for_loop()
is_set()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Return(setting_name, parent=None, comment=None)[source]

Bases: robot.parsing.settings.Setting

as_list()
directory
is_for_loop()
is_set()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
reset()
source
class robot.parsing.settings.Metadata(parent, name, value, comment=None, joined=False)[source]

Bases: robot.parsing.settings.Setting

setting_name = 'Metadata'
reset()[source]
is_set()[source]
as_list()
directory
is_for_loop()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR')
source
class robot.parsing.settings.Library(parent, name, args=None, alias=None, comment=None)[source]

Bases: robot.parsing.settings._Import

as_list()
directory
is_for_loop()
is_set()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR', parent=None)
reset()
source
type
class robot.parsing.settings.Resource(parent, name, invalid_args=None, comment=None)[source]

Bases: robot.parsing.settings._Import

as_list()
directory
is_for_loop()
is_set()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR', parent=None)
reset()
source
type
class robot.parsing.settings.Variables(parent, name, args=None, comment=None)[source]

Bases: robot.parsing.settings._Import

as_list()
directory
is_for_loop()
is_set()
populate(value, comment=None)

Mainly used at parsing time, later attributes can be set directly.

report_invalid_syntax(message, level='ERROR', parent=None)
reset()
source
type
class robot.parsing.settings.ImportList(parent)[source]

Bases: robot.parsing.settings._DataList

populate_library(data, comment)[source]
populate_resource(data, comment)[source]
populate_variables(data, comment)[source]
add(meta)
class robot.parsing.settings.MetadataList(parent)[source]

Bases: robot.parsing.settings._DataList

populate(name, value, comment)[source]
add(meta)

robot.parsing.tablepopulators module

class robot.parsing.tablepopulators.Populator[source]

Bases: object

Explicit interface for all populators.

add(row)[source]
populate()[source]
class robot.parsing.tablepopulators.NullPopulator[source]

Bases: robot.parsing.tablepopulators.Populator

add(row)[source]
populate()[source]
class robot.parsing.tablepopulators.SettingTablePopulator(table)[source]

Bases: robot.parsing.tablepopulators._TablePopulator

add(row)
populate()
class robot.parsing.tablepopulators.VariableTablePopulator(table)[source]

Bases: robot.parsing.tablepopulators._TablePopulator

populate()[source]
add(row)
class robot.parsing.tablepopulators.TestTablePopulator(table)[source]

Bases: robot.parsing.tablepopulators._StepContainingTablePopulator

add(row)
populate()
class robot.parsing.tablepopulators.KeywordTablePopulator(table)[source]

Bases: robot.parsing.tablepopulators._StepContainingTablePopulator

add(row)
populate()
class robot.parsing.tablepopulators.ForLoopPopulator(for_loop_creator)[source]

Bases: robot.parsing.tablepopulators.Populator

add(row)[source]
populate()[source]
class robot.parsing.tablepopulators.TestCasePopulator(test_or_uk_creator)[source]

Bases: robot.parsing.tablepopulators._TestCaseUserKeywordPopulator

add(row)
populate()
class robot.parsing.tablepopulators.UserKeywordPopulator(test_or_uk_creator)[source]

Bases: robot.parsing.tablepopulators._TestCaseUserKeywordPopulator

add(row)
populate()
class robot.parsing.tablepopulators.VariablePopulator(setter, name)[source]

Bases: robot.parsing.tablepopulators._PropertyPopulator

populate()[source]
add(row)
class robot.parsing.tablepopulators.SettingPopulator(setter)[source]

Bases: robot.parsing.tablepopulators._PropertyPopulator

populate()[source]
add(row)
class robot.parsing.tablepopulators.DocumentationPopulator(setter)[source]

Bases: robot.parsing.tablepopulators._PropertyPopulator

populate()[source]
add(row)
class robot.parsing.tablepopulators.MetadataPopulator(setter)[source]

Bases: robot.parsing.tablepopulators.DocumentationPopulator

populate()[source]
add(row)
class robot.parsing.tablepopulators.StepPopulator(setter)[source]

Bases: robot.parsing.tablepopulators._PropertyPopulator

populate()[source]
add(row)

robot.parsing.tsvreader module

class robot.parsing.tsvreader.TsvReader[source]

Bases: object

read(tsvfile, populator)[source]
classmethod split_row(row)[source]

robot.parsing.txtreader module

class robot.parsing.txtreader.TxtReader[source]

Bases: robot.parsing.tsvreader.TsvReader

classmethod split_row(row)[source]
read(tsvfile, populator)