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


Python Source.strip方法代码示例

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


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

示例1: _makefile

# 需要导入模块: from _pytest._code import Source [as 别名]
# 或者: from _pytest._code.Source import strip [as 别名]
    def _makefile(self, ext, args, kwargs, encoding="utf-8"):
        items = list(kwargs.items())
        if args:
            source = py.builtin._totext("\n").join(
                map(py.builtin._totext, args)) + py.builtin._totext("\n")
            basename = self.request.function.__name__
            items.insert(0, (basename, source))
        ret = None
        for name, value in items:
            p = self.tmpdir.join(name).new(ext=ext)
            p.dirpath().ensure_dir()
            source = Source(value)

            def my_totext(s, encoding="utf-8"):
                if py.builtin._isbytes(s):
                    s = py.builtin._totext(s, encoding=encoding)
                return s

            source_unicode = "\n".join([my_totext(line) for line in source.lines])
            source = py.builtin._totext(source_unicode)
            content = source.strip().encode(encoding) # + "\n"
            #content = content.rstrip() + "\n"
            p.write(content, "wb")
            if ret is None:
                ret = p
        return ret
开发者ID:luke-chang,项目名称:gecko-1,代码行数:28,代码来源:pytester.py

示例2: _makefile

# 需要导入模块: from _pytest._code import Source [as 别名]
# 或者: from _pytest._code.Source import strip [as 别名]
    def _makefile(self, ext, args, kwargs, encoding="utf-8"):
        items = list(kwargs.items())

        def to_text(s):
            return s.decode(encoding) if isinstance(s, bytes) else six.text_type(s)

        if args:
            source = u"\n".join(to_text(x) for x in args)
            basename = self.request.function.__name__
            items.insert(0, (basename, source))

        ret = None
        for basename, value in items:
            p = self.tmpdir.join(basename).new(ext=ext)
            p.dirpath().ensure_dir()
            source = Source(value)
            source = u"\n".join(to_text(line) for line in source.lines)
            p.write(source.strip().encode(encoding), "wb")
            if ret is None:
                ret = p
        return ret
开发者ID:marcosptf,项目名称:fedora,代码行数:23,代码来源:pytester.py

示例3: test_source_strip_multiline

# 需要导入模块: from _pytest._code import Source [as 别名]
# 或者: from _pytest._code.Source import strip [as 别名]
def test_source_strip_multiline():
    source = Source()
    source.lines = ["", " hello", "  "]
    source2 = source.strip()
    assert source2.lines == [" hello"]
开发者ID:bronsen,项目名称:pytest,代码行数:7,代码来源:test_source.py

示例4: test_source_strips

# 需要导入模块: from _pytest._code import Source [as 别名]
# 或者: from _pytest._code.Source import strip [as 别名]
def test_source_strips():
    source = Source("")
    assert source == Source()
    assert str(source) == ""
    assert source.strip() == source
开发者ID:bronsen,项目名称:pytest,代码行数:7,代码来源:test_source.py

示例5: _getlines

# 需要导入模块: from _pytest._code import Source [as 别名]
# 或者: from _pytest._code.Source import strip [as 别名]
 def _getlines(self, lines2):
     if isinstance(lines2, str):
         lines2 = Source(lines2)
     if isinstance(lines2, Source):
         lines2 = lines2.strip().lines
     return lines2
开发者ID:luke-chang,项目名称:gecko-1,代码行数:8,代码来源:pytester.py


注:本文中的_pytest._code.Source.strip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。