Beispiel #1
0
 def setUp(self):
     result = ExecutionResult(StringIO(GOLDEN_XML),
                              StringIO(GOLDEN_XML),
                              StringIO(GOLDEN_XML),
                              merge=True)
     self.suite = result.suite
     self.test = self.suite.tests[0]
Beispiel #2
0
 def test_rpa(self):
     rpa_false = GOLDEN_XML
     self._validate_rpa(ExecutionResult(StringIO(rpa_false)), False)
     self._validate_rpa(ExecutionResult(StringIO(rpa_false), rpa=True), True)
     rpa_true = GOLDEN_XML.replace('rpa="false"', 'rpa="true"')
     self._validate_rpa(ExecutionResult(StringIO(rpa_true)), True)
     self._validate_rpa(ExecutionResult(StringIO(rpa_true), rpa=False), False)
Beispiel #3
0
def run(suite, **config):
    result = suite.run(output=None,
                       log=None,
                       report=None,
                       stdout=StringIO(),
                       stderr=StringIO(),
                       **config)
    return result.suite
def run(suite, **kwargs):
    config = dict(output=None,
                  log=None,
                  report=None,
                  stdout=StringIO(),
                  stderr=StringIO())
    config.update(kwargs)
    result = suite.run(**config)
    return result.suite
 def _read_html(self, doctree, rawdata):
     htmlfile = StringIO()
     htmlfile.write(publish_from_doctree(
         doctree, writer_name='html',
         settings_overrides={'output_encoding': 'UTF-8'}))
     htmlfile.seek(0)
     return HtmlReader().read(htmlfile, rawdata)
Beispiel #6
0
def _handle_variables_in_expression(expression, variable_store):
    variables = None
    variable_started = False
    tokens = []
    for toknum, tokval, _, _, _ in generate_tokens(StringIO(expression).readline):
        if variable_started:
            if toknum == token.NAME:
                if variables is None:
                    variables = variable_store.as_dict(decoration=False)
                if tokval not in variables:
                    variable_not_found('$%s' % tokval, variables,
                                       deco_braces=False)
                tokval = 'RF_VAR_' + tokval
            else:
                tokens.append((token.ERRORTOKEN, '$'))
            variable_started = False
        if toknum == token.ERRORTOKEN and tokval == '$':
            variable_started = True
        else:
            tokens.append((toknum, tokval))
    if variables is None:
        return expression, {}
    expression = untokenize(tokens).strip()
    variables = VariableNamespace(variables, variable_store)
    return expression, variables
 def test_run_multiple_times_with_different_stdout_and_stderr(self):
     stdout, stderr = StringIO(), StringIO()
     self._run(stdout, stderr)
     self._assert_normal_stdout_stderr_are_empty()
     self._assert_output(stdout, [('My Suite', 2), ('My Test', 1)])
     self._assert_output(stderr, [('Hello, world!', 1)])
     stdout.close(); stderr.close()
     output = StringIO()
     self._run(output, output, variable='MESSAGE:Hi, again!')
     self._assert_normal_stdout_stderr_are_empty()
     self._assert_output(output, [('My Suite', 2), ('My Test', 1),
                                  ('Hi, again!', 1), ('Hello, world!', 0)])
     output.close()
     self._run(variable='MESSAGE:Last hi!')
     self._assert_output(sys.__stdout__, [('My Suite', 2), ('My Test', 1)])
     self._assert_output(sys.__stderr__, [('Last hi!', 1), ('Hello, world!', 0)])
 def _add_long_step_and_save(self, format):
     data = create_test_case_file()
     data.testcase_table.tests[0].add_step(
         ['A kw', '1', '2', '3', '4', '6', '7', '8'])
     output = StringIO()
     data.save(format=format, output=output)
     return output.getvalue().strip()
Beispiel #9
0
 def test_line_separator(self):
     output = StringIO()
     writer = HtmlWriter(output)
     writer.start('b')
     writer.end('b')
     writer.element('i')
     assert_equal(output.getvalue(), '<b>\n</b>\n<i></i>\n')
Beispiel #10
0
 def test_non_ascii(self):
     self.output = StringIO()
     writer = HtmlWriter(self.output)
     writer.start(u'p', attrs={'name': u'hyv\xe4\xe4'}, newline=False)
     writer.content(u'y\xf6')
     writer.element('i', u't\xe4', newline=False)
     writer.end('p', newline=False)
     self._verify(u'<p name="hyv\xe4\xe4">y\xf6<i>t\xe4</i></p>')
    def test_configuring_number_of_separating_spaces(self):
        output = StringIO()
        create_test_case_file().save(output=output, txt_separating_spaces=8)
        expected = '''\
*** test case ***         some        and other
A test                    A kw        an arg
'''
        assert_equal(output.getvalue(), expected)
    def test_end_of_line_whitespace_is_removed(self):
        output = StringIO()
        create_test_case_file().save(output=output)
        expected = '''\
*** test case ***     some    and other
A test                A kw    an arg
'''
        assert_equal(output.getvalue(), expected)
 def test_dont_register_signal_handlers_when_run_on_thread(self):
     stream = StringIO()
     thread = threading.Thread(target=run_without_outputs, args=(self.data,),
                               kwargs=dict(stdout=stream, stderr=stream))
     thread.start()
     thread.join()
     output = stream.getvalue()
     assert_true('ERROR' not in output.upper(), 'Errors:\n%s' % output)
