def test_eq(self):
     error = subunit.RemoteError(_u("Something went wrong"))
     another_error = subunit.RemoteError(_u("Something went wrong"))
     different_error = subunit.RemoteError(_u("boo!"))
     self.assertEqual(error, another_error)
     self.assertNotEqual(error, different_error)
     self.assertNotEqual(different_error, another_error)
Esempio n. 2
0
 def check_success_or_xfail(self, as_success, error_message=None):
     if as_success:
         self.assertEqual([
             ('startTest', self.test),
             ('addSuccess', self.test),
             ('stopTest', self.test),
         ], self.client._events)
     else:
         details = {}
         if error_message is not None:
             details['traceback'] = Content(
                 ContentType("text", "x-traceback", {'charset': 'utf8'}),
                 lambda: [_b(error_message)])
         if isinstance(self.client, ExtendedTestResult):
             value = details
         else:
             if error_message is not None:
                 value = subunit.RemoteError(
                     _u("Text attachment: traceback\n"
                        "------------\n") + _u(error_message) +
                     _u("------------\n"))
             else:
                 value = subunit.RemoteError()
         self.assertEqual([
             ('startTest', self.test),
             ('addExpectedFailure', self.test, value),
             ('stopTest', self.test),
         ], self.client._events)
Esempio n. 3
0
 def test_describe_non_ascii_unicode(self):
     string = _u("A\xA7")
     suffix = _u("B\xA7")
     mismatch = DoesNotEndWith(string, suffix)
     self.assertEqual(
         "%s does not end with %s." %
         (text_repr(string), text_repr(suffix)), mismatch.describe())
Esempio n. 4
0
 def test_eq(self):
     error = subunit.RemoteError(_u("Something went wrong"))
     another_error = subunit.RemoteError(_u("Something went wrong"))
     different_error = subunit.RemoteError(_u("boo!"))
     self.assertEqual(error, another_error)
     self.assertNotEqual(error, different_error)
     self.assertNotEqual(different_error, another_error)
Esempio n. 5
0
 def test_four_tests_in_a_row_with_plan(self):
     # A file
     # 1..4
     # ok 1 - first test in a script with no plan at all
     # not ok 2 - second
     # ok 3 - third
     # not ok 4 - fourth
     # results in four tests numbered and named
     self.tap.write(_u('1..4\n'))
     self.tap.write(_u('ok 1 - first test in a script with a plan\n'))
     self.tap.write(_u('not ok 2 - second\n'))
     self.tap.write(_u('ok 3 - third\n'))
     self.tap.write(_u('not ok 4 - fourth\n'))
     self.tap.seek(0)
     result = subunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.check_events([
         ('status', 'test 1 - first test in a script with a plan',
          'success', None, False, None, None, True, None, None, None),
         ('status', 'test 2 - second', 'fail', None, False, None, None,
          True, None, None, None),
         ('status', 'test 3 - third', 'success', None, False, None, None,
          True, None, None, None),
         ('status', 'test 4 - fourth', 'fail', None, False, None, None,
          True, None, None, None)])
Esempio n. 6
0
    def output_error(self, error_tuple):
        if 'TESTR_PDB' in os.environ:
            import traceback
            self._stderr.write(
                _u('').join(traceback.format_tb(error_tuple[2])))
            self._stderr.write(_u('\n'))
            # This is terrible: it is because on Python2.x pdb writes bytes to
            # its pipes, and the test suite uses io.StringIO that refuse bytes.
            import pdb
            if sys.version_info[0] == 2:
                if isinstance(self._stdout, io.StringIO):
                    write = self._stdout.write

                    def _write(text):
                        return write(text.decode('utf8'))

                    self._stdout.write = _write
            p = pdb.Pdb(stdin=self._stdin, stdout=self._stdout)
            p.reset()
            p.interaction(None, error_tuple[2])
        error_type = str(error_tuple[1])
        # XX: Python2.
        if type(error_type) is bytes:
            error_type = error_type.decode('utf8')
        self._stderr.write(error_type + _u('\n'))
Esempio n. 7
0
 def test_four_tests_in_a_row_no_plan(self):
     # A file
     # ok 1 - first test in a script with no plan at all
     # not ok 2 - second
     # ok 3 - third
     # not ok 4 - fourth
     # results in four tests numbered and named
     self.tap.write(
         compat._u('ok 1 - first test in a script with no plan at all\n'))
     self.tap.write(compat._u('not ok 2 - second\n'))
     self.tap.write(compat._u('ok 3 - third\n'))
     self.tap.write(compat._u('not ok 4 - fourth\n'))
     self.tap.seek(0)
     result = pysubunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.check_events([
         ('status', 'test 1 - first test in a script with no plan at all',
          'success', None, False, None, None, True, None, None, None),
         ('status', 'test 2 - second', 'fail', None, False, None, None,
          True, None, None, None),
         ('status', 'test 3 - third', 'success', None, False, None, None,
          True, None, None, None),
         ('status', 'test 4 - fourth', 'fail', None, False, None, None,
          True, None, None, None)
     ])
