当前位置: 首页>>代码示例>>Python>>正文


Python StringIO.write方法代码示例

本文整理汇总了Python中testtools.compat.StringIO.write方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.write方法的具体用法?Python StringIO.write怎么用?Python StringIO.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testtools.compat.StringIO的用法示例。


在下文中一共展示了StringIO.write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSubUnitTags

# 需要导入模块: from testtools.compat import StringIO [as 别名]
# 或者: from testtools.compat.StringIO import write [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: TestTAP2SubUnit

# 需要导入模块: from testtools.compat import StringIO [as 别名]
# 或者: from testtools.compat.StringIO import write [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.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。