本文整理汇总了Python中textwrap.dedent函数的典型用法代码示例。如果您正苦于以下问题:Python dedent函数的具体用法?Python dedent怎么用?Python dedent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dedent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_uninstall_from_reqs_file
def test_uninstall_from_reqs_file():
"""
Test uninstall from a requirements file.
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""\
-e %s#egg=initools-dev
# and something else to test out:
PyLogo<0.4
""" % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
result = run_pip('install', '-r', 'test-req.txt')
write_file('test-req.txt', textwrap.dedent("""\
# -f, -i, and --extra-index-url should all be ignored by uninstall
-f http://www.example.com
-i http://www.example.com
--extra-index-url http://www.example.com
-e %s#egg=initools-dev
# and something else to test out:
PyLogo<0.4
""" % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
assert_all_changes(
result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
示例2: assert_fromfile
def assert_fromfile(self, parse_func, expected_append=None, append_contents=None):
def _do_assert_fromfile(dest, expected, contents):
with temporary_file() as fp:
fp.write(contents)
fp.close()
options = parse_func(dest, fp.name)
self.assertEqual(expected, options.for_scope('fromfile')[dest])
_do_assert_fromfile(dest='string', expected='jake', contents='jake')
_do_assert_fromfile(dest='intvalue', expected=42, contents='42')
_do_assert_fromfile(dest='dictvalue', expected={'a': 42, 'b': (1, 2)}, contents=dedent("""
{
'a': 42,
'b': (
1,
2
)
}
"""))
_do_assert_fromfile(dest='listvalue', expected=['a', '1', '2'], contents=dedent("""
['a',
1,
2]
"""))
expected_append = expected_append or [1, 2, 42]
append_contents = append_contents or dedent("""
[
1,
2,
42
]
""")
_do_assert_fromfile(dest='appendvalue', expected=expected_append, contents=append_contents)
示例3: testSetGlobalStyle
def testSetGlobalStyle(self):
try:
style.SetGlobalStyle(style.CreateChromiumStyle())
unformatted_code = textwrap.dedent(u"""\
for i in range(5):
print('bar')
""")
expected_formatted_code = textwrap.dedent(u"""\
for i in range(5):
print('bar')
""")
uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
self.assertCodeEqual(expected_formatted_code,
reformatter.Reformat(uwlines))
finally:
style.SetGlobalStyle(style.CreatePEP8Style())
style.DEFAULT_STYLE = self.current_style
unformatted_code = textwrap.dedent(u"""\
for i in range(5):
print('bar')
""")
expected_formatted_code = textwrap.dedent(u"""\
for i in range(5):
print('bar')
""")
uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
示例4: createInterfaceFile
def createInterfaceFile(className):
fileText = createHeadingComment()
fileText += textwrap.dedent('''\
#ifndef ''' + className.upper() + '''_H
#define ''' + className.upper() + '''_H
class ''' + className + '''
{
public:
virtual ~''' + className + '''() {};
public: // signals
public: // slots
};
#endif
''')
fileText = textwrap.dedent(fileText)
if os.path.isfile(className + '.h'):
return
file = open(className + '.h', 'w')
file.write(fileText)
示例5: test_load_from_file_with_local_overriding_global
def test_load_from_file_with_local_overriding_global(self):
# The config data in the local and global files is loaded correctly.
# The local data will override the global one
content = '''
[A]
a=1
b=c
[B]
b=2'''
site_path = touch(content=textwrap.dedent(content))
os.environ["OQ_SITE_CFG_PATH"] = site_path
content = '''
[A]
a=2
d=e
[D]
c=d-1
d=4'''
local_path = touch(content=textwrap.dedent(content))
os.environ["OQ_LOCAL_CFG_PATH"] = local_path
config.cfg.cfg.clear()
config.cfg._load_from_file()
self.assertEqual(["A", "B", "D"],
sorted(config.cfg.cfg))
self.assertEqual({"a": "2", "b": "c", "d": "e"},
config.cfg.cfg.get("A"))
self.assertEqual({"b": "2"}, config.cfg.cfg.get("B"))
self.assertEqual({"c": "d-1", "d": "4"}, config.cfg.cfg.get("D"))
示例6: test_sibling_build_files_duplicates
def test_sibling_build_files_duplicates(self):
# This workspace is malformed, you can't shadow a name in a sibling BUILD file
self.add_to_build_file('BUILD', dedent(
"""
fake(name="base",
dependencies=[
':foo',
])
"""))
self.add_to_build_file('BUILD.foo', dedent(
"""
fake(name="foo",
dependencies=[
':bat',
])
"""))
self.add_to_build_file('./BUILD.bar', dedent(
"""
fake(name="base")
"""))
with self.assertRaises(BuildFileParser.SiblingConflictException):
base_build_file = FilesystemBuildFile(self.build_root, 'BUILD')
self.build_file_parser.address_map_from_build_file(base_build_file)
示例7: test_nested_namespaces
def test_nested_namespaces(self):
self.create_file('src/thrift/com/foo/one.thrift', contents=dedent("""
namespace py foo.bar
struct One {}
"""))
self.create_file('src/thrift/com/foo/bar/two.thrift', contents=dedent("""
namespace py foo.bar.baz
struct Two {}
"""))
one = self.make_target(spec='src/thrift/com/foo:one',
target_type=PythonThriftLibrary,
sources=['one.thrift', 'bar/two.thrift'])
_, synthetic_target = self.generate_single_thrift_target(one)
self.assertEqual({'foo/__init__.py',
'foo/bar/__init__.py',
'foo/bar/constants.py',
'foo/bar/ttypes.py',
'foo/bar/baz/__init__.py',
'foo/bar/baz/constants.py',
'foo/bar/baz/ttypes.py'},
set(synthetic_target.sources_relative_to_source_root()))
self.assert_ns_package(synthetic_target, 'foo')
self.assert_leaf_package(synthetic_target, 'foo/bar')
self.assert_leaf_package(synthetic_target, 'foo/bar/baz')
示例8: run
def run(self):
##########################
# Get a list of all known
# tests that we can run.
##########################
all_tests = self.__gather_tests()
##########################
# Setup client/server
##########################
print textwrap.dedent("""
=====================================================
Preparing up Server and Client ...
=====================================================
""")
self.__setup_server()
self.__setup_client()
##########################
# Run tests
##########################
self.__run_tests(all_tests)
##########################
# Parse results
##########################
if self.mode == "benchmark":
print textwrap.dedent("""
=====================================================
Parsing Results ...
=====================================================
""")
self.__parse_results(all_tests)
self.__finish()
示例9: test_upgrade_from_reqs_file
def test_upgrade_from_reqs_file(script):
"""
Upgrade from a requirements file.
"""
script.scratch_path.join("test-req.txt").write(textwrap.dedent("""\
PyLogo<0.4
# and something else to test out:
INITools==0.3
"""))
install_result = script.pip(
'install', '-r', script.scratch_path / 'test-req.txt'
)
script.scratch_path.join("test-req.txt").write(textwrap.dedent("""\
PyLogo
# and something else to test out:
INITools
"""))
script.pip(
'install', '--upgrade', '-r', script.scratch_path / 'test-req.txt'
)
uninstall_result = script.pip(
'uninstall', '-r', script.scratch_path / 'test-req.txt', '-y'
)
assert_all_changes(
install_result,
uninstall_result,
[script.venv / 'build', 'cache', script.scratch / 'test-req.txt'],
)
示例10: test_check_prog_input
def test_check_prog_input(self):
config, out, status = self.get_result(textwrap.dedent('''
option("--with-ccache", nargs=1, help="ccache")
check_prog("CCACHE", ("known-a",), input="--with-ccache")
'''), ['--with-ccache=known-b'])
self.assertEqual(status, 0)
self.assertEqual(config, {'CCACHE': self.KNOWN_B})
self.assertEqual(out, 'checking for ccache... %s\n' % self.KNOWN_B)
script = textwrap.dedent('''
option(env="CC", nargs=1, help="compiler")
@depends("CC")
def compiler(value):
return value[0].split()[0] if value else None
check_prog("CC", ("known-a",), input=compiler)
''')
config, out, status = self.get_result(script)
self.assertEqual(status, 0)
self.assertEqual(config, {'CC': self.KNOWN_A})
self.assertEqual(out, 'checking for cc... %s\n' % self.KNOWN_A)
config, out, status = self.get_result(script, ['CC=known-b'])
self.assertEqual(status, 0)
self.assertEqual(config, {'CC': self.KNOWN_B})
self.assertEqual(out, 'checking for cc... %s\n' % self.KNOWN_B)
config, out, status = self.get_result(script, ['CC=known-b -m32'])
self.assertEqual(status, 0)
self.assertEqual(config, {'CC': self.KNOWN_B})
self.assertEqual(out, 'checking for cc... %s\n' % self.KNOWN_B)
示例11: dedent
def dedent(text):
"""Equivalent of textwrap.dedent that ignores unindented first line.
This means it will still dedent strings like:
'''foo
is a bar
'''
For use in wrap_paragraphs.
"""
if text.startswith('\n'):
# text starts with blank line, don't ignore the first line
return textwrap.dedent(text)
# split first line
splits = text.split('\n',1)
if len(splits) == 1:
# only one line
return textwrap.dedent(text)
first, rest = splits
# dedent everything but the first line
rest = textwrap.dedent(rest)
return '\n'.join([first, rest])
示例12: test_good_txt_transcript
def test_good_txt_transcript(self):
good_sjson = _create_file(content=textwrap.dedent("""\
{
"start": [
270,
2720
],
"end": [
2720,
5430
],
"text": [
"Hi, welcome to Edx.",
"Let's start with what is on your screen right now."
]
}
"""))
_upload_sjson_file(good_sjson, self.item.location)
self.item.sub = _get_subs_id(good_sjson.name)
transcripts = self.item.get_transcripts_info()
text, filename, mime_type = self.item.get_transcript(transcripts, transcript_format="txt")
expected_text = textwrap.dedent("""\
Hi, welcome to Edx.
Let's start with what is on your screen right now.""")
self.assertEqual(text, expected_text)
self.assertEqual(filename, self.item.sub + '.txt')
self.assertEqual(mime_type, 'text/plain; charset=utf-8')
示例13: test_py3k_commutative_with_config_disable
def test_py3k_commutative_with_config_disable(self):
module = join(HERE, 'regrtest_data', 'py3k_errors_and_warnings.py')
rcfile = join(HERE, 'regrtest_data', 'py3k-disabled.rc')
cmd = [module, "--msg-template='{msg}'", "--reports=n"]
expected = textwrap.dedent("""
************* Module py3k_errors_and_warnings
import missing `from __future__ import absolute_import`
Use raise ErrorClass(args) instead of raise ErrorClass, args.
Calling a dict.iter*() method
print statement used
""")
self._test_output(cmd + ["--py3k"], expected_output=expected)
expected = textwrap.dedent("""
************* Module py3k_errors_and_warnings
Use raise ErrorClass(args) instead of raise ErrorClass, args.
Calling a dict.iter*() method
print statement used
""")
self._test_output(cmd + ["--py3k", "--rcfile", rcfile],
expected_output=expected)
expected = textwrap.dedent("""
************* Module py3k_errors_and_warnings
Use raise ErrorClass(args) instead of raise ErrorClass, args.
print statement used
""")
self._test_output(cmd + ["--py3k", "-E", "--rcfile", rcfile],
expected_output=expected)
self._test_output(cmd + ["-E", "--py3k", "--rcfile", rcfile],
expected_output=expected)
示例14: getMissingImportStr
def getMissingImportStr(modNameList):
"""
Given a list of missing module names, returns a nicely-formatted message to the user
that gives instructions on how to expand music21 with optional packages.
>>> print(common.getMissingImportStr(['matplotlib']))
Certain music21 functions might need the optional package matplotlib;
if you run into errors, install it by following the instructions at
http://mit.edu/music21/doc/installing/installAdditional.html
>>> print(common.getMissingImportStr(['matplotlib', 'numpy']))
Certain music21 functions might need these optional packages: matplotlib, numpy;
if you run into errors, install them by following the instructions at
http://mit.edu/music21/doc/installing/installAdditional.html
"""
if len(modNameList) == 0:
return None
elif len(modNameList) == 1:
return textwrap.dedent(
"""\
Certain music21 functions might need the optional package %s;
if you run into errors, install it by following the instructions at
http://mit.edu/music21/doc/installing/installAdditional.html"""
% modNameList[0]
)
else:
return textwrap.dedent(
"""\
Certain music21 functions might need these optional packages: %s;
if you run into errors, install them by following the instructions at
http://mit.edu/music21/doc/installing/installAdditional.html"""
% ", ".join(modNameList)
)
示例15: test_api_token_authentication
def test_api_token_authentication(self):
# Given
yaml_string = textwrap.dedent("""\
authentication:
kind: token
api_token: ulysse
""")
# When
config = Configuration.from_yaml_filename(StringIO(yaml_string))
# Then
self.assertFalse(config.use_webservice)
self.assertEqual(config.auth, APITokenAuth("ulysse"))
# Given
yaml_string = textwrap.dedent("""\
authentication:
api_token: ulysse
""")
# When
config = Configuration.from_yaml_filename(StringIO(yaml_string))
# Then
self.assertFalse(config.use_webservice)
self.assertEqual(config.auth, APITokenAuth("ulysse"))