Esempio n. 8
0
 def test_describe_non_ascii_unicode(self):
     string = _u("A\xA7")
     suffix = _u("B\xA7")
     mismatch = DoesNotEndWith(string, suffix)
     self.assertEqual("%s does not end with %s." % (
         text_repr(string), text_repr(suffix)),
         mismatch.describe())
 def check_success_or_xfail(self, as_success, error_message=None):
     if as_success:
         self.assertEqual([
             ('startTest', self.test),
             ('addSuccess', self.test),
             ('stopTest', self.test),
             ], self.client._events)
     else:
         details = {}
         if error_message is not None:
             details['traceback'] = Content(
                 ContentType("text", "x-traceback", {'charset': 'utf8'}),
                 lambda:[_b(error_message)])
         if isinstance(self.client, ExtendedTestResult):
             value = details
         else:
             if error_message is not None:
                 value = subunit.RemoteError(_u("Text attachment: traceback\n"
                     "------------\n") + _u(error_message) +
                     _u("------------\n"))
             else:
                 value = subunit.RemoteError()
         self.assertEqual([
             ('startTest', self.test),
             ('addExpectedFailure', self.test, value),
             ('stopTest', self.test),
             ], self.client._events)
Esempio n. 10
0
 def test_supports_syntax_error(self):
     self._assert_exception_format(
         SyntaxError,
         SyntaxError("Some Syntax Message", ("/path/to/file", 12, 2, "This is the line of code")),
         [
             _u('  File "/path/to/file", line 12\n'),
             _u("    This is the line of code\n"),
             _u("     ^\n"),
             _u("SyntaxError: Some Syntax Message\n"),
         ],
     )
Esempio n. 11
0
 def _format_error(self, label, test, error_text, test_tags=None):
     test_tags = test_tags or ()
     tags = _u(' ').join(test_tags)
     if tags:
         tags = _u('tags: %s\n') % tags
     return _u('').join([
         self.sep1,
         _u('%s: %s\n') % (label, test.id()),
         tags,
         self.sep2,
         error_text,
     ])
Esempio n. 12
0
 def test_individual_functions_called(self):
     self.patch(testtools.compat, "_format_stack_list", lambda stack_list: [_u("format stack list called\n")])
     self.patch(
         testtools.compat, "_format_exception_only", lambda etype, evalue: [_u("format exception only called\n")]
     )
     result = _format_exc_info(None, None, None)
     expected = [
         _u("Traceback (most recent call last):\n"),
         _u("format stack list called\n"),
         _u("format exception only called\n"),
     ]
     self.assertThat(expected, Equals(result))
Esempio n. 13
0
 def _format_error(self, label, test, error_text, test_tags=None):
     test_tags = test_tags or ()
     tags = _u(' ').join(test_tags)
     if tags:
         tags = _u('tags: %s\n') % tags
     return _u('').join([
         self.sep1,
         _u('%s: %s\n') % (label, test.id()),
         tags,
         self.sep2,
         error_text,
         ])
Esempio n. 14
0
 def test_assertThat_verbose_unicode(self):
     # When assertThat is given matchees or matchers that contain non-ASCII
     # unicode strings, we can still provide a meaningful error.
     matchee = _u("\xa7")
     matcher = Equals(_u("a"))
     expected = (
         "Match failed. Matchee: %s\n"
         "Matcher: %s\n"
         "Difference: %s\n\n" % (repr(matchee).replace("\\xa7", matchee), matcher, matcher.match(matchee).describe())
     )
     e = self.assertRaises(self.failureException, self.assertThat, matchee, matcher, verbose=True)
     self.assertEqual(expected, self.get_error_string(e))
Esempio n. 15
0
 def test_bail_out_errors(self):
     # A file with line in it
     # Bail out! COMMENT
     # is treated as an error
     self.tap.write(compat._u("ok 1 foo\n"))
     self.tap.write(compat._u("Bail out! Lifejacket engaged\n"))
     self.tap.seek(0)
     result = pysubunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.check_events([('status', 'test 1 foo', 'success', None, False,
                         None, None, True, None, None, None),
                        ('status', 'Bail out! Lifejacket engaged', 'fail',
                         None, False, None, None, True, None, None, None)])
Esempio n. 16
0
 def test_individual_functions_called(self):
     self.patch(testtools.compat, '_format_stack_list',
                lambda stack_list: [_u("format stack list called\n")])
     self.patch(
         testtools.compat, '_format_exception_only',
         lambda etype, evalue: [_u("format exception only called\n")])
     result = _format_exc_info(None, None, None)
     expected = [
         _u("Traceback (most recent call last):\n"),
         _u("format stack list called\n"),
         _u("format exception only called\n"),
     ]
     self.assertThat(expected, Equals(result))
