當前位置: 首頁>>代碼示例>>Python>>正文


Python StringIO.getvalue方法代碼示例

本文整理匯總了Python中testtools.compat.StringIO.getvalue方法的典型用法代碼示例。如果您正苦於以下問題:Python StringIO.getvalue方法的具體用法?Python StringIO.getvalue怎麽用?Python StringIO.getvalue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在testtools.compat.StringIO的用法示例。


在下文中一共展示了StringIO.getvalue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestSubUnitTags

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
class TestSubUnitTags(unittest.TestCase):
    def setUp(self):
        self.original = StringIO()
        self.filtered = StringIO()

    def test_add_tag(self):
        self.original.write("tags: foo\n")
        self.original.write("test: test\n")
        self.original.write("tags: bar -quux\n")
        self.original.write("success: test\n")
        self.original.seek(0)
        result = subunit.tag_stream(self.original, self.filtered, ["quux"])
        self.assertEqual(
            ["tags: quux", "tags: foo", "test: test", "tags: bar", "success: test"],
            self.filtered.getvalue().splitlines(),
        )

    def test_remove_tag(self):
        self.original.write("tags: foo\n")
        self.original.write("test: test\n")
        self.original.write("tags: bar -quux\n")
        self.original.write("success: test\n")
        self.original.seek(0)
        result = subunit.tag_stream(self.original, self.filtered, ["-bar"])
        self.assertEqual(
            ["tags: -bar", "tags: foo", "test: test", "tags: -quux", "success: test"],
            self.filtered.getvalue().splitlines(),
        )
開發者ID:hef,項目名稱:samba,代碼行數:30,代碼來源:test_subunit_tags.py

示例2: test_run_list

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_run_list(self):
        self.useFixture(SampleTestFixture())
        out = StringIO()
        run.main(['prog', '-l', 'testtools.runexample.test_suite'], out)
        self.assertEqual("""testtools.runexample.TestFoo.test_bar
testtools.runexample.TestFoo.test_quux
""", out.getvalue())
開發者ID:AIdrifter,項目名稱:samba,代碼行數:9,代碼來源:test_run.py

示例3: test_run_load_list

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_run_load_list(self):
        self.useFixture(SampleTestFixture())
        out = StringIO()
        # We load two tests - one that exists and one that doesn't, and we
        # should get the one that exists and neither the one that doesn't nor
        # the unmentioned one that does.
        tempdir = self.useFixture(fixtures.TempDir())
        tempname = tempdir.path + '/tests.list'
        f = open(tempname, 'wb')
        try:
            f.write(_b("""
testtools.runexample.TestFoo.test_bar
testtools.runexample.missingtest
"""))
        finally:
            f.close()
        try:
            run.main(['prog', '-l', '--load-list', tempname,
                'testtools.runexample.test_suite'], out)
        except SystemExit:
            exc_info = sys.exc_info()
            raise AssertionError(
                "-l --load-list tried to exit. %r" % exc_info[1])
        self.assertEqual("""testtools.runexample.TestFoo.test_bar
""", out.getvalue())
開發者ID:RayFerr000,項目名稱:PLTL,代碼行數:27,代碼來源:test_run.py

示例4: _run_core

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def _run_core(self):
        # Add an observer to trap all logged errors.
        self.case.reactor = self._reactor
        error_observer = _log_observer
        full_log = StringIO()
        full_observer = log.FileLogObserver(full_log)
        spinner = self._make_spinner()
        successful, unhandled = run_with_log_observers(
            [error_observer.gotEvent, full_observer.emit], self._blocking_run_deferred, spinner
        )

        self.case.addDetail("twisted-log", text_content(full_log.getvalue()))

        logged_errors = error_observer.flushErrors()
        for logged_error in logged_errors:
            successful = False
            self._got_user_failure(logged_error, tb_label="logged-error")

        if unhandled:
            successful = False
            for debug_info in unhandled:
                f = debug_info.failResult
                info = debug_info._getDebugTracebacks()
                if info:
                    self.case.addDetail("unhandled-error-in-deferred-debug", text_content(info))
                self._got_user_failure(f, "unhandled-error-in-deferred")

        junk = spinner.clear_junk()
        if junk:
            successful = False
            self._log_user_exception(UncleanReactorError(junk))

        if successful:
            self.result.addSuccess(self.case, details=self.case.getDetails())
