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


Python textwrap.dedent方法代碼示例

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


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

示例1: test_read_setup_cfg_missing_mutatest_ini

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_read_setup_cfg_missing_mutatest_ini(tmp_path, section, monkeypatch):
    """Setup.cfg will support both [mutatest] and [tool:mutatest] sections."""
    ini_contents = dedent(
        f"""\
    [{section}]
    whitelist = nc su ix"""
    )

    expected = ["nc", "su", "ix"]

    with open(tmp_path / "setup.cfg", "w") as fstream:
        fstream.write(ini_contents)

    monkeypatch.chdir(tmp_path)
    result = cli.cli_args([])
    print(result.__dict__)

    assert len(result.whitelist) == 3
    for r, e in zip(result.whitelist, expected):
        assert r == e 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:22,代碼來源:test_cli.py

示例2: augassign_file

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def augassign_file(tmp_path_factory):
    """A simple python file with the AugAssign attributes."""
    contents = dedent(
        """\
    def my_func(a, b):
        a += 6
        b -= 4
        b /= 2
        b *= 3

        return a, b
    """
    )

    fn = tmp_path_factory.mktemp("augassign") / "augassign.py"

    with open(fn, "w") as output_fn:
        output_fn.write(contents)

    yield fn

    fn.unlink() 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:24,代碼來源:conftest.py

示例3: boolop_file

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def boolop_file(tmp_path_factory):
    """A simple python file with bool op operations."""
    contents = dedent(
        """\
    def equal_test(a, b):
        return a and b

    print(equal_test(1,1))
    """
    )

    fn = tmp_path_factory.mktemp("boolop") / "boolop.py"

    with open(fn, "w") as output_fn:
        output_fn.write(contents)

    yield fn

    fn.unlink() 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:21,代碼來源:conftest.py

示例4: compare_file

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def compare_file(tmp_path_factory):
    """A simple python file with the compare."""
    contents = dedent(
        """\
    def equal_test(a, b):
        return a == b

    def is_test(a, b):
        return a is b

    def in_test(a, b):
        return a in b
    print(equal_test(1,1))
    """
    )

    fn = tmp_path_factory.mktemp("compare") / "compare.py"

    with open(fn, "w") as output_fn:
        output_fn.write(contents)

    yield fn

    fn.unlink() 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:26,代碼來源:conftest.py

示例5: index_file

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def index_file(tmp_path_factory):
    """A simple python file with the index attributes for list slices."""
    contents = dedent(
        """\
    def my_func(x_list):
        a_list = x_list[-1]
        b_list = x_list[0]
        c_list = x_list[1][2]
    """
    )

    fn = tmp_path_factory.mktemp("index") / "index.py"

    with open(fn, "w") as output_fn:
        output_fn.write(contents)

    yield fn

    fn.unlink() 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:21,代碼來源:conftest.py

示例6: slice_file

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def slice_file(tmp_path_factory):
    """A simple python file with the slice attributes."""
    contents = dedent(
        """\
    def my_func(x_list):
        y_list = x_list[:-1]
        z_list = x_list[0:2:-4]
        zz_list = x_list[0::2]
        zzs_list = x_list[-8:-3:2]
        yz_list = y_list[0:]
        a_list = x_list[::]

        return yz_list
    """
    )

    fn = tmp_path_factory.mktemp("slice") / "slice.py"

    with open(fn, "w") as output_fn:
        output_fn.write(contents)

    yield fn

    fn.unlink() 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:26,代碼來源:conftest.py

示例7: test_build_report_section

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_build_report_section(mock_Mutant):
    """Simplified report section formatting for the report."""

    title = "Title"
    mutants = [mock_Mutant]

    report = build_report_section(title, mutants)

    expected = dedent(
        """

    Title
    -----
     - src.py: (l: 1, c: 2) - mutation from <class '_ast.Add'> to <class '_ast.Mult'>"""
    )

    assert report == expected 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:19,代碼來源:test_report.py

示例8: build_arg_parser

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def build_arg_parser(description, env_vars={}):
    from argparse import ArgumentParser, RawDescriptionHelpFormatter
    from textwrap import dedent

    base_env_vars = {
        'MONO_SOURCE_ROOT': 'Overrides default value for --mono-sources',
    }

    env_vars_text = '\n'.join(['    %s: %s' % (var, desc) for var, desc in env_vars.items()])
    base_env_vars_text = '\n'.join(['    %s: %s' % (var, desc) for var, desc in base_env_vars.items()])

    epilog=dedent('''\
environment variables:
%s
%s
''' % (env_vars_text, base_env_vars_text))

    return ArgumentParser(
        description=description,
        formatter_class=RawDescriptionHelpFormatter,
        epilog=epilog
    ) 
開發者ID:godotengine,項目名稱:godot-mono-builds,代碼行數:24,代碼來源:cmd_utils.py