Esempio n. 17
0
 def test_syntax_error_line_utf_8(self):
     """Syntax error on a utf-8 line shows the line decoded"""
     text, raw = self._get_sample_text("utf-8")
     textoutput = self._setup_external_case("import bad")
     self._write_module("bad", "utf-8", _u("\ufeff^ = 0 # %s\n") % text)
     textoutput = self._run_external_case()
     self.assertIn(self._as_output(_u(
         'bad.py", line 1\n'
         '    ^ = 0 # %s\n'
         + ' ' * self._error_on_character +
         '   ^\n'
         'SyntaxError: ') %
         text), textoutput)
 def test_syntax_error_line_utf_8(self):
     """Syntax error on a utf-8 line shows the line decoded"""
     text, raw = self._get_sample_text("utf-8")
     textoutput = self._setup_external_case("import bad")
     self._write_module("bad", "utf-8", _u("\ufeff^ = 0 # %s\n") % text)
     textoutput = self._run_external_case()
     self.assertIn(self._as_output(_u(
         'bad.py", line 1\n'
         '    ^ = 0 # %s\n'
         + ' ' * self._error_on_character +
         '   ^\n'
         'SyntaxError: ') %
         text), textoutput)
Esempio n. 19
0
    def test_broken_runner(self):
        # If the object called breaks, the stream is informed about it
        # regardless.
        class BrokenTest(object):
            # broken - no result parameter!
            def __call__(self):
                pass

            def run(self):
                pass

        result = LoggingStream()
        cases = lambda: [(BrokenTest(), '0')]
        suite = ConcurrentStreamTestSuite(cases)
        suite.run(result)
        events = result._events
        # Check the traceback loosely.
        self.assertEqual(events[1][6].decode('utf8'),
                         "Traceback (most recent call last):\n")
        self.assertThat(
            events[2][6].decode('utf8'),
            DocTestMatches(
                """\
  File "...testtools/testsuite.py", line ..., in _run_test
    test.run(process_result)
""", doctest.ELLIPSIS))
        self.assertThat(
            events[3][6].decode('utf8'),
            DocTestMatches(
                """\
TypeError: run() takes ...1 ...argument...2...given...
""", doctest.ELLIPSIS))
        events = [event[0:10] + (None, ) for event in events]
        events[1] = events[1][:6] + (None, ) + events[1][7:]
        events[2] = events[2][:6] + (None, ) + events[2][7:]
        events[3] = events[3][:6] + (None, ) + events[3][7:]
        self.assertEqual([
            ('status', "broken-runner-'0'", 'inprogress', None, True, None,
             None, False, None, _u('0'), None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback',
             None, False,
             'text/x-traceback; charset="utf8"; language="python"', '0', None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback',
             None, False,
             'text/x-traceback; charset="utf8"; language="python"', '0', None),
            ('status', "broken-runner-'0'", None, None, True, 'traceback',
             None, True, 'text/x-traceback; charset="utf8"; language="python"',
             '0', None),
            ('status', "broken-runner-'0'", 'fail', set(), True, None, None,
             False, None, _u('0'), None)
        ], events)
Esempio n. 20
0
 def test_supports_syntax_error(self):
     self._assert_exception_format(
         SyntaxError,
         SyntaxError("Some Syntax Message", (
             "/path/to/file",
             12,
             2,
             "This is the line of code",
         )), [
             _u('  File "/path/to/file", line 12\n'),
             _u('    This is the line of code\n'),
             _u('     ^\n'),
             _u('SyntaxError: Some Syntax Message\n'),
         ])
Esempio n. 21
0
 def _check_cmd(self):
     parser = get_command_parser(self.cmd)
     parser.add_option(
         "-d",
         "--here",
         dest="here",
         help="Set the directory or url that a command should run from. "
         "This affects all default path lookups but does not affect paths "
         "supplied to the command.",
         default=os.getcwd(),
         type=str)
     parser.add_option(
         "-q",
         "--quiet",
         action="store_true",
         default=False,
         help="Turn off output other than the primary output for a command "
         "and any errors.")
     # yank out --, as optparse makes it silly hard to just preserve it.
     try:
         where_dashdash = self._argv.index('--')
         opt_argv = self._argv[:where_dashdash]
         other_args = self._argv[where_dashdash:]
     except ValueError:
         opt_argv = self._argv
         other_args = []
     if '-h' in opt_argv or '--help' in opt_argv or '-?' in opt_argv:
         self.output_rest(parser.format_help())
         # Fugly, but its what optparse does: we're just overriding the
         # output path.
         raise SystemExit(0)
     options, args = parser.parse_args(opt_argv)
     args += other_args
     self.here = options.here
     self.options = options
     parsed_args = {}
     failed = False
     for arg in self.cmd.args:
         try:
             parsed_args[arg.name] = arg.parse(args)
         except ValueError:
             exc_info = sys.exc_info()
             failed = True
             self._stderr.write(_u("%s\n") % str(exc_info[1]))
             break
     if not failed:
         self.arguments = parsed_args
         if args != []:
             self._stderr.write(_u("Unexpected arguments: %r\n") % args)
     return not failed and args == []