開發者ID:ClusterHQ,項目名稱:testtools,代碼行數:36,代碼來源:deferredruntest.py

示例5: test_preserving_existing_handlers

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
 def test_preserving_existing_handlers(self):
     stream = StringIO()
     self.logger.addHandler(logging.StreamHandler(stream))
     self.logger.setLevel(logging.INFO)
     fixture = LogHandler(self.CustomHandler(), nuke_handlers=False)
     with fixture:
         logging.info("message")
     self.assertEqual(["message"], fixture.handler.msgs)
     self.assertEqual("message\n", stream.getvalue())
開發者ID:brantlk,項目名稱:fixtures,代碼行數:11,代碼來源:test_logger.py

示例6: _run_external_case

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
 def _run_external_case(self):
     """Run the prepared test case in a seperate module"""
     sys.path.insert(0, self.dir)
     self.addCleanup(sys.path.remove, self.dir)
     module = __import__(self.modname)
     self.addCleanup(sys.modules.pop, self.modname)
     stream = StringIO()
     self._run(stream, module.Test())
     return stream.getvalue()
開發者ID:IsCoolEntertainment,項目名稱:debpkg_percona-xtrabackup,代碼行數:11,代碼來源:test_testresult.py

示例7: test_run_list

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_run_list(self):
        self.useFixture(SampleTestFixture())
        out = StringIO()
        try:
            run.main(['prog', '-l', 'testtools.runexample.test_suite'], out)
        except SystemExit:
            exc_info = sys.exc_info()
            raise AssertionError("-l tried to exit. %r" % exc_info[1])
        self.assertEqual("""testtools.runexample.TestFoo.test_bar
testtools.runexample.TestFoo.test_quux
""", out.getvalue())
開發者ID:RayFerr000,項目名稱:PLTL,代碼行數:13,代碼來源:test_run.py

示例8: test_run_list_failed_import

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_run_list_failed_import(self):
        if not run.have_discover:
            self.skipTest("Need discover")
        broken = self.useFixture(SampleTestFixture(broken=True))
        out = StringIO()
        exc = self.assertRaises(
            SystemExit,
            run.main, ['prog', 'discover', '-l', broken.package.base, '*.py'], out)
        self.assertEqual(2, exc.args[0])
        self.assertEqual("""Failed to import
runexample
""", out.getvalue())
開發者ID:harrisonfeng,項目名稱:testtools,代碼行數:14,代碼來源:test_run.py

示例9: test_replace_and_restore_handlers

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
 def test_replace_and_restore_handlers(self):
     stream = StringIO()
     logger = logging.getLogger()
     logger.addHandler(logging.StreamHandler(stream))
     logger.setLevel(logging.INFO)
     logging.info("one")
     fixture = FakeLogger()
     with fixture:
         logging.info("two")
     logging.info("three")
     self.assertEqual("two\n", fixture.output)
     self.assertEqual("one\nthree\n", stream.getvalue())
開發者ID:brantlk,項目名稱:fixtures,代碼行數:14,代碼來源:test_logger.py