示例9: test_config

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_config(self):
        from textwrap import dedent

        # variable substitution with [DEFAULT]
        conf = dedent("""
        [DEFAULT]
        dir = "/some/dir"
        my.dir = %(dir)s + "/sub"

        [my]
        my.dir = %(dir)s + "/my/dir"
        my.dir2 = %(my.dir)s + '/dir2'

        """)

        fp = StringIOFromNative(conf)

        cherrypy.config.update(fp)
        self.assertEqual(cherrypy.config['my']['my.dir'], '/some/dir/my/dir')
        self.assertEqual(cherrypy.config['my']
                         ['my.dir2'], '/some/dir/my/dir/dir2') 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:23,代碼來源:test_config.py

示例10: test_call_with_kwargs

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_call_with_kwargs(self):
        from textwrap import dedent
        conf = dedent("""
        [my]
        value = dict(foo="buzz", **cherrypy._test_dict)
        """)
        test_dict = {
            'foo': 'bar',
            'bar': 'foo',
            'fizz': 'buzz'
        }
        cherrypy._test_dict = test_dict
        fp = StringIOFromNative(conf)
        cherrypy.config.update(fp)
        test_dict['foo'] = 'buzz'
        self.assertEqual(cherrypy.config['my']['value']['foo'], 'buzz')
        self.assertEqual(cherrypy.config['my']['value'], test_dict)
        del cherrypy._test_dict 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:20,代碼來源:test_config.py

示例11: test_syntax

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_syntax(self):
        if sys.version_info < (3,):
            return self.skip('skipped (Python 3 only)')
        code = textwrap.dedent("""
            class Root:
                @cherrypy.expose
                @cherrypy.tools.params()
                def resource(self, limit: int):
                    return type(limit).__name__
            conf = {'/': {'tools.params.on': True}}
            cherrypy.tree.mount(Root(), config=conf)
            """)
        exec(code)

        self.getPage('/resource?limit=0')
        self.assertStatus(200)
        self.assertBody('int') 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:19,代碼來源:test_params.py

示例12: test_process_empty

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_process_empty():  # type: () -> None
    """
    Submitting an empty payment request fails.
    """
    response = post_sandbox_checkout({})
    assert {
        'payment_summary': 'Payment total R ZAR',
        'notice': dedent("""\
            The supplied variables are not according to specification:
            amount : amount is required
            item_name : item_name is required
            merchant_id : merchant_id is required
            merchant_key : merchant_key is required
        """),
    } == parse_payfast_page(response)


# Check for ITN testing configuration: 
開發者ID:PiDelport,項目名稱:django-payfast,代碼行數:20,代碼來源:test_integration_sandbox.py

示例13: visit_While

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def visit_While(self, node):
        self.labelStack.append(node.breakLabel)
        self.labelStack.append(node.loopLabel)
        if node.breakLabel.isActive:
            self.write("begin: %s" % node.breakLabel)
            self.writeline()
        self.write("while (")
        self.visit(node.test)
        self.write(") begin")
        if node.loopLabel.isActive:
            self.write(": %s" % node.loopLabel)
        self.indent()
        self.visit_stmt(node.body)
        self.dedent()
        self.writeline()
        self.write("end")
        if node.breakLabel.isActive:
            self.writeline()
            self.write("end")
        self.labelStack.pop()
        self.labelStack.pop() 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:23,代碼來源:_toVerilog.py

示例14: visit_FunctionDef

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def visit_FunctionDef(self, node):
        self.writeDoc(node)
        w = node.body[-1]
        y = w.body[0]
        if isinstance(y, ast.Expr):
            y = y.value
        assert isinstance(y, ast.Yield)
        self.writeAlwaysHeader()
        self.writeDeclarations()
        # assert isinstance(w.body, astNode.Stmt)
        for stmt in w.body[1:]:
            self.writeline()
            self.visit(stmt)
        self.dedent()
        self.writeline()
        self.write("end")
        self.writeline(2) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:19,代碼來源:_toVerilog.py

示例15: test_load_from_file

# 需要導入模塊: import textwrap [as 別名]
# 或者: from textwrap import dedent [as 別名]
def test_load_from_file(app):
    config = dedent(
        """
    VALUE = 'some value'
    condition = 1 == 1
    if condition:
        CONDITIONAL = 'should be set'
    """
    )
    with temp_path() as config_path:
        config_path.write_text(config)
        app.config.from_pyfile(str(config_path))
        assert "VALUE" in app.config
        assert app.config.VALUE == "some value"
        assert "CONDITIONAL" in app.config
        assert app.config.CONDITIONAL == "should be set"
        assert "condition" not in app.config 
開發者ID:huge-success,項目名稱:sanic,代碼行數:19,代碼來源:test_config.py


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