本文整理汇总了Python中fixtures.TempDir方法的典型用法代码示例。如果您正苦于以下问题:Python fixtures.TempDir方法的具体用法?Python fixtures.TempDir怎么用?Python fixtures.TempDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fixtures
的用法示例。
在下文中一共展示了fixtures.TempDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def setUp(self):
super(SkipFileWrites, self).setUp()
self.temp_path = self.useFixture(fixtures.TempDir()).path
self.root_dir = os.path.abspath(os.path.curdir)
self.git_dir = os.path.join(self.root_dir, ".git")
if not os.path.exists(self.git_dir):
self.skipTest("%s is missing; skipping git-related checks"
% self.git_dir)
return
self.filename = os.path.join(self.temp_path, self.filename)
self.option_dict = dict()
if self.option_key is not None:
self.option_dict[self.option_key] = ('setup.cfg',
self.option_value)
self.useFixture(
fixtures.EnvironmentVariable(self.env_key, self.env_value))
示例2: _setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def _setUp(self):
tmpdir = self.useFixture(fixtures.TempDir()).path
package_dirs = {}
for pkg_name in self.packages:
pkg_path = os.path.join(tmpdir, pkg_name)
package_dirs[pkg_name] = pkg_path
os.mkdir(pkg_path)
for cf in ['setup.py', 'setup.cfg']:
if cf in self.packages[pkg_name]:
contents = self.packages[pkg_name].pop(cf)
else:
contents = self.defaults[cf].format(pkg_name=pkg_name)
self._writeFile(pkg_path, cf, contents)
for cf in self.packages[pkg_name]:
self._writeFile(pkg_path, cf, self.packages[pkg_name][cf])
self.useFixture(TestRepo(pkg_path)).commit()
self.addCleanup(delattr, self, 'package_dirs')
self.package_dirs = package_dirs
return package_dirs
示例3: _setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def _setUp(self):
super(RealPolicyFixture, self)._setUp()
self.policy_dir = self.useFixture(fixtures.TempDir())
self.policy_file = os.path.join(self.policy_dir.path, 'policy.yaml')
# Load the fake_policy data and add the missing default rules.
policy_rules = yaml.safe_load(fake_policy.policy_data)
self.add_missing_default_rules(policy_rules)
with open(self.policy_file, 'w') as f:
yaml.safe_dump(policy_rules, f)
policy_opts.set_defaults(CONF)
self.useFixture(
ConfPatcher(
policy_dirs=[],
policy_file=self.policy_file,
group='oslo_policy'))
armada.common.policy.reset_policy()
armada.common.policy.setup_policy()
self.addCleanup(armada.common.policy.reset_policy)
if self.verify:
self._install_policy_verification_hook()
示例4: test_get_helm_chart_with_values
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_get_helm_chart_with_values(self):
chart_dir = self.useFixture(fixtures.TempDir())
self.addCleanup(shutil.rmtree, chart_dir.path)
self._write_temporary_file_contents(
chart_dir.path, 'Chart.yaml', self.chart_yaml)
self._write_temporary_file_contents(
chart_dir.path, 'values.yaml', self.chart_value)
ch = yaml.safe_load(self.chart_stream)
ch['data']['source_dir'] = (chart_dir.path, '')
test_chart = ch
chartbuilder = ChartBuilder.from_chart_doc(test_chart)
helm_chart = chartbuilder.get_helm_chart()
self.assertIsInstance(helm_chart, Chart)
self.assertTrue(hasattr(helm_chart, 'metadata'))
self.assertTrue(hasattr(helm_chart, 'values'))
self.assertTrue(hasattr(helm_chart.values, 'raw'))
self.assertEqual(self.chart_value, helm_chart.values.raw)
示例5: test_get_files_always_fails_to_read_binary_file_raises_exc
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_get_files_always_fails_to_read_binary_file_raises_exc(self):
chart_dir = self.useFixture(fixtures.TempDir())
self.addCleanup(shutil.rmtree, chart_dir.path)
for filename in ['foo', 'bar', 'Chart.yaml', 'values.yaml']:
self._write_temporary_file_contents(
chart_dir.path, filename, "DIRC^@^@^@^B^@^@^@×Z®<86>F.1")
chartbuilder = ChartBuilder.from_chart_doc(
self._get_test_chart(chart_dir))
# Confirm it failed for both encodings.
error_re = (
r'.*A str exception occurred while trying to read file:'
r'.*Details:\n.*\(encoding=utf-8\).*\n\(encoding=latin1\)')
with mock.patch("builtins.open", mock.mock_open(read_data="")) \
as mock_file:
mock_file.return_value.read.side_effect = self.exc_to_raise
self.assertRaisesRegexp(
chartbuilder_exceptions.FilesLoadException, error_re,
chartbuilder.get_files)
示例6: _setUp
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def _setUp(self):
super(RealPolicyFixture, self)._setUp()
self.policy_dir = self.useFixture(fixtures.TempDir())
self.policy_file = os.path.join(self.policy_dir.path,
'policy.yaml')
# Load the fake_policy data and add the missing default rules.
policy_rules = yaml.safe_load(fake_policy.policy_data)
self.add_missing_default_rules(policy_rules)
with open(self.policy_file, 'w') as f:
yaml.safe_dump(policy_rules, f)
policy_opts.set_defaults(CONF)
self.useFixture(
ConfPatcher(policy_dirs=[], policy_file=self.policy_file,
group='oslo_policy'))
armada.common.policy.reset_policy()
armada.common.policy.setup_policy()
self.addCleanup(armada.common.policy.reset_policy)
if self.verify:
self._install_policy_verification_hook()
示例7: test_get_helm_chart_with_values
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_get_helm_chart_with_values(self):
chart_dir = self.useFixture(fixtures.TempDir())
self.addCleanup(shutil.rmtree, chart_dir.path)
self._write_temporary_file_contents(chart_dir.path, 'Chart.yaml',
self.chart_yaml)
self._write_temporary_file_contents(chart_dir.path, 'values.yaml',
self.chart_value)
ch = yaml.safe_load(self.chart_stream)['chart']
ch['source_dir'] = (chart_dir.path, '')
test_chart = ch
chartbuilder = ChartBuilder(test_chart)
helm_chart = chartbuilder.get_helm_chart()
self.assertIsInstance(helm_chart, Chart)
self.assertTrue(hasattr(helm_chart, 'metadata'))
self.assertTrue(hasattr(helm_chart, 'values'))
self.assertTrue(hasattr(helm_chart.values, 'raw'))
self.assertEqual(self.chart_value, helm_chart.values.raw)
示例8: test_get_files_fails_once_to_read_binary_file_passes
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_get_files_fails_once_to_read_binary_file_passes(self):
chart_dir = self.useFixture(fixtures.TempDir())
self.addCleanup(shutil.rmtree, chart_dir.path)
files = ['foo', 'bar']
for filename in files:
self._write_temporary_file_contents(
chart_dir.path, filename, "DIRC^@^@^@^B^@^@^@×Z®<86>F.1")
test_chart = {'source_dir': (chart_dir.path, '')}
chartbuilder = ChartBuilder(test_chart)
side_effects = [self.exc_to_raise, "", ""]
with mock.patch("builtins.open", mock.mock_open(read_data="")) \
as mock_file:
mock_file.return_value.read.side_effect = side_effects
chartbuilder.get_files()
示例9: test_configure_add_with_multi_datadirs
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_configure_add_with_multi_datadirs(self):
"""
Tests multiple filesystem specified by filesystem_store_datadirs
are parsed correctly.
"""
store_map = [self.useFixture(fixtures.TempDir()).path,
self.useFixture(fixtures.TempDir()).path]
self.conf.set_override('filesystem_store_datadir',
override=None,
group='glance_store')
self.conf.set_override('filesystem_store_datadirs',
[store_map[0] + ":100",
store_map[1] + ":200"],
group='glance_store')
self.store.configure_add()
expected_priority_map = {100: [store_map[0]], 200: [store_map[1]]}
expected_priority_list = [200, 100]
self.assertEqual(expected_priority_map, self.store.priority_data_map)
self.assertEqual(expected_priority_list, self.store.priority_list)
示例10: test_configure_add_same_dir_multiple_times
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_configure_add_same_dir_multiple_times(self):
"""
Tests BadStoreConfiguration exception is raised if same directory
is specified multiple times in filesystem_store_datadirs.
"""
store_map = [self.useFixture(fixtures.TempDir()).path,
self.useFixture(fixtures.TempDir()).path]
self.conf.clear_override('filesystem_store_datadir',
group='glance_store')
self.conf.set_override('filesystem_store_datadirs',
[store_map[0] + ":100",
store_map[1] + ":200",
store_map[0] + ":300"],
group='glance_store')
self.assertRaises(exceptions.BadStoreConfiguration,
self.store.configure_add)
示例11: test_configure_add_same_dir_multiple_times
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_configure_add_same_dir_multiple_times(self):
"""Tests handling of same dir in config multiple times.
Tests BadStoreConfiguration exception is raised if same directory
is specified multiple times in filesystem_store_datadirs with different
priorities.
"""
store_map = [self.useFixture(fixtures.TempDir()).path,
self.useFixture(fixtures.TempDir()).path]
self.conf.clear_override('filesystem_store_datadir',
group='file1')
self.conf.set_override('filesystem_store_datadirs',
[store_map[0] + ":100",
store_map[1] + ":200",
store_map[0] + ":300"],
group='file1')
self.assertRaises(exceptions.BadStoreConfiguration,
self.store.configure_add)
示例12: test_main_git_command_failure
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_main_git_command_failure(self):
# Test that bandit does not run when the Git command fails
repo_directory = self.useFixture(fixtures.TempDir()).path
git_repo = git.Repo.init(repo_directory)
git_repo.index.commit('Initial Commit')
os.chdir(repo_directory)
additional_content = 'additional_file.py'
with open(additional_content, 'wt') as fd:
fd.write(self.temp_file_contents)
git_repo.index.add([additional_content])
git_repo.index.commit('Additional Content')
with mock.patch('git.Repo.commit') as mock_git_repo_commit:
mock_git_repo_commit.side_effect = git.exc.GitCommandError(
'commit', '')
# assert the system exits with code 2
self.assertRaisesRegex(SystemExit, '2', baseline.main)
示例13: test_initialize_git_command_failure
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_initialize_git_command_failure(self):
# Test that bandit does not run when the Git command fails
repo_directory = self.useFixture(fixtures.TempDir()).path
git_repo = git.Repo.init(repo_directory)
git_repo.index.commit('Initial Commit')
os.chdir(repo_directory)
additional_content = 'additional_file.py'
with open(additional_content, 'wt') as fd:
fd.write(self.temp_file_contents)
git_repo.index.add([additional_content])
git_repo.index.commit('Additional Content')
with mock.patch('git.Repo') as mock_git_repo:
mock_git_repo.side_effect = git.exc.GitCommandNotFound('clone', '')
return_value = baseline.initialize()
# assert bandit did not run due to git command failure
self.assertEqual((None, None, None), return_value)
示例14: test_initialize_dirty_repo
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_initialize_dirty_repo(self):
# Test that bandit does not run when the current git repository is
# 'dirty' when calling the initialize method
repo_directory = self.useFixture(fixtures.TempDir()).path
git_repo = git.Repo.init(repo_directory)
git_repo.index.commit('Initial Commit')
os.chdir(repo_directory)
# make the git repo 'dirty'
with open('dirty_file.py', 'wt') as fd:
fd.write(self.temp_file_contents)
git_repo.index.add(['dirty_file.py'])
return_value = baseline.initialize()
# assert bandit did not run due to dirty repo
self.assertEqual((None, None, None), return_value)
示例15: test_initialize_existing_report_file
# 需要导入模块: import fixtures [as 别名]
# 或者: from fixtures import TempDir [as 别名]
def test_initialize_existing_report_file(self):
# Test that bandit does not run when the output file exists (and the
# provided output format does not match the default format) when
# calling the initialize method
repo_directory = self.useFixture(fixtures.TempDir()).path
git_repo = git.Repo.init(repo_directory)
git_repo.index.commit('Initial Commit')
os.chdir(repo_directory)
# create an existing version of output report file
existing_report = "{}.{}".format(baseline.report_basename, 'txt')
with open(existing_report, 'wt') as fd:
fd.write(self.temp_file_contents)
return_value = baseline.initialize()
# assert bandit did not run due to existing report file
self.assertEqual((None, None, None), return_value)