本文整理汇总了Python中utils.temp_dir函数的典型用法代码示例。如果您正苦于以下问题:Python temp_dir函数的具体用法?Python temp_dir怎么用?Python temp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了temp_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_installer
def test_create_installer(self):
# create_installer() creates an iss-style installer and copies it
# to the ci dir.
with temp_dir() as iss_dir:
with temp_dir() as ci_dir:
installer_name = 'juju-setup-1.20.1.exe'
def make_installer(*args, **kwargs):
output_dir = os.path.join(iss_dir, 'output')
os.makedirs(output_dir)
installer_path = os.path.join(
output_dir, installer_name)
with open(installer_path, 'w') as fake_installer:
fake_installer.write('juju installer')
with patch('winbuildtest.run',
return_value='',
side_effect=make_installer) as run_mock:
devnull = open(os.devnull, 'w')
with patch('sys.stdout', devnull):
create_installer('1.20.1', iss_dir, ISS_CMD, ci_dir)
args, kwargs = run_mock.call_args
self.assertEqual((ISS_CMD, 'setup.iss'), args)
installer_path = os.path.join(ci_dir, installer_name)
self.assertTrue(os.path.isfile(installer_path))
示例2: test_create_cloud_agent
def test_create_cloud_agent(self):
# create_cloud_agent() creates an agent tgz from the jujud and
# copies it to the ci dir.
with temp_dir() as cmd_dir:
with temp_dir() as ci_dir:
with open('%s/jujud.exe' % cmd_dir, 'w') as fake_jujud:
fake_jujud.write('jujud')
create_cloud_agent('1.20.1', cmd_dir, ci_dir)
agent = os.path.join(ci_dir, 'juju-1.20.1-win2012-amd64.tgz')
self.assertTrue(os.path.isfile(agent))
with tarfile.open(name=agent, mode='r:gz') as tar:
self.assertEqual(['jujud.exe'], tar.getnames())
示例3: test_upload_packages
def test_upload_packages(self, up_mock):
# assigning a side_effect requires an iterable, unlike instantiation.
up_mock.side_effect = iter([False, True])
team = Mock(name='bar', getPPAByName=Mock())
team.getPPAByName.return_value = 'baz'
lp = Mock(people={'bar': team})
with temp_dir() as package_dir1:
with temp_dir() as package_dir2:
upload_packages(
lp, 'ppa:bar/baz', [package_dir1, package_dir2],
dry_run=False)
call1 = call('ppa:bar/baz', 'baz', package_dir1, dry_run=False)
call2 = call('ppa:bar/baz', 'baz', package_dir2, dry_run=False)
self.assertEqual([call1, call2], up_mock.mock_calls)
team.getPPAByName.assert_called_once_with(name='baz')
示例4: test_cpc_generate_mirrors_file_deprecated_tree
def test_cpc_generate_mirrors_file_deprecated_tree(self):
updated = datetime.datetime.utcnow()
with temp_dir() as base_path:
stream_path = '%s/devel/tools/streams/v1' % base_path
os.makedirs(stream_path)
generate_cpc_mirrors_file(updated, stream_path)
mirror_path = '%s/cpc-mirrors.json' % stream_path
self.assertTrue(os.path.isfile(mirror_path))
with open(mirror_path) as mirror_file:
data = json.load(mirror_file)
product_name = 'com.ubuntu.juju:released:tools'
self.assertEqual([product_name], data['mirrors'].keys())
purposeful_mirror = data['mirrors'][product_name]
purpose = product_name.split(':')[1]
self.assertEqual(
'streams/v1/com.ubuntu.juju-%s-tools.json' % purpose,
purposeful_mirror[0]['path'])
self.assertEqual(
'https://juju-dist.s3.amazonaws.com/devel/tools',
purposeful_mirror[0]['mirror'])
self.assertEqual(11, len(purposeful_mirror[0]['clouds']))
self.assertEqual(
'https://jujutools.blob.core.windows.net'
'/juju-tools/devel/tools',
purposeful_mirror[1]['mirror'])
self.assertEqual(17, len(purposeful_mirror[1]['clouds']))
self.assertEqual(
("https://us-east.manta.joyent.com/"
"cpcjoyentsupport/public/juju-dist/devel/tools"),
purposeful_mirror[2]['mirror'])
self.assertEqual(6, len(purposeful_mirror[2]['clouds']))
示例5: test_cpc_generate_mirrors_file
def test_cpc_generate_mirrors_file(self):
updated = datetime.datetime.utcnow()
with temp_dir() as base_path:
stream_path = '%s/tools/streams/v1' % base_path
os.makedirs(stream_path)
generate_cpc_mirrors_file(updated, stream_path)
mirror_path = '%s/cpc-mirrors.json' % stream_path
self.assertTrue(os.path.isfile(mirror_path))
with open(mirror_path) as mirror_file:
data = json.load(mirror_file)
self.assertEqual(['format', 'mirrors', 'updated'], sorted(data.keys()))
self.assertEqual('mirrors:1.0', data['format'])
expected_updated = updated.strftime('%a, %d %b %Y %H:%M:%S -0000')
self.assertEqual(expected_updated, data['updated'])
expected_produts = sorted(
'com.ubuntu.juju:%s:tools' % p for p in PURPOSES)
for product_name in expected_produts:
purposeful_mirrors = data['mirrors'][product_name]
purpose = product_name.split(':')[1]
self.assertEqual(
'streams/v1/com.ubuntu.juju-%s-tools.json' % purpose,
purposeful_mirrors[0]['path'])
self.assertEqual(
'https://juju-dist.s3.amazonaws.com/tools',
purposeful_mirrors[0]['mirror'])
self.assertEqual(11, len(purposeful_mirrors[0]['clouds']))
self.assertEqual(
'https://jujutools.blob.core.windows.net/juju-tools/tools',
purposeful_mirrors[1]['mirror'])
self.assertEqual(17, len(purposeful_mirrors[1]['clouds']))
self.assertEqual(
("https://us-east.manta.joyent.com/"
"cpcjoyentsupport/public/juju-dist/tools"),
purposeful_mirrors[2]['mirror'])
self.assertEqual(6, len(purposeful_mirrors[2]['clouds']))
示例6: test_get_filenames_url
def test_get_filenames_url(self):
with temp_dir() as temp:
with temp_cwd(temp):
h_file, j_file = cloud_weather_report.get_filenames(
'http://example.com/~git')
self.assertTrue(h_file.startswith(
'results/http___example_com__git') and h_file.endswith('.html'))
self.assertTrue(j_file.startswith(
'results/http___example_com__git') and j_file.endswith('.json'))
with temp_dir() as temp:
with temp_cwd(temp):
h_file, j_file = cloud_weather_report.get_filenames(
'cs:~user/mysql-benchmark')
self.assertTrue(j_file.startswith(
'results/cs__user_mysql_benchmark') and j_file.endswith('.json'))
示例7: test_make_client_tarball
def test_make_client_tarball(self):
with temp_dir() as base_dir:
cmd_dir = os.path.join(base_dir, 'foo')
os.makedirs(cmd_dir)
juju_binary = os.path.join(cmd_dir, 'juju')
readme_file = os.path.join(cmd_dir, 'README.txt')
for path in [juju_binary, readme_file]:
with open(path, 'w') as jb:
jb.write('juju')
os.chmod(juju_binary, 0o775)
os.chmod(readme_file, 0o664)
make_client_tarball(
'osx', [juju_binary, readme_file], '1.2.3', base_dir)
osx_tarball_path = os.path.join(base_dir, 'juju-1.2.3-osx.tar.gz')
self.assertTrue(os.path.isfile(osx_tarball_path))
with tarfile.open(osx_tarball_path, 'r:gz') as tar:
self.assertEqual(
['juju-bin', 'juju-bin/juju', 'juju-bin/README.txt'],
tar.getnames())
self.assertEqual(
0o775, tar.getmember('juju-bin').mode)
self.assertEqual(
0o775, tar.getmember('juju-bin/juju').mode)
self.assertEqual(
0o664, tar.getmember('juju-bin/README.txt').mode)
示例8: test_consolidate_deps
def test_consolidate_deps(self):
expected_deps = {
'github/foo': Dependency('github/foo', 'git', 'rev123', None),
'github/bar': Dependency('github/bar', 'git', 'rev456', None),
'github/baz': Dependency('github/baz', 'git', 'rev789', None),
'github/qux': Dependency('github/qux', 'git', 'revdef', None),
'lp/qoh': Dependency('lp/qoh', 'bzr', 'rev789', '3')
}
conflict_dep = Dependency('github/baz', 'git', 'revabc', None)
with temp_dir() as base_dir:
a_dep_file = '%s/a.tsv' % base_dir
with open(a_dep_file, 'w') as f:
f.write(expected_deps['github/foo'].to_line())
f.write(expected_deps['github/bar'].to_line())
f.write(expected_deps['github/baz'].to_line())
b_dep_file = '%s/b.tsv' % base_dir
with open(b_dep_file, 'w') as f:
f.write(expected_deps['github/foo'].to_line())
f.write(conflict_dep.to_line())
f.write(expected_deps['github/qux'].to_line())
f.write(expected_deps['lp/qoh'].to_line())
dep_file = DependencyFile([a_dep_file, b_dep_file])
deps, conflicts = dep_file.consolidate_deps()
self.assertEqual([(b_dep_file, conflict_dep)], conflicts)
self.assertEqual(expected_deps, deps)
示例9: test_parse_args_signing_passphrase_file
def test_parse_args_signing_passphrase_file(self):
with temp_dir() as metadata_dir:
with NamedTemporaryFile() as pass_file:
args = parse_args([metadata_dir, 's_key',
'--signing-passphrase-file', pass_file.name])
self.assertEqual(args, Namespace(
signing_key='s_key', signing_passphrase_file=pass_file.name,
metadata_dir=metadata_dir))
示例10: test_no_patchdir
def test_no_patchdir(self):
stream = StringIO.StringIO()
with temp_dir() as basedir:
with self.assertRaises(SystemExit):
with mock.patch("sys.stderr", stream):
main(["test", os.path.join(basedir, "missing"), basedir])
self.assertRegexpMatches(
stream.getvalue(), "Could not list patch directory: .*/missing")
示例11: test_no_srctree
def test_no_srctree(self):
stream = StringIO.StringIO()
with temp_dir() as basedir:
with self.assertRaises(SystemExit):
with mock.patch("sys.stderr", stream):
main(["test", basedir, os.path.join(basedir, "missing")])
self.assertRegexpMatches(
stream.getvalue(), "Source tree '.*/missing' not a directory")
示例12: test_working_directory
def test_working_directory(self):
this_dir = os.getcwd()
with temp_dir() as base_dir:
new_dir = os.path.join(base_dir, 'juju-core_1.2.3')
os.makedirs(new_dir)
with working_directory(new_dir):
self.assertEqual(os.path.realpath(new_dir), os.getcwd())
self.assertEqual(this_dir, os.getcwd())
示例13: test_write_item_streams
def test_write_item_streams(self):
now = datetime(2001, 2, 3)
east_image = make_mock_image(region_name='us-east-1')
west_image = make_mock_image(region_name='us-west-1')
items = [make_item(west_image, now), make_item(east_image, now)]
with temp_dir() as streams:
with patch('simplestreams.util.timestamp',
return_value='now'):
with patch('sys.stderr'):
write_item_streams(items, streams)
self.assertFalse(
os.path.exists(os.path.join(streams, 'streams', 'v1',
'index2.json')))
index = load_json(streams, 'index.json')
releases = load_json(streams, 'com.ubuntu.cloud.released-aws.json')
self.assertEqual(
{'format': 'index:1.0', 'updated': 'now', 'index': {
'com.ubuntu.cloud.released:aws': {
'format': 'products:1.0',
'updated': 'now',
'datatype': 'image-ids',
'path': 'streams/v1/com.ubuntu.cloud.released-aws.json',
'products': ['com.ubuntu.cloud:server:centos7:amd64'],
}
}}, index)
expected = {
'content_id': 'com.ubuntu.cloud.released:aws',
'format': 'products:1.0',
'updated': 'now',
'datatype': 'image-ids',
'products': {'com.ubuntu.cloud:server:centos7:amd64': {
'endpoint': 'https://foo',
'arch': 'amd64',
'release_title': 'Centos 7',
'label': 'release',
'release_codename': 'centos7',
'version': 'centos7',
'release': 'centos7',
'os': 'centos',
'versions': {'20010203': {
'items': {
'usww1he': {
'id': 'qux',
'region': 'us-west-1',
'root_store': 'ebs',
'virt': 'hvm',
},
'usee1he': {
'id': 'qux',
'region': 'us-east-1',
'root_store': 'ebs',
'virt': 'hvm',
},
}
}},
}},
}
self.assertEqual(releases, expected)
示例14: test_generate_index_file
def test_generate_index_file(self):
updated = datetime.datetime.utcnow()
with temp_dir() as base_path:
stream_path = '%s/tools/streams/v1' % base_path
os.makedirs(stream_path)
generate_index_file(updated, stream_path)
index_path = '%s/index.json' % stream_path
self.assertTrue(os.path.isfile(index_path))
with open(index_path) as index_file:
data = json.load(index_file)
self.assertEqual(['format', 'index', 'updated'], sorted(data.keys()))
self.assertEqual('index:1.0', data['format'])
expected_updated = updated.strftime('%a, %d %b %Y %H:%M:%S -0000')
self.assertEqual(expected_updated, data['updated'])
product_name = 'com.ubuntu.juju:released:tools'
self.assertEqual([product_name], data['index'].keys())
released_index = data['index'][product_name]
self.assertEqual(
['datatype', 'format', 'path', 'products', 'updated'],
sorted(released_index.keys()))
self.assertEqual('content-download', released_index['datatype'])
self.assertEqual('products:1.0', released_index['format'])
self.assertEqual(
'streams/v1/com.ubuntu.juju:released:tools.json',
released_index['path'])
self.assertEqual(expected_updated, released_index['updated'])
self.assertEqual(
['com.ubuntu.juju:12.04:amd64',
'com.ubuntu.juju:12.04:armhf',
'com.ubuntu.juju:12.04:i386',
'com.ubuntu.juju:12.10:amd64',
'com.ubuntu.juju:12.10:i386',
'com.ubuntu.juju:13.04:amd64',
'com.ubuntu.juju:13.04:i386',
'com.ubuntu.juju:13.10:amd64',
'com.ubuntu.juju:13.10:armhf',
'com.ubuntu.juju:13.10:i386',
'com.ubuntu.juju:14.04:amd64',
'com.ubuntu.juju:14.04:arm64',
'com.ubuntu.juju:14.04:armhf',
'com.ubuntu.juju:14.04:i386',
'com.ubuntu.juju:14.04:powerpc',
'com.ubuntu.juju:14.04:ppc64',
'com.ubuntu.juju:14.04:ppc64el',
'com.ubuntu.juju:14.10:amd64',
'com.ubuntu.juju:14.10:arm64',
'com.ubuntu.juju:14.10:armhf',
'com.ubuntu.juju:14.10:i386',
'com.ubuntu.juju:14.10:ppc64',
'com.ubuntu.juju:14.10:ppc64el',
'com.ubuntu.juju:15.04:amd64',
'com.ubuntu.juju:15.04:arm64',
'com.ubuntu.juju:15.04:armhf',
'com.ubuntu.juju:15.04:i386',
'com.ubuntu.juju:15.04:ppc64',
'com.ubuntu.juju:15.04:ppc64el'],
released_index['products'])
示例15: test_setup_local
def test_setup_local(self):
with temp_dir() as workspace:
source_files = make_source_files(workspace, 'my.dsc')
build_dir = setup_local(
workspace, 'trusty', 'i386', source_files, verbose=False)
self.assertEqual(
os.path.join(workspace, 'juju-build-trusty-i386'),
build_dir)
self.assertTrue(os.path.isdir(build_dir))