Beispiel #14
0
 def setUp(self):
     self.result = ExecutionResult(StringIO(GOLDEN_XML))
     self.suite = self.result.suite
     self.test = self.suite.tests[0]
     self.keyword = self.test.keywords[0]
     self.user_keyword = self.test.keywords[1]
     self.message = self.keyword.messages[0]
     self.setup = self.suite.keywords[0]
     self.errors = self.result.errors
Beispiel #15
0
 def test_already_processed(self):
     inp = SUITE_TEARDOWN_FAILED.replace('generator="Robot', 'generator="Rebot')
     passed, failed, teardowns = ExecutionResult(StringIO(inp)).suite.tests
     assert_equal(passed.status, 'PASS')
     assert_equal(passed.message, '')
     assert_equal(failed.status, 'FAIL')
     assert_equal(failed.message, 'Message')
     assert_equal(teardowns.status, 'PASS')
     assert_equal(teardowns.message, '')
 def setUp(self):
     result = ExecutionResult(StringIO(GOLDEN_XML))
     self._suite = result.suite
     self._test = self._suite.tests[0]
     self._keyword = self._test.keywords[0]
     self._user_keyword = self._test.keywords[1]
     self._message = self._keyword.messages[0]
     self._setup = self._suite.keywords[0]
     self._errors = result.errors
 def __init__(self, stdout=True):
     if stdout:
         self._original = sys.stdout
         self._set_stream = self._set_stdout
     else:
         self._original = sys.stderr
         self._set_stream = self._set_stderr
     self._stream = StringIO()
     self._set_stream(self._stream)
Beispiel #18
0
 def _split(self, options):
     split_options = []
     start_position = 0
     tokens = generate_tokens(StringIO(options).readline)
     for toknum, tokval, tokpos, _, _ in tokens:
         if toknum == token.OP and tokval == ';':
             split_options.append(options[start_position:tokpos[1]])
             start_position = tokpos[1] + 1
     split_options.append(options[start_position:])
     return split_options
    def test_omit_keywords_during_xml_parsing(self):
        class NonVisitingSuite(TestSuite):
            def visit(self, visitor):
                pass

        result = Result(root_suite=NonVisitingSuite())
        builder = ExecutionResultBuilder(StringIO(GOLDEN_XML),
                                         include_keywords=False)
        builder.build(result)
        assert_equal(len(result.suite.tests[0].body), 0)
Beispiel #20
0
 def test_suite_message(self):
     xml = """
     <robot>
     <suite name="foo">
       <status status="FAIL">Setup failed</status>
     </suite>
     </robot>
     """
     suite = ExecutionResult(StringIO(xml)).suite
     assert_equal(suite.message, 'Setup failed')
 def test_excluding_keywords_and_already_processed(self):
     inp = SUITE_TEARDOWN_FAILED.replace('generator="Robot', 'generator="Rebot')
     suite = ExecutionResult(StringIO(inp), include_keywords=False).suite
     passed, failed, teardowns = suite.tests
     assert_equal(passed.status, 'PASS')
     assert_equal(passed.message, '')
     assert_equal(failed.status, 'FAIL')
     assert_equal(failed.message, 'Message')
     assert_equal(teardowns.status, 'PASS')
     assert_equal(teardowns.message, '')
     for item in suite, passed, failed, teardowns:
         assert_equal(list(item.keywords), [])
 def test_original_signal_handlers_are_restored(self):
     orig_sigint = signal.getsignal(signal.SIGINT)
     orig_sigterm = signal.getsignal(signal.SIGTERM)
     my_sigterm = lambda signum, frame: None
     signal.signal(signal.SIGTERM, my_sigterm)
     try:
         run_without_outputs(self.data, stdout=StringIO())
         assert_signal_handler_equal(signal.SIGINT, orig_sigint)
         assert_signal_handler_equal(signal.SIGTERM, my_sigterm)
     finally:
         signal.signal(signal.SIGINT, orig_sigint)
         signal.signal(signal.SIGTERM, orig_sigterm)
