Пример #1
0
 def test_unicode_encodings_not_wrapped(self):
     """A unicode encoding is left unwrapped as needs no error handler"""
     sout = _FakeOutputStream()
     sout.encoding = "utf-8"
     self.assertIs(unicode_output_stream(sout), sout)
     sout = _FakeOutputStream()
     sout.encoding = "utf-16-be"
     self.assertIs(unicode_output_stream(sout), sout)
Пример #2
0
 def test_unicode_encodings_not_wrapped(self):
     """A unicode encoding is left unwrapped as needs no error handler"""
     sout = _FakeOutputStream()
     sout.encoding = "utf-8"
     self.assertIs(unicode_output_stream(sout), sout)
     sout = _FakeOutputStream()
     sout.encoding = "utf-16-be"
     self.assertIs(unicode_output_stream(sout), sout)
Пример #3
0
def main(argv, prepare_args=prepare_argv, find_tests=find_tests):
    """CLI entry point to adapt a test run to parallel testing."""
    child_args = prepare_argv(argv)
    test_ids = find_tests(argv)

    # We could create a proxy object per test id if desired in future)
    def parallelise_tests(suite):
        test_ids = list(suite)[0]._test_ids
        count = concurrency()
        partitions = partition_tests(test_ids, count)
        return [
            ListTestCase(partition, child_args) for partition in partitions
        ]

    suite = ConcurrentTestSuite(ListTestCase(test_ids, None),
                                parallelise_tests)
    if '--subunit' in argv:
        runner = SubunitTestRunner(sys.stdout)
        result = runner.run(suite)
    else:
        stream = unicode_output_stream(sys.stdout)
        result = TextTestResult(stream)
        result.startTestRun()
        try:
            suite.run(result)
        finally:
            result.stopTestRun()
    if result.wasSuccessful():
        return 0
    return -1
Пример #4
0
def main(argv, prepare_args=prepare_argv, find_tests=find_tests):
    """CLI entry point to adapt a test run to parallel testing."""
    child_args = prepare_argv(argv)
    test_ids = find_tests(argv)
    # We could create a proxy object per test id if desired in future)
    def parallelise_tests(suite):
        test_ids = list(suite)[0]._test_ids
        count = concurrency()
        partitions = partition_tests(test_ids, count)
        return [ListTestCase(partition, child_args) for partition in partitions]
    suite = ConcurrentTestSuite(ListTestCase(test_ids, None), parallelise_tests)
    if '--subunit' in argv:
        runner = SubunitTestRunner(sys.stdout)
        result = runner.run(suite)
    else:
        stream = unicode_output_stream(sys.stdout)
        result = TextTestResult(stream)
        result.startTestRun()
        try:
            suite.run(result)
        finally:
            result.stopTestRun()
    if result.wasSuccessful():
        return 0
    return -1
Пример #5
0
 def run(self, test):
     "Run the given test case or test suite."
     result = TextTestResult(unicode_output_stream(self.stdout))
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
Пример #6
0
 def test_unicode_encodings_wrapped_when_str_is_not_unicode(self):
     """A unicode encoding is wrapped but needs no error handler"""
     sout = _FakeOutputStream()
     sout.encoding = "utf-8"
     uout = unicode_output_stream(sout)
     self.assertEqual(uout.errors, "strict")
     uout.write(self.uni)
     self.assertEqual([_b("pa\xc9\xaa\xce\xb8\xc9\x99n")], sout.writelog)
 def run(self, test):
     "Run the given test case or test suite."
     result = TextTestResult(unicode_output_stream(self.stdout))
     result.startTestRun()
     try:
         return test.run(result)
     finally:
         result.stopTestRun()
Пример #8
0
 def test_unicode_encodings_wrapped_when_str_is_not_unicode(self):
     """A unicode encoding is wrapped but needs no error handler"""
     sout = _FakeOutputStream()
     sout.encoding = "utf-8"
     uout = unicode_output_stream(sout)
     self.assertEqual(uout.errors, "strict")
     uout.write(self.uni)
     self.assertEqual([_b("pa\xc9\xaa\xce\xb8\xc9\x99n")], sout.writelog)
Пример #9
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'])
Пример #10
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'])
Пример #11
0
 def test_stringio(self):
     """A StringIO object should maybe get an ascii native str type"""
     try:
         from cStringIO import StringIO
         newio = False
     except ImportError:
         from io import StringIO
         newio = True
     sout = StringIO()
     soutwrapper = unicode_output_stream(sout)
     soutwrapper.write(self.uni)
     if newio:
         self.assertEqual(self.uni, sout.getvalue())
     else:
         self.assertEqual("pa???n", sout.getvalue())
Пример #12
0
 def test_stringio(self):
     """A StringIO object should maybe get an ascii native str type"""
     try:
         from cStringIO import StringIO
         newio = False
     except ImportError:
         from io import StringIO
         newio = True
     sout = StringIO()
     soutwrapper = unicode_output_stream(sout)
     soutwrapper.write(self.uni)
     if newio:
         self.assertEqual(self.uni, sout.getvalue())
     else:
         self.assertEqual("pa???n", sout.getvalue())
Пример #13
0
 def test_stringio(self):
     """A StringIO object should maybe get an ascii native str type"""
     try:
         from cStringIO import StringIO
         newio = False
     except ImportError:
         from io import StringIO
         newio = True
     sout = StringIO()
     soutwrapper = unicode_output_stream(sout)
     if newio:
         self.expectFailure("Python 3 StringIO expects text not bytes",
             self.assertThat, lambda: soutwrapper.write(self.uni),
             Not(Raises(MatchesException(TypeError))))
     soutwrapper.write(self.uni)
     self.assertEqual("pa???n", sout.getvalue())
