本文整理汇总了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
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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
)
示例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')
示例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
示例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')
示例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:
示例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()
示例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)
示例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