Esempio n. 22
0
 def __init__(self, ui, get_id, stream, previous_run=None, filter_tags=None):
     """Construct a CLITestResult writing to stream.
     
     :param filter_tags: Tags that should be used to filter tests out. When
         a tag in this set is present on a test outcome, the test is not
         counted towards the test run count. If the test errors, then it is
         still counted and the error is still shown.
     """
     super(CLITestResult, self).__init__(ui, get_id, previous_run)
     self.stream = unicode_output_stream(stream)
     self.sep1 = _u('=' * 70 + '\n')
     self.sep2 = _u('-' * 70 + '\n')
     self.filter_tags = filter_tags or frozenset()
     self.filterable_states = set(['success', 'uxsuccess', 'xfail', 'skip'])
Esempio n. 23
0
 def __init__(self, ui, get_id, stream, previous_run=None, filter_tags=None):
     """Construct a CLITestResult writing to stream.
     
     :param filter_tags: Tags that should be used to filter tests out. When
         a tag in this set is present on a test outcome, the test is not
         counted towards the test run count. If the test errors, then it is
         still counted and the error is still shown.
     """
     super(CLITestResult, self).__init__(ui, get_id, previous_run)
     self.stream = unicode_output_stream(stream)
     self.sep1 = _u('=' * 70 + '\n')
     self.sep2 = _u('-' * 70 + '\n')
     self.filter_tags = filter_tags or frozenset()
     self.filterable_states = set(['success', 'uxsuccess', 'xfail', 'skip'])
Esempio n. 24
0
 def test_bail_out_errors(self):
     # A file with line in it
     # Bail out! COMMENT
     # is treated as an error
     self.tap.write(_u("ok 1 foo\n"))
     self.tap.write(_u("Bail out! Lifejacket engaged\n"))
     self.tap.seek(0)
     result = subunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.check_events([
         ('status', 'test 1 foo', 'success', None, False, None, None, True,
          None, None, None),
         ('status', 'Bail out! Lifejacket engaged', 'fail', None, False,
          None, None, True, None, None, None)])
Esempio n. 25
0
 def __init__(self, parser):
     self.parser = parser
     self._test_sym = (_b('test'), _b('testing'))
     self._colon_sym = _b(':')
     self._error_sym = (_b('error'),)
     self._failure_sym = (_b('failure'),)
     self._progress_sym = (_b('progress'),)
     self._skip_sym = _b('skip')
     self._success_sym = (_b('success'), _b('successful'))
     self._tags_sym = (_b('tags'),)
     self._time_sym = (_b('time'),)
     self._xfail_sym = (_b('xfail'),)
     self._uxsuccess_sym = (_b('uxsuccess'),)
     self._start_simple = _u(" [")
     self._start_multipart = _u(" [ multipart")
Esempio n. 26
0
 def __init__(self, parser):
     self.parser = parser
     self._test_sym = (_b("test"), _b("testing"))
     self._colon_sym = _b(":")
     self._error_sym = (_b("error"),)
     self._failure_sym = (_b("failure"),)
     self._progress_sym = (_b("progress"),)
     self._skip_sym = _b("skip")
     self._success_sym = (_b("success"), _b("successful"))
     self._tags_sym = (_b("tags"),)
     self._time_sym = (_b("time"),)
     self._xfail_sym = (_b("xfail"),)
     self._uxsuccess_sym = (_b("uxsuccess"),)
     self._start_simple = _u(" [")
     self._start_multipart = _u(" [ multipart")
Esempio n. 27
0
 def test_stream_content_reset(self):
     detail_name = 'test'
     fixture = StringStream(detail_name)
     with fixture:
         stream = fixture.stream
         content = fixture.getDetails()[detail_name]
         stream.write(_u("testing 1 2 3"))
     with fixture:
         # The old content object returns the old usage
         self.assertEqual(_u("testing 1 2 3"), content.as_text())
         content = fixture.getDetails()[detail_name]
         # A new fixture returns the new output:
         stream = fixture.stream
         stream.write(_u("1 2 3 testing"))
         self.assertEqual(_u("1 2 3 testing"), content.as_text())
Esempio n. 28
0
 def test_stream_content_reset(self):
     detail_name = 'test'
     fixture = StringStream(detail_name)
     with fixture:
         stream = fixture.stream
         content = fixture.getDetails()[detail_name]
         stream.write(_u("testing 1 2 3"))
     with fixture:
         # The old content object returns the old usage
         self.assertEqual(_u("testing 1 2 3"), content.as_text())
         content = fixture.getDetails()[detail_name]
         # A new fixture returns the new output:
         stream = fixture.stream
         stream.write(_u("1 2 3 testing"))
         self.assertEqual(_u("1 2 3 testing"), content.as_text())