示例10: TestTestResultStats

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
class TestTestResultStats(unittest.TestCase):
    """Test for TestResultStats, a TestResult object that generates stats."""

    def setUp(self):
        self.output = StringIO()
        self.result = subunit.TestResultStats(self.output)
        self.input_stream = BytesIO()
        self.test = subunit.ProtocolTestCase(self.input_stream)

    def test_stats_empty(self):
        self.test.run(self.result)
        self.assertEqual(0, self.result.total_tests)
        self.assertEqual(0, self.result.passed_tests)
        self.assertEqual(0, self.result.failed_tests)
        self.assertEqual(set(), self.result.seen_tags)

    def setUpUsedStream(self):
        self.input_stream.write(_b("""tags: global
test passed
success passed
test failed
tags: local
failure failed
test error
error error
test skipped
skip skipped
test todo
xfail todo
"""))
        self.input_stream.seek(0)
        self.test.run(self.result)
    
    def test_stats_smoke_everything(self):
        # Statistics are calculated usefully.
        self.setUpUsedStream()
        self.assertEqual(5, self.result.total_tests)
        self.assertEqual(2, self.result.passed_tests)
        self.assertEqual(2, self.result.failed_tests)
        self.assertEqual(1, self.result.skipped_tests)
        self.assertEqual(set(["global", "local"]), self.result.seen_tags)

    def test_stat_formatting(self):
        expected = ("""
Total tests:       5
Passed tests:      2
Failed tests:      2
Skipped tests:     1
Seen tags: global, local
""")[1:]
        self.setUpUsedStream()
        self.result.formatStats()
        self.assertEqual(expected, self.output.getvalue())
開發者ID:AIdrifter,項目名稱:samba,代碼行數:55,代碼來源:test_subunit_stats.py

示例11: test_issue_16662

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
 def test_issue_16662(self):
     # unittest's discover implementation didn't handle load_tests on
     # packages. That is fixed pending commit, but we want to offer it
     # to all testtools users regardless of Python version.
     # See http://bugs.python.org/issue16662
     pkg = self.useFixture(SampleLoadTestsPackage())
     out = StringIO()
     self.assertEqual(None, run.main(
         ['prog', 'discover', '-l', pkg.package.base], out))
     self.assertEqual(dedent("""\
         discoverexample.TestExample.test_foo
         fred
         """), out.getvalue())
開發者ID:harrisonfeng,項目名稱:testtools,代碼行數:15,代碼來源:test_run.py

示例12: test_stdout_honoured

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_stdout_honoured(self):
        self.useFixture(SampleTestFixture())
        tests = []
        out = StringIO()
        exc = self.assertRaises(SystemExit, run.main,
            argv=['prog', 'testtools.runexample.test_suite'],
            stdout=out)
        self.assertEqual((0,), exc.args)
        self.assertThat(
            out.getvalue(),
            MatchesRegex(_u("""Tests running...

Ran 2 tests in \\d.\\d\\d\\ds
OK
""")))
開發者ID:RayFerr000,項目名稱:PLTL,代碼行數:17,代碼來源:test_run.py

示例13: test_run_orders_tests

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_run_orders_tests(self):
        self.useFixture(SampleTestFixture())
        out = StringIO()
        # We load two tests - one that exists and one that doesn't, and we
        # should get the one that exists and neither the one that doesn't nor
        # the unmentioned one that does.
        tempdir = self.useFixture(fixtures.TempDir())
        tempname = tempdir.path + '/tests.list'
        f = open(tempname, 'wb')
        try:
            f.write(_b("""
testtools.runexample.TestFoo.test_bar
testtools.runexample.missingtest
"""))
        finally:
            f.close()
        run.main(['prog', '-l', '--load-list', tempname,
            'testtools.runexample.test_suite'], out)
        self.assertEqual("""testtools.runexample.TestFoo.test_bar
""", out.getvalue())
開發者ID:AIdrifter,項目名稱:samba,代碼行數:22,代碼來源:test_run.py

示例14: test_run_list_failed_import

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
    def test_run_list_failed_import(self):
        broken = self.useFixture(SampleTestFixture(broken=True))
        out = StringIO()
        # XXX: http://bugs.python.org/issue22811
        unittest2.defaultTestLoader._top_level_dir = None
        exc = self.assertRaises(
            SystemExit,
            run.main, ['prog', 'discover', '-l', broken.package.base, '*.py'], out)
        self.assertEqual(2, exc.args[0])
        self.assertThat(out.getvalue(), DocTestMatches("""\
Failed to import test module: runexample
Traceback (most recent call last):
  File ".../loader.py", line ..., in _find_test_path
    package = self._get_module_from_name(name)
  File ".../loader.py", line ..., in _get_module_from_name
    __import__(name)
  File ".../runexample/__init__.py", line 1
    class not in
...^...
SyntaxError: invalid syntax

""", doctest.ELLIPSIS))
開發者ID:RayFerr000,項目名稱:PLTL,代碼行數:24,代碼來源:test_run.py

