Skip to content

Commit 601b7c9

Browse files
committed
Set rpa mode correctly
1 parent ad11854 commit 601b7c9

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/robot/parsing/newparser/nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def __init__(self, variables):
2929
class TestCaseSection(Node):
3030
_fields = ('tests',)
3131

32-
def __init__(self, tests):
32+
def __init__(self, tests, header):
3333
self.tests = tests
34+
self.header = header[0].strip("*").strip()
3435

3536

3637
class KeywordSection(Node):

src/robot/parsing/newparser/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,12 @@ def p_variable(self, p):
173173
def p_testcase_section(self, p):
174174
'''testcase_section : testcase_header EOS
175175
| testcase_header EOS tests'''
176-
p[0] = TestCaseSection(p[3] if len(p) == 4 else [])
176+
p[0] = TestCaseSection(p[3] if len(p) == 4 else [], p[1])
177177

178178
def p_testcase_header(self, p):
179179
'''testcase_header : TESTCASE_HEADER
180180
| testcase_header TESTCASE_HEADER'''
181+
append_to_list_value(p)
181182

182183
def p_keyword_section(self, p):
183184
'''keyword_section : keyword_header EOS

src/robot/running/newbuilder.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from robot.errors import DataError
66
from robot.parsing import TEST_EXTENSIONS
77
from robot.parsing.newparser import builder
8+
from robot.parsing.newparser.nodes import TestCaseSection
89
from robot.model import SuiteNamePatterns
910
from robot.running.model import TestSuite, Keyword, ForLoop, ResourceFile
1011
from robot.utils import abspath
1112
from robot.variables import VariableIterator
1213
from robot.output import LOGGER
13-
from robot.utils import get_error_message, unic
14+
from robot.utils import normalize, unic
1415

1516

1617
def create_fixture(data, type):
@@ -329,6 +330,7 @@ class TestSuiteBuilder(object):
329330

330331
def __init__(self, include_suites=None, extension=None, rpa=None):
331332
self.rpa = rpa
333+
self._rpa_not_given = rpa is None
332334
self.include_suites = include_suites
333335
self.extension = extension
334336

@@ -372,11 +374,15 @@ def _parse_and_build(self, path, parent_defaults=None, include_suites=None, incl
372374
else:
373375
LOGGER.info("Parsing file '%s'." % path)
374376
suite, _ = self._build_suite(path, name, parent_defaults)
377+
suite.rpa = self.rpa
375378
suite.remove_empty_suites()
376379
return suite
377380

378381
def _build_suite(self, source, name, parent_defaults):
379382
data = self._parse(source)
383+
test_section = self._get_test_section(data)
384+
if self._rpa_not_given and test_section:
385+
self._set_execution_mode(test_section, source)
380386
suite = TestSuite(name=name, source=source)
381387
defaults = TestDefaults(parent_defaults)
382388
if data:
@@ -385,6 +391,22 @@ def _build_suite(self, source, name, parent_defaults):
385391
SuiteBuilder(suite, defaults).visit(data)
386392
return suite, defaults
387393

394+
def _get_test_section(self, data):
395+
test_sections = [s for s in data.sections if isinstance(s, TestCaseSection)]
396+
return test_sections[0] if test_sections else None
397+
398+
def _set_execution_mode(self, test_section, source):
399+
rpa = test_section.header.lower() in ('task', 'tasks')
400+
if self.rpa is None:
401+
self.rpa = rpa
402+
elif self.rpa is not rpa:
403+
this, that = ('tasks', 'tests') if rpa else ('tests', 'tasks')
404+
raise DataError("Conflicting execution modes. File '%s' has %s "
405+
"but files parsed earlier have %s. Fix headers "
406+
"or use '--rpa' or '--norpa' options to set the "
407+
"execution mode explicitly."
408+
% (source, this, that))
409+
388410
def _parse(self, path):
389411
try:
390412
return builder.get_test_case_file_ast(path)

0 commit comments

Comments
 (0)