本文整理匯總了Python中testtools.content.text_content方法的典型用法代碼示例。如果您正苦於以下問題:Python content.text_content方法的具體用法?Python content.text_content怎麽用?Python content.text_content使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類testtools.content
的用法示例。
在下文中一共展示了content.text_content方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_command_hooks
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_command_hooks(self):
"""Test command hooks.
Simple test that the appropriate command hooks run at the
beginning/end of the appropriate command.
"""
stdout, _, return_code = self.run_setup('egg_info')
assert 'build_ext pre-hook' not in stdout
assert 'build_ext post-hook' not in stdout
assert return_code == 0
stdout, stderr, return_code = self.run_setup('build_ext')
self.addDetailUniqueName('stderr', text_content(stderr))
assert textwrap.dedent("""
running build_ext
running pre_hook pbr_testpackage._setup_hooks.test_pre_hook for command build_ext
build_ext pre-hook
""") in stdout # flake8: noqa
self.expectThat(stdout, EndsWith('build_ext post-hook'))
assert return_code == 0
示例2: test_volume_to_image
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_volume_to_image(self):
'''Test volume export to image functionality'''
volume_name = self.getUniqueString()
image_name = self.getUniqueString()
self.addDetail('volume', content.text_content(volume_name))
self.addCleanup(self.cleanup, volume_name, image_name=image_name)
volume = self.user_cloud.create_volume(
display_name=volume_name, size=1)
image = self.user_cloud.create_image(
image_name, volume=volume, wait=True)
volume_ids = [v['id'] for v in self.user_cloud.list_volumes()]
self.assertIn(volume['id'], volume_ids)
image_list = self.user_cloud.list_images()
image_ids = [s['id'] for s in image_list]
self.assertIn(image['id'], image_ids)
self.user_cloud.delete_image(image_name, wait=True)
self.user_cloud.delete_volume(volume_name, wait=True)
示例3: test_staged_file
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_staged_file(self):
# Prove that we can get a file we have staged.
# Start with a standard commit and tag
self._make_python_package()
self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0')
# Now stage a release note
n = self.get_note_num()
basename = 'staged-note-%016x.yaml' % n
filename = os.path.join(self.reporoot, 'releasenotes', 'notes',
basename)
create._make_note_file(filename, 'staged note')
self.repo.git('add', filename)
status_results = self.repo.git('status')
self.addDetail('git status', text_content(status_results))
# Now run the scanner
self.scanner = scanner.Scanner(self.c)
raw_results = self.scanner.get_notes_by_version()
self.assertEqual(
{'*working-copy*': [
(os.path.join('releasenotes', 'notes', basename),
None)],
},
raw_results,
)
示例4: test_added_tagged_not_staged
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_added_tagged_not_staged(self):
# Prove that we can get a file we have created but not staged.
# Start with a standard commit and tag
self._make_python_package()
self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0')
# Now create a note without staging it
n = self.get_note_num()
basename = 'staged-note-%016x.yaml' % n
filename = os.path.join(self.reporoot, 'releasenotes', 'notes',
basename)
create._make_note_file(filename, 'staged note')
status_results = self.repo.git('status')
self.addDetail('git status', text_content(status_results))
# Now run the scanner
self.scanner = scanner.Scanner(self.c)
raw_results = self.scanner.get_notes_by_version()
# Take the staged version of the file, but associate it with
# tagged version 1.0.0 because the file was added before that
# version.
self.assertEqual(
{'1.0.0': [(os.path.join('releasenotes', 'notes', basename),
None)],
},
raw_results,
)
示例5: test_modified_tagged_not_staged
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_modified_tagged_not_staged(self):
# Prove that we can get a file we have changed but not staged.
# Start with a standard commit and tag
self._make_python_package()
f1 = self._add_notes_file('slug1')
self.repo.git('tag', '-s', '-m', 'first tag', '1.0.0')
# Now modify the note
fullpath = os.path.join(self.repo.reporoot, f1)
with open(fullpath, 'w') as f:
f.write('modified first note')
status_results = self.repo.git('status')
self.addDetail('git status', text_content(status_results))
# Now run the scanner
self.scanner = scanner.Scanner(self.c)
raw_results = self.scanner.get_notes_by_version()
# Take the staged version of the file, but associate it with
# tagged version 1.0.0 because the file was added before that
# version.
self.assertEqual(
{'1.0.0': [(f1, None)],
},
raw_results,
)
示例6: test_files_current_branch
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_files_current_branch(self):
self.repo.git('checkout', '2.0.0')
self.repo.git('checkout', '-b', 'stable/2')
f21 = self._add_notes_file('slug21')
log_text = self.repo.git('log', '--decorate')
self.addDetail('git log', text_content(log_text))
self.scanner = scanner.Scanner(self.c)
raw_results = self.scanner.get_notes_by_version()
results = {
k: [f for (f, n) in v]
for (k, v) in raw_results.items()
}
self.assertEqual(
{
'2.0.0-1': [f21],
'2.0.0': [self.f2],
},
results,
)
示例7: test_twistd_low_verbosity
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_twistd_low_verbosity(self):
verbosity, set_verbosity = self._get_log_levels(1)
name = factory.make_name("log.name")
logged = log_something(
name,
verbosity=verbosity,
set_verbosity=set_verbosity,
mode=LoggingMode.TWISTD,
)
self.addDetail("logged", text_content(logged))
observed = find_log_lines(logged)
expected = [
(name, "warn", "From `twisted.logger`."),
(name, "error", "From `twisted.logger`."),
(name, "warn", "From `logging`."),
(name, "error", "From `logging`."),
("maas." + name, "warn", "From `get_maas_logger`."),
("maas." + name, "error", "From `get_maas_logger`."),
("stderr", "error", "Printing to stderr."),
("-", "warn", "UserWarning: This is a warning!"),
]
self.assertSequenceEqual(expected, observed)
示例8: test_twistd_lowest_verbosity
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_twistd_lowest_verbosity(self):
verbosity, set_verbosity = self._get_log_levels(0)
name = factory.make_name("log.name")
logged = log_something(
name,
verbosity=verbosity,
set_verbosity=set_verbosity,
mode=LoggingMode.TWISTD,
)
self.addDetail("logged", text_content(logged))
observed = find_log_lines(logged)
expected = [
(name, "error", "From `twisted.logger`."),
(name, "error", "From `logging`."),
("maas." + name, "error", "From `get_maas_logger`."),
("stderr", "error", "Printing to stderr."),
]
self.assertSequenceEqual(expected, observed)
示例9: get_details
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def get_details(self):
return {
'expected': content.text_content(self.expected),
'actual': content.text_content(self.actual),
}
示例10: setUp
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def setUp(self):
super(CapturedSubprocess, self).setUp()
proc = subprocess.Popen(*self.args, **self.kwargs)
out, err = proc.communicate()
self.out = out.decode('utf-8', 'replace')
self.err = err.decode('utf-8', 'replace')
self.addDetail(self.label + '-stdout', content.text_content(self.out))
self.addDetail(self.label + '-stderr', content.text_content(self.err))
self.returncode = proc.returncode
if proc.returncode:
raise AssertionError('Failed process %s' % proc.returncode)
self.addCleanup(delattr, self, 'out')
self.addCleanup(delattr, self, 'err')
self.addCleanup(delattr, self, 'returncode')
示例11: test_custom_build_py_command
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_custom_build_py_command(self):
"""Test custom build_py command.
Test that a custom subclass of the build_py command runs when listed in
the commands [global] option, rather than the normal build command.
"""
stdout, stderr, return_code = self.run_setup('build_py')
self.addDetail('stdout', content.text_content(stdout))
self.addDetail('stderr', content.text_content(stderr))
self.assertIn('Running custom build_py command.', stdout)
self.assertEqual(return_code, 0)
示例12: test_custom_rpm_version_py_command
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_custom_rpm_version_py_command(self):
"""Test custom rpm_version command."""
stdout, stderr, return_code = self.run_setup('rpm_version')
self.addDetail('stdout', content.text_content(stdout))
self.addDetail('stderr', content.text_content(stderr))
self.assertIn('Extracting rpm version', stdout)
self.assertEqual(return_code, 0)
示例13: test_template_error
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def test_template_error(self):
"""
Template errors result in the process exiting and an error message
printed to stderr.
Packer prints machine-readable output to stderr and
``publish-installer-images`` echos those lines to its stderr as well as
parsing the output.
"""
sys_module = FakeSysModule()
self.addCleanup(
lambda: self.addDetail(
name="stderr",
content_object=text_content(
sys_module.stderr.getvalue()
)
)
)
configuration_path = self.make_temporary_file(content='')
d = async_perform(
dispatcher=RealPerformers(
sys_module=sys_module,
).dispatcher(),
effect=Effect(
intent=PackerBuild(
configuration_path=configuration_path,
)
)
)
d = self.assertFailure(d, ProcessTerminated)
def check_error(exception):
self.assertEqual(1, exception.exitCode)
self.assertIn(
"Failed to parse template", sys_module.stderr.getvalue()
)
return d.addCallback(check_error)
示例14: _test_skipped
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def _test_skipped(case, result, exception):
result.addSkip(case, details={'reason': text_content(unicode(exception))})
示例15: _attempt_test
# 需要導入模塊: from testtools import content [as 別名]
# 或者: from testtools.content import text_content [as 別名]
def _attempt_test(self, case):
"""
Run 'case' with a temporary result.
:param testtools.TestCase case: The test to run.
:return: a tuple of ``(successful, result, details)``, where
``successful`` is a boolean indicating whether the test was
succcessful, ``result`` is a _ResultType indicating what the test
result was and ``details`` is a dictionary of testtools details.
"""
tmp_result = testtools.TestResult()
# XXX: Still using internal API of testtools despite improvements in
# #165. Will need to do follow-up work on testtools to ensure that
# RunTest.run(case); RunTest.run(case) is supported.
case._reset()
self._run_test(case, tmp_result)
result_type = _get_result_type(tmp_result)
details = pmap(case.getDetails())
if result_type == _ResultType.skip:
# XXX: Work around a testtools bug where it reports stack traces
# for skips that aren't passed through its supported
# SkipException: https://bugs.launchpad.net/testtools/+bug/1518100
[reason] = list(tmp_result.skip_reasons.keys())
details = details.discard('traceback').set(
'reason', text_content(reason))
return (tmp_result.wasSuccessful(), result_type, details)