23 from .datarow
import DataRow
24 from .tablepopulators
import (SettingTablePopulator, VariableTablePopulator,
25 TestTablePopulator, KeywordTablePopulator,
27 from .htmlreader
import HtmlReader
28 from .tsvreader
import TsvReader
29 from .robotreader
import RobotReader
30 from .restreader
import RestReader
33 READERS = {
'html': HtmlReader,
'htm': HtmlReader,
'xhtml': HtmlReader,
34 'tsv': TsvReader ,
'rst': RestReader,
'rest': RestReader,
35 'txt': RobotReader,
'robot': RobotReader}
49 _populators = {
'setting': SettingTablePopulator,
50 'variable': VariableTablePopulator,
51 'test case': TestTablePopulator,
52 'test cases': TestTablePopulator,
53 'task': TestTablePopulator,
54 'tasks': TestTablePopulator,
55 'keyword': KeywordTablePopulator}
64 return path.replace(
'\\',
'\\\\')
if path
else None
70 LOGGER.info(
"Parsing file '%s'." % path)
71 source = self.
_open_open(path)
74 self.
_get_reader_get_reader(path, resource).read(source, self)
82 if not os.path.isfile(path):
83 raise DataError(
"File or directory to execute does not exist.")
87 return open(path,
'rb')
92 file_format = os.path.splitext(path.lower())[-1][1:]
93 if resource
and file_format ==
'resource':
96 return READERS[file_format](self.
_tab_size_tab_size)
98 raise DataError(
"Unsupported file format '%s'." % file_format)
114 if PROCESS_CURDIR
and self.
_curdir_curdir:
122 old, new =
'${CURDIR}', self.
_curdir_curdir
123 return [cell
if old
not in cell
else cell.replace(old, new)
128 ignored_prefixes = (
'_',
'.')
129 ignored_dirs = (
'CVS',)
131 def populate(self, path, datadir, include_suites=None,
132 include_extensions=None, recurse=True, tab_size=2):
133 LOGGER.info(
"Parsing directory '%s'." % path)
135 init_file, children = self.
_get_children_get_children(path, include_extensions,
141 include_suites, tab_size)
144 datadir.initfile = init_file
147 except DataError
as err:
148 LOGGER.error(err.message)
151 include_suites, tab_size):
152 for child
in children:
154 datadir.add_child(child, include_suites, include_extensions)
156 LOGGER.info(
"Data source '%s' has no tests or tasks." % child)
157 except DataError
as err:
158 LOGGER.error(
"Parsing '%s' failed: %s" % (child, err.message))
163 if not isinstance(incl_suites, SuiteNamePatterns):
172 for suite
in incl_suites:
175 suite = suite.split(
'.', 1)[1]
181 for path, is_init_file
in self.
_list_dir_list_dir(dirpath, incl_extensions,
187 LOGGER.error(
"Ignoring second test suite init file '%s'." % path)
189 children.append(path)
190 return init_file, children
192 def _list_dir(self, dir_path, incl_extensions, incl_suites):
194 dir_path =
unic(dir_path)
195 names = os.listdir(dir_path)
196 for name
in sorted(names, key=
lambda item: item.lower()):
198 path = os.path.join(dir_path, name)
199 base, ext = os.path.splitext(name)
200 ext = ext[1:].
lower()
201 if self.
_is_init_file_is_init_file(path, base, ext, incl_extensions):
203 elif self.
_is_included_is_included(path, base, ext, incl_extensions, incl_suites):
206 LOGGER.info(
"Ignoring file or directory '%s'." % path)
209 return (base.lower() ==
'__init__' and
211 os.path.isfile(path))
215 return ext
in incl_extensions
216 return ext
in READERS
221 if os.path.isdir(path):
230 return incl_suites.match(self.
_split_prefix_split_prefix(name))
233 return name.split(
'__', 1)[-1]
Used when variable does not exist.
def _get_include_suites(self, path, incl_suites)
def _is_in_included_suites(self, name, incl_suites)
def _create_included_suites(self, incl_suites)
def _populate_init_file(self, datadir, init_file, tab_size)
def _is_included(self, path, base, ext, incl_extensions, incl_suites)
def _list_dir(self, dir_path, incl_extensions, incl_suites)
def populate(self, path, datadir, include_suites=None, include_extensions=None, recurse=True, tab_size=2)
def _split_prefix(self, name)
def _populate_children(self, datadir, children, include_extensions, include_suites, tab_size)
def _extension_is_accepted(self, ext, incl_extensions)
def _is_init_file(self, path, base, ext, incl_extensions)
def _get_children(self, dirpath, incl_extensions, incl_suites)
def _get_curdir(self, path)
def start_table(self, header)
def populate(self, path, resource=False)
def _replace_curdirs_in(self, row)
def _get_reader(self, path, resource=False)
def add_preamble(self, row)
def __init__(self, datafile, tab_size=2)
def get_error_message()
Returns error message of the last occurred exception.