Esempio n. 29
0
 def __init__(self, parser):
     self.parser = parser
     self._test_sym = (_b('test'), _b('testing'))
     self._colon_sym = _b(':')
     self._error_sym = (_b('error'),)
     self._failure_sym = (_b('failure'),)
     self._progress_sym = (_b('progress'),)
     self._skip_sym = _b('skip')
     self._success_sym = (_b('success'), _b('successful'))
     self._tags_sym = (_b('tags'),)
     self._time_sym = (_b('time'),)
     self._xfail_sym = (_b('xfail'),)
     self._uxsuccess_sym = (_b('uxsuccess'),)
     self._start_simple = _u(" [")
     self._start_multipart = _u(" [ multipart")
Esempio n. 30
0
class TestDocTestMatchesInterfaceUnicode(TestCase, TestMatchersInterface):

    matches_matcher = DocTestMatches(_u("\xa7..."), doctest.ELLIPSIS)
    matches_matches = [_u("\xa7"), _u("\xa7 more\n")]
    matches_mismatches = ["\\xa7", _u("more \xa7"), _u("\n\xa7")]

    str_examples = [
        ("DocTestMatches(%r)" % (_u("\xa7\n"), ), DocTestMatches(_u("\xa7"))),
    ]

    describe_examples = [(_u("Expected:\n    \xa7\nGot:\n    a\n"), "a",
                          DocTestMatches(_u("\xa7"), doctest.ELLIPSIS))]
Esempio n. 31
0
 def _handleTime(self, offset, line):
     # Accept it, but do not do anything with it yet.
     try:
         event_time = iso8601.parse_date(line[offset:-1])
     except TypeError:
         raise TypeError(_u("Failed to parse %r, got %r") % (line, sys.exec_info[1]))
     self.client.time(event_time)
Esempio n. 32
0
 def test_supports_strange_syntax_error(self):
     """Test support for syntax errors with unusual number of arguments"""
     self._assert_exception_format(
         SyntaxError,
         SyntaxError("Message"),
         [_u("SyntaxError: Message\n")]
     )
 def test_addSkip_is_success(self):
     # addSkip does not fail the test run.
     result = self.makeResult()
     result.startTest(self)
     result.addSkip(self, _u("Skipped for some reason"))
     result.stopTest(self)
     self.assertTrue(result.wasSuccessful())
Esempio n. 34
0
 def test_add_failure(self):
     """Test addFailure on a TestProtocolClient."""
     self.protocol.addFailure(self.test, subunit.RemoteError(_u("boo qux")))
     self.assertEqual(
         self.io.getvalue(),
         _b(('failure: %s [\n' + _remote_exception_str + ': boo qux\n]\n') %
            self.test.id()))
Esempio n. 35
0
    def test_useFixture_details_captured(self):
        class DetailsFixture(fixtures.Fixture):
            def setUp(self):
                fixtures.Fixture.setUp(self)
                self.addCleanup(delattr, self, 'content')
                self.content = [_b('content available until cleanUp')]
                self.addDetail(
                    'content',
                    content.Content(content_type.UTF8_TEXT, self.get_content))

            def get_content(self):
                return self.content

        fixture = DetailsFixture()

        class SimpleTest(TestCase):
            def test_foo(self):
                self.useFixture(fixture)
                # Add a colliding detail (both should show up)
                self.addDetail(
                    'content',
                    content.Content(content_type.UTF8_TEXT,
                                    lambda: [_b('foo')]))

        result = ExtendedTestResult()
        SimpleTest('test_foo').run(result)
        self.assertEqual('addSuccess', result._events[-2][0])
        details = result._events[-2][2]
        self.assertEqual(['content', 'content-1'], sorted(details.keys()))
        self.assertEqual('foo', _u('').join(details['content'].iter_text()))
        self.assertEqual('content available until cleanUp',
                         ''.join(details['content-1'].iter_text()))
Esempio n. 36
0
 def run(self, result=None):
     if result is None:
         result = self.defaultTestResult()
     result.startTest(self)
     result.addError(
         self, RemoteError(compat._u("Cannot run RemotedTestCases.\n")))
     result.stopTest(self)
Esempio n. 37
0
 def _format_summary(self, successful, tests, tests_delta, time, time_delta,
                     values):
     # We build the string by appending to a list of strings and then
     # joining trivially at the end. Avoids expensive string concatenation.
     summary = []
     a = summary.append
     if tests:
         a("Ran %s" % (tests, ))
         if tests_delta:
             a(" (%+d)" % (tests_delta, ))
         a(" tests")
     if time:
         if not summary:
             a("Ran tests")
         a(" in %0.3fs" % (time, ))
         if time_delta:
             a(" (%+0.3fs)" % (time_delta, ))
     if summary:
         a("\n")
     if successful:
         a('PASSED')
     else:
         a('FAILED')
     if values:
         a(' (')
         values_strings = []
         for name, value, delta in values:
             value_str = '%s=%s' % (name, value)
             if delta:
                 value_str += ' (%+d)' % (delta, )
             values_strings.append(value_str)
         a(', '.join(values_strings))
         a(')')
     return _u('').join(summary)