示例15: TestTAP2SubUnit

# 需要導入模塊: from testtools.compat import StringIO [as 別名]
# 或者: from testtools.compat.StringIO import getvalue [as 別名]
class TestTAP2SubUnit(unittest.TestCase):
    """Tests for TAP2SubUnit.

    These tests test TAP string data in, and subunit string data out.
    This is ok because the subunit protocol is intended to be stable,
    but it might be easier/pithier to write tests against TAP string in,
    parsed subunit objects out (by hooking the subunit stream to a subunit
    protocol server.
    """

    def setUp(self):
        self.tap = StringIO()
        self.subunit = StringIO()

    def test_skip_entire_file(self):
        # A file
        # 1..- # Skipped: comment
        # results in a single skipped test.
        self.tap.write("1..0 # Skipped: entire file skipped\n")
        self.tap.seek(0)
        result = subunit.TAP2SubUnit(self.tap, self.subunit)
        self.assertEqual(0, result)
        self.assertEqual([
            "test file skip",
            "skip file skip [",
            "Skipped: entire file skipped",
            "]",
            ],
            self.subunit.getvalue().splitlines())

    def test_ok_test_pass(self):
        # A file
        # ok
        # results in a passed test with name 'test 1' (a synthetic name as tap
        # does not require named fixtures - it is the first test in the tap
        # stream).
        self.tap.write("ok\n")
        self.tap.seek(0)
        result = subunit.TAP2SubUnit(self.tap, self.subunit)
        self.assertEqual(0, result)
        self.assertEqual([
            "test test 1",
            "success test 1",
            ],
            self.subunit.getvalue().splitlines())

    def test_ok_test_number_pass(self):
        # A file
        # ok 1
        # results in a passed test with name 'test 1'
        self.tap.write("ok 1\n")
        self.tap.seek(0)
        result = subunit.TAP2SubUnit(self.tap, self.subunit)
        self.assertEqual(0, result)
        self.assertEqual([
            "test test 1",
            "success test 1",
            ],
            self.subunit.getvalue().splitlines())

    def test_ok_test_number_description_pass(self):
        # A file
        # ok 1 - There is a description
        # results in a passed test with name 'test 1 - There is a description'
        self.tap.write("ok 1 - There is a description\n")
        self.tap.seek(0)
        result = subunit.TAP2SubUnit(self.tap, self.subunit)
        self.assertEqual(0, result)
        self.assertEqual([
            "test test 1 - There is a description",
            "success test 1 - There is a description",
            ],
            self.subunit.getvalue().splitlines())

    def test_ok_test_description_pass(self):
        # A file
        # ok There is a description
        # results in a passed test with name 'test 1 There is a description'
        self.tap.write("ok There is a description\n")
        self.tap.seek(0)
        result = subunit.TAP2SubUnit(self.tap, self.subunit)
        self.assertEqual(0, result)
        self.assertEqual([
            "test test 1 There is a description",
            "success test 1 There is a description",
            ],
            self.subunit.getvalue().splitlines())

    def test_ok_SKIP_skip(self):
        # A file
        # ok # SKIP
        # results in a skkip test with name 'test 1'
        self.tap.write("ok # SKIP\n")
        self.tap.seek(0)
        result = subunit.TAP2SubUnit(self.tap, self.subunit)
        self.assertEqual(0, result)
        self.assertEqual([
            "test test 1",
            "skip test 1",
            ],
#.........這裏部分代碼省略.........
開發者ID:AIdrifter,項目名稱:samba,代碼行數:103,代碼來源:test_tap2subunit.py


注:本文中的testtools.compat.StringIO.getvalue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。