Beispiel #23
0
    def test_start_table(self):
        tsv = StringIO('''*SettING*\t*  Value  *\t*V*
***Variable

*Not*Table*

Keyword*\tNot a table because doesn't start with '*'

*******************T*e*s*t*********C*a*s*e************\t***********\t******\t*
''')
        TsvReader().read(tsv, FromFilePopulator(self.tcf))
        assert_equals(self.tcf.setting_table.name, 'SettING')
        assert_equals(self.tcf.setting_table.header, ['SettING', 'Value', 'V'])
Beispiel #24
0
 def test_excluding_keywords(self):
     suite = ExecutionResult(StringIO(SUITE_TEARDOWN_FAILED),
                             include_keywords=False).suite
     passed, failed, teardowns = suite.tests
     assert_equal(passed.status, 'FAIL')
     assert_equal(passed.message, 'Parent suite teardown failed:\nXXX')
     assert_equal(failed.status, 'FAIL')
     assert_equal(failed.message, 'Message\n\n'
                  'Also parent suite teardown failed:\nXXX')
     assert_equal(teardowns.status, 'FAIL')
     assert_equal(teardowns.message, 'Parent suite teardown failed:\nXXX')
     for item in suite, passed, failed, teardowns:
         assert_equal(list(item.keywords), [])
 def test_json_dump_mapping(self):
     output = StringIO()
     dumper = JsonDumper(output)
     mapped1 = object()
     mapped2 = 'string'
     dumper.dump([mapped1, [mapped2, {
         mapped2: mapped1
     }]],
                 mapping={
                     mapped1: '1',
                     mapped2: 'a'
                 })
     assert_equal(output.getvalue(), '[1,[a,{a:1}]]')
     assert_raises(ValueError, dumper.dump, [mapped1])
Beispiel #26
0
 def _parse_to_tokens(self, item):
     result = {}
     method = None
     arguments = []
     tokens = generate_tokens(StringIO(item).readline)
     for toknum, tokval, _, _, _ in tokens:
         if toknum == token.NAME and not method:
             method = tokval
         elif toknum == token.STRING:
             arguments.append(ast.literal_eval(tokval))
         elif toknum in [token.NAME, token.NUMBER] and method:
             arguments.append(ast.literal_eval(tokval))
     result[method] = arguments
     return result
Beispiel #27
0
 def test_test_message(self):
     xml = """
     <robot>
     <suite name="foo">
       <test name="test">
         <status status="FAIL">Failure message</status>
       </test>
     </suite>
     </robot>
     """
     test = ExecutionResult(StringIO(xml)).suite.tests[0]
     assert_equal(test.message, 'Failure message')
     assert_equal(test.status, 'FAIL')
     assert_equal(test.longname, 'foo.test')
def get_lines(suite=(),
              strings=(),
              basemillis=100,
              start_block='',
              end_block='',
              split_threshold=9999,
              min_level='INFO'):
    output = StringIO()
    data = JsExecutionResult(suite,
                             None,
                             None,
                             strings,
                             basemillis,
                             min_level=min_level)
    writer = JsResultWriter(output, start_block, end_block, split_threshold)
    writer.write(data, settings={})
    return output.getvalue().splitlines()
Beispiel #29
0
 def test_nested_suites(self):
     xml = """
     <robot>
     <suite name="foo">
       <suite name="bar">
         <suite name="quux">
         </suite>
       </suite>
     </suite>
     </robot>
     """
     suite = ExecutionResult(StringIO(xml)).suite
     assert_equal(suite.name, 'foo')
     assert_equal(suite.suites[0].name, 'bar')
     assert_equal(suite.longname, 'foo')
     assert_equal(suite.suites[0].longname, 'foo.bar')
     assert_equal(suite.suites[0].suites[0].name, 'quux')
     assert_equal(suite.suites[0].suites[0].longname, 'foo.bar.quux')
Beispiel #30
0
    def test_rows(self):
        tsv = StringIO('''Ignored text before tables...
Mote\tignored\text
*Setting*\t*Value*\t*Value*
Document\tWhatever\t\t\\\t
Default Tags\tt1\tt2\tt3\t\t

*Variable*\tWhatever
\\ \\ 2 escaped spaces before and after \\ \\\t\\ \\ value \\ \\

''')
        TsvReader().read(tsv, FromFilePopulator(self.tcf))
        assert_equals(self.tcf.setting_table.doc.value, 'Whatever  ')
        assert_equals(self.tcf.setting_table.default_tags.value,
                      ['t1', 't2', 't3'])
        assert_equals(self.tcf.variable_table.variables[0].name,
                      '\\ \\ 2 escaped spaces before and after \\ \\')
        assert_equals(self.tcf.variable_table.variables[0].value,
                      ['\\ \\ value \\ \\'])