Esempio n. 38
0
class Test_BinaryMismatch(TestCase):
    """Mismatches from binary comparisons need useful describe output"""

    _long_string = "This is a longish multiline non-ascii string\n\xa7"
    _long_b = _b(_long_string)
    _long_u = _u(_long_string)

    class CustomRepr(object):
        def __init__(self, repr_string):
            self._repr_string = repr_string

        def __repr__(self):
            return _u('<object ') + _u(self._repr_string) + _u('>')

    def test_short_objects(self):
        o1, o2 = self.CustomRepr('a'), self.CustomRepr('b')
        mismatch = _BinaryMismatch(o1, "!~", o2)
        self.assertEqual(mismatch.describe(), "%r !~ %r" % (o1, o2))

    def test_short_mixed_strings(self):
        b, u = _b("\xa7"), _u("\xa7")
        mismatch = _BinaryMismatch(b, "!~", u)
        self.assertEqual(mismatch.describe(), "%r !~ %r" % (b, u))

    def test_long_bytes(self):
        one_line_b = self._long_b.replace(_b("\n"), _b(" "))
        mismatch = _BinaryMismatch(one_line_b, "!~", self._long_b)
        self.assertEqual(
            mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
            ("!~", text_repr(one_line_b),
             text_repr(self._long_b, multiline=True)))

    def test_long_unicode(self):
        one_line_u = self._long_u.replace("\n", " ")
        mismatch = _BinaryMismatch(one_line_u, "!~", self._long_u)
        self.assertEqual(
            mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
            ("!~", text_repr(one_line_u),
             text_repr(self._long_u, multiline=True)))

    def test_long_mixed_strings(self):
        mismatch = _BinaryMismatch(self._long_b, "!~", self._long_u)
        self.assertEqual(
            mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
            ("!~", text_repr(self._long_b, multiline=True),
             text_repr(self._long_u, multiline=True)))

    def test_long_bytes_and_object(self):
        obj = object()
        mismatch = _BinaryMismatch(self._long_b, "!~", obj)
        self.assertEqual(
            mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
            ("!~", text_repr(self._long_b, multiline=True), repr(obj)))

    def test_long_unicode_and_object(self):
        obj = object()
        mismatch = _BinaryMismatch(self._long_u, "!~", obj)
        self.assertEqual(
            mismatch.describe(), "%s:\nreference = %s\nactual    = %s\n" %
            ("!~", text_repr(self._long_u, multiline=True), repr(obj)))
Esempio n. 39
0
 def test_addSkip_is_success(self):
     # addSkip does not fail the test run.
     result = self.makeResult()
     result.startTest(self)
     result.addSkip(self, _u("Skipped for some reason"))
     result.stopTest(self)
     self.assertTrue(result.wasSuccessful())
Esempio n. 40
0
 def status(self,
            test_id=None,
            test_status=None,
            test_tags=None,
            runnable=True,
            file_name=None,
            file_bytes=None,
            eof=False,
            mime_type=None,
            route_code=None,
            timestamp=None):
     super(CLITestResult, self).status(test_id=test_id,
                                       test_status=test_status,
                                       test_tags=test_tags,
                                       runnable=runnable,
                                       file_name=file_name,
                                       file_bytes=file_bytes,
                                       eof=eof,
                                       mime_type=mime_type,
                                       route_code=route_code,
                                       timestamp=timestamp)
     if test_status == 'fail':
         self.stream.write(
             self._format_error(_u('FAIL'),
                                *(self._summary.errors[-1]),
                                test_tags=test_tags))
     if test_status not in self.filterable_states:
         return
     if test_tags and test_tags.intersection(self.filter_tags):
         self._summary.testsRun -= 1
Esempio n. 41
0
 def _format_summary(self, successful, tests, tests_delta,
                     time, time_delta, values):
     # We build the string by appending to a list of strings and then
     # joining trivially at the end. Avoids expensive string concatenation.
     summary = []
     a = summary.append
     if tests:
         a("Ran %s" % (tests,))
         if tests_delta:
             a(" (%+d)" % (tests_delta,))
         a(" tests")
     if time:
         if not summary:
             a("Ran tests")
         a(" in %0.3fs" % (time,))
         if time_delta:
             a(" (%+0.3fs)" % (time_delta,))
     if summary:
         a("\n")
     if successful:
         a('PASSED')
     else:
         a('FAILED')
     if values:
         a(' (')
         values_strings = []
         for name, value, delta in values:
             value_str = '%s=%s' % (name, value)
             if delta:
                 value_str += ' (%+d)' % (delta,)
             values_strings.append(value_str)
         a(', '.join(values_strings))
         a(')')
     return _u('').join(summary)
 def _got_failure(deferred, failure):
     deferred.addErrback(lambda _: None)
     return Mismatch(
         _u('Success result expected on %r, found failure result '
            'instead: %r' % (deferred, failure)),
         {'traceback': failure_content(failure)},
     )