Пример #14
0
 def test_stringio(self):
     """A StringIO object should maybe get an ascii native str type"""
     try:
         from cStringIO import StringIO
         newio = False
     except ImportError:
         from io import StringIO
         newio = True
     sout = StringIO()
     soutwrapper = unicode_output_stream(sout)
     if newio:
         self.expectFailure("Python 3 StringIO expects text not bytes",
             self.assertThat, lambda: soutwrapper.write(self.uni),
             Not(Raises(MatchesException(TypeError))))
     soutwrapper.write(self.uni)
     self.assertEqual("pa???n", sout.getvalue())
Пример #15
0
 def test_encoding_as_none_becomes_ascii(self):
     """A stream with encoding value of None gets ascii/replace strings"""
     sout = _FakeOutputStream()
     sout.encoding = None
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa???n")], sout.writelog)
Пример #16
0
 def test_no_encoding_becomes_ascii(self):
     """A stream with no encoding attribute gets ascii/replace strings"""
     sout = _FakeOutputStream()
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa???n")], sout.writelog)
Пример #17
0
 def test_unicode_encodings_not_wrapped_when_str_is_unicode(self):
     # No wrapping needed if native str type is unicode
     sout = _FakeOutputStream()
     sout.encoding = "utf-8"
     uout = unicode_output_stream(sout)
     self.assertIs(uout, sout)
Пример #18
0
 def test_io_stringio(self):
     # io.StringIO only accepts unicode so should be returned as itself.
     s = io.StringIO()
     self.assertEqual(s, unicode_output_stream(s))
Пример #19
0
 def test_partial_encoding_replace(self):
     """A string which can be partly encoded correctly should be"""
     sout = _FakeOutputStream()
     sout.encoding = "iso-8859-7"
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa?\xe8?n")], sout.writelog)
Пример #20
0
 def test_io_textwrapper(self):
     # textwrapper is unicode, should be returned as itself.
     text_io = io.TextIOWrapper(io.BytesIO())
     self.assertThat(unicode_output_stream(text_io), Is(text_io))
     # To be sure...
     unicode_output_stream(text_io).write(_u('foo'))
Пример #21
0
 def test_stringio(self):
     """A StringIO object should maybe get an ascii native str type"""
     sout = io.StringIO()
     soutwrapper = unicode_output_stream(sout)
     soutwrapper.write(self.uni)
     self.assertEqual(self.uni, sout.getvalue())
Пример #22
0
 def test_bogus_encoding_becomes_ascii(self):
     """A stream with a bogus encoding gets ascii/replace strings"""
     sout = _FakeOutputStream()
     sout.encoding = "bogus"
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa???n")], sout.writelog)
Пример #23
0
 def test_io_textwrapper(self):
     # textwrapper is unicode, should be returned as itself.
     text_io = io.TextIOWrapper(io.BytesIO())
     self.assertThat(unicode_output_stream(text_io), Is(text_io))
     # To be sure...
     unicode_output_stream(text_io).write(_u('foo'))
Пример #24
0
 def test_io_bytesio(self):
     # io.BytesIO only accepts bytes so should be wrapped.
     bytes_io = io.BytesIO()
     self.assertThat(bytes_io, Not(Is(unicode_output_stream(bytes_io))))
     # Will error if s was not wrapped properly.
     unicode_output_stream(bytes_io).write(_u('foo'))
Пример #25
0
 def test_io_stringio(self):
     # io.StringIO only accepts unicode so should be returned as itself.
     s = io.StringIO()
     self.assertEqual(s, unicode_output_stream(s))
Пример #26
0
 def test_partial_encoding_replace(self):
     """A string which can be partly encoded correctly should be"""
     sout = _FakeOutputStream()
     sout.encoding = "iso-8859-7"
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa?\xe8?n")], sout.writelog)
Пример #27
0
 def test_no_encoding_becomes_ascii(self):
     """A stream with no encoding attribute gets ascii/replace strings"""
     sout = _FakeOutputStream()
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa???n")], sout.writelog)
Пример #28
0
 def test_unicode_encodings_not_wrapped_when_str_is_unicode(self):
     # No wrapping needed if native str type is unicode
     sout = _FakeOutputStream()
     sout.encoding = "utf-8"
     uout = unicode_output_stream(sout)
     self.assertIs(uout, sout)
Пример #29
0
 def test_encoding_as_none_becomes_ascii(self):
     """A stream with encoding value of None gets ascii/replace strings"""
     sout = _FakeOutputStream()
     sout.encoding = None
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa???n")], sout.writelog)
Пример #30
0
 def test_bogus_encoding_becomes_ascii(self):
     """A stream with a bogus encoding gets ascii/replace strings"""
     sout = _FakeOutputStream()
     sout.encoding = "bogus"
     unicode_output_stream(sout).write(self.uni)
     self.assertEqual([_b("pa???n")], sout.writelog)
Пример #31
0
 def test_io_bytesio(self):
     # io.BytesIO only accepts bytes so should be wrapped.
     bytes_io = io.BytesIO()
     self.assertThat(bytes_io, Not(Is(unicode_output_stream(bytes_io))))
     # Will error if s was not wrapped properly.
     unicode_output_stream(bytes_io).write(_u('foo'))