Esempio n. 43
0
    def test_useFixture_details_captured(self):
        class DetailsFixture(fixtures.Fixture):
            def setUp(self):
                fixtures.Fixture.setUp(self)
                self.addCleanup(delattr, self, "content")
                self.content = [_b("content available until cleanUp")]
                self.addDetail("content", content.Content(content_type.UTF8_TEXT, self.get_content))

            def get_content(self):
                return self.content

        fixture = DetailsFixture()

        class SimpleTest(TestCase):
            def test_foo(self):
                self.useFixture(fixture)
                # Add a colliding detail (both should show up)
                self.addDetail("content", content.Content(content_type.UTF8_TEXT, lambda: [_b("foo")]))

        result = ExtendedTestResult()
        SimpleTest("test_foo").run(result)
        self.assertEqual("addSuccess", result._events[-2][0])
        details = result._events[-2][2]
        self.assertEqual(["content", "content-1"], sorted(details.keys()))
        self.assertEqual("foo", _u("").join(details["content"].iter_text()))
        self.assertEqual("content available until cleanUp", "".join(details["content-1"].iter_text()))
Esempio n. 44
0
 def test_add_error(self):
     """Test stopTest on a TestProtocolClient."""
     self.protocol.addError(self.test,
                            subunit.RemoteError(_u("phwoar crikey")))
     self.assertEqual(
         self.io.getvalue(),
         _b(('error: %s [\n' + _remote_exception_str + ": phwoar crikey\n"
             "]\n") % self.test.id()))
Esempio n. 45
0
 def test_add_failure(self):
     """Test addFailure on a TestProtocolClient."""
     self.protocol.addFailure(
         self.test, subunit.RemoteError(_u("boo qux")))
     self.assertEqual(
         self.io.getvalue(),
         _b(('failure: %s [\n' + _remote_exception_str + ': boo qux\n]\n')
         % self.test.id()))
Esempio n. 46
0
 def test_assertEqual_non_ascii_str_with_newlines(self):
     message = _u("Be careful mixing unicode and bytes")
     a = "a\n\xa7\n"
     b = "Just a longish string so the more verbose output form is used."
     expected_error = "\n".join(
         ["!=:", "reference = '''\\", "a", repr("\xa7")[1:-1], "'''", "actual    = %r" % (b,), ": " + message]
     )
     self.assertFails(expected_error, self.assertEqual, a, b, message)
Esempio n. 47
0
 def test_missing_test_no_plan_adds_error(self):
     # A file
     # ok first test
     # not ok 3 third test
     # results in three tests, with the second being created
     self.tap.write(compat._u('ok first test\n'))
     self.tap.write(compat._u('not ok 3 third test\n'))
     self.tap.seek(0)
     result = pysubunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.check_events([('status', 'test 1 first test', 'success', None,
                         False, None, None, True, None, None, None),
                        ('status', 'test 2', 'fail', None, False,
                         'tap meta', b'test missing from TAP output', True,
                         'text/plain; charset=UTF8', None, None),
                        ('status', 'test 3 third test', 'fail', None, False,
                         None, None, True, None, None, None)])
Esempio n. 48
0
 def output_tests(self, tests):
     for test in tests:
         # On Python 2.6 id() returns bytes.
         id_str = test.id()
         if type(id_str) is bytes:
             id_str = id_str.decode('utf8')
         self._stdout.write(id_str)
         self._stdout.write(_u('\n'))
Esempio n. 49
0
 def _handleTime(self, offset, line):
     # Accept it, but do not do anything with it yet.
     try:
         event_time = iso8601.parse_date(line[offset:-1])
     except TypeError:
         raise TypeError(_u("Failed to parse %r, got %r")
             % (line, sys.exec_info[1]))
     self.client.time(event_time)
Esempio n. 50
0
 def test_ok_skip_number_comment_lowercase(self):
     self.tap.write(_u("ok 1 # skip no samba environment available, skipping compilation\n"))
     self.tap.seek(0)
     result = subunit.TAP2SubUnit(self.tap, self.subunit)
     self.assertEqual(0, result)
     self.check_events([('status', 'test 1', 'skip', None, False, 'tap comment',
         b'no samba environment available, skipping compilation', True,
         'text/plain; charset=UTF8', None, None)])
Esempio n. 51
0
    def as_text(self):
        """Return all of the content as text.

        This is only valid where ``iter_text`` is.  It will load all of the
        content into memory.  Where this is a concern, use ``iter_text``
        instead.
        """
        return _u('').join(self.iter_text())
Esempio n. 52
0
 def test_add_expected_failure(self):
     """Test addExpectedFailure on a TestProtocolClient."""
     self.protocol.addExpectedFailure(
         self.test, subunit.RemoteError(_u("phwoar crikey")))
     self.assertEqual(
         self.io.getvalue(),
         _b(('xfail: %s [\n' + _remote_exception_str + ": phwoar crikey\n"
             "]\n") % self.test.id()))
Esempio n. 53
0
    def as_text(self):
        """Return all of the content as text.

        This is only valid where ``iter_text`` is.  It will load all of the
        content into memory.  Where this is a concern, use ``iter_text``
        instead.
        """
        return _u('').join(self.iter_text())
Esempio n. 54
0
 def output_tests(self, tests):
     for test in tests:
         # On Python 2.6 id() returns bytes.
         id_str = test.id()
         if type(id_str) is bytes:
             id_str = id_str.decode('utf8')
         self._stdout.write(id_str)
         self._stdout.write(_u('\n'))
Esempio n. 55
0
 def test_useFixture_multiple_details_captured(self):
     class DetailsFixture(fixtures.Fixture):
         def setUp(self):
             fixtures.Fixture.setUp(self)
             self.addDetail('aaa', content.text_content("foo"))
             self.addDetail('bbb', content.text_content("bar"))
     fixture = DetailsFixture()
     class SimpleTest(TestCase):
         def test_foo(self):
             self.useFixture(fixture)
     result = ExtendedTestResult()
     SimpleTest('test_foo').run(result)
     self.assertEqual('addSuccess', result._events[-2][0])
     details = result._events[-2][2]
     self.assertEqual(['aaa', 'bbb'], sorted(details))
     self.assertEqual(_u('foo'), details['aaa'].as_text())
     self.assertEqual(_u('bar'), details['bbb'].as_text())
Esempio n. 56
0
def _details_to_str(details, special=None):
    """Convert a details dict to a string.

    :param details: A dictionary mapping short names to ``Content`` objects.
    :param special: If specified, an attachment that should have special
        attention drawn to it. The primary attachment. Normally it's the
        traceback that caused the test to fail.
    :return: A formatted string that can be included in text test results.
    """
    empty_attachments = []
    binary_attachments = []
    text_attachments = []
    special_content = None
    # sorted is for testing, may want to remove that and use a dict
    # subclass with defined order for items instead.
    for key, content in sorted(details.items()):
        if content.content_type.type != 'text':
            binary_attachments.append((key, content.content_type))
            continue
        text = _u('').join(content.iter_text()).strip()
        if not text:
            empty_attachments.append(key)
            continue
        # We want the 'special' attachment to be at the bottom.
        if key == special:
            special_content = '%s\n' % (text,)
            continue
        text_attachments.append(_format_text_attachment(key, text))
    if text_attachments and not text_attachments[-1].endswith('\n'):
        text_attachments.append('')
    if special_content:
        text_attachments.append(special_content)
    lines = []
    if binary_attachments:
        lines.append('Binary content:\n')
        for name, content_type in binary_attachments:
            lines.append('  %s (%s)\n' % (name, content_type))
    if empty_attachments:
        lines.append('Empty attachments:\n')
        for name in empty_attachments:
            lines.append('  %s\n' % (name,))
    if (binary_attachments or empty_attachments) and text_attachments:
        lines.append('\n')
    lines.append('\n'.join(text_attachments))
    return _u('').join(lines)
Esempio n. 57
0
 def test_add_expected_failure(self):
     """Test addExpectedFailure on a TestProtocolClient."""
     self.protocol.addExpectedFailure(
         self.test, subunit.RemoteError(_u("phwoar crikey")))
     self.assertEqual(
         self.io.getvalue(),
         _b(('xfail: %s [\n' +
         _remote_exception_str + ": phwoar crikey\n"
         "]\n") % self.test.id()))
Esempio n. 58
0
 def test_lost_connected_after_failure(self):
     self.protocol.lineReceived(_b("test old mcdonald\n"))
     self.protocol.lineReceived(_b("failure old mcdonald\n"))
     self.protocol.lostConnection()
     self.assertEqual([
         ('startTest', self.test),
         ('addFailure', self.test, subunit.RemoteError(_u(""))),
         ('stopTest', self.test),
         ], self.client._events)
Esempio n. 59
0
 def test_stream_content_in_details(self):
     detail_name = 'test'
     fixture = StringStream(detail_name)
     with fixture:
         stream = fixture.stream
         content = fixture.getDetails()[detail_name]
         # Output after getDetails is called is included.
         stream.write(_u("testing 1 2 3"))
         self.assertEqual("testing 1 2 3", content.as_text())