• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.temp_dir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.temp_dir函数的典型用法代码示例。如果您正苦于以下问题:Python temp_dir函数的具体用法?Python temp_dir怎么用?Python temp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了temp_dir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:mjs,项目名称:juju,代码行数:25,代码来源:test_winbuildtest.py


示例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())
开发者ID:mjs,项目名称:juju,代码行数:12,代码来源:test_winbuildtest.py


示例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')
开发者ID:mjs,项目名称:juju,代码行数:15,代码来源:test_upload_packages.py


示例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']))
开发者ID:mjs,项目名称:juju,代码行数:31,代码来源:test_generate_mirrors.py


示例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']))
开发者ID:mjs,项目名称:juju,代码行数:35,代码来源:test_generate_mirrors.py


示例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'))
开发者ID:marcoceppi,项目名称:cloud-weather-report,代码行数:16,代码来源:test_cloud_weather_report.py


示例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)
开发者ID:mjs,项目名称:juju,代码行数:25,代码来源:test_crossbuild.py


示例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)
开发者ID:mjs,项目名称:juju,代码行数:25,代码来源:test_deptree.py


示例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))
开发者ID:mjs,项目名称:juju,代码行数:8,代码来源:test_sign_metadata.py


示例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")
开发者ID:mjs,项目名称:juju,代码行数:8,代码来源:test_apply_patches.py


示例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")
开发者ID:mjs,项目名称:juju,代码行数:8,代码来源:test_apply_patches.py


示例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())
开发者ID:mjs,项目名称:juju,代码行数:8,代码来源:test_crossbuild.py


示例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)
开发者ID:mjs,项目名称:juju,代码行数:58,代码来源:test_make_image_streams.py


示例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'])
开发者ID:mjs,项目名称:juju,代码行数:57,代码来源:test_generate_index.py


示例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))
开发者ID:mjs,项目名称:juju,代码行数:9,代码来源:test_build_package_lxd.py


示例16: test_diff_files

 def test_diff_files(self, gr_mock):
     gr_mock.return_value = 'one\ntwo\nthree'
     with temp_dir() as base:
         local_path = os.path.join(base, 'bar.json')
         with open(local_path, 'w') as local_file:
             local_file.write('one\ntwo\nthree')
         identical, diff = diff_files(local_path, 'http://foo/bar.json')
     self.assertTrue(identical)
     self.assertIsNone(diff)
     gr_mock.assert_called_with('http://foo/bar.json')
开发者ID:mjs,项目名称:juju,代码行数:10,代码来源:test_publish_streams.py


示例17: test_includes_mirror

 def test_includes_mirror(self):
     with temp_dir() as local_dir:
         foo_path = os.path.join(local_dir, 'foo-mirror')
         expected = [
             SyncFile('bools/foo-mirror', size=3, local_path=foo_path,
                      md5content=md5sum['bar'], mimetype=None),
             ]
         write_file(foo_path, 'bar')
         result = get_local_sync_files('bools', local_dir)
         self.assertEqual(expected, result)
开发者ID:mjs,项目名称:juju,代码行数:10,代码来源:test_azure_publish_tools.py


示例18: test_get_changes

 def test_get_changes(self):
     with temp_dir() as package_dir:
         changes_path = os.path.join(package_dir, 'foo_source.changes')
         with open(changes_path, 'w') as changes_file:
             changes_file.write(CHANGES_DATA)
         with open(os.path.join(package_dir, 'foo.dsc'), 'w') as other_file:
             other_file.write('other_file')
         source_name, version, file_name = get_changes(package_dir)
     self.assertEqual('juju-core', source_name)
     self.assertEqual('1.24.5-0ubuntu1~14.04.1~juju1', version)
     self.assertEqual('foo_source.changes', file_name)
开发者ID:mjs,项目名称:juju,代码行数:11,代码来源:test_upload_packages.py


示例19: test_find_agents

 def test_find_agents(self):
     products = make_products_data(['1.20.7', '1.20.8'])
     with temp_dir() as wd:
         file_path = '{}/json'.format(wd)
         with open(file_path, 'w') as f:
             f.write(json.dumps(products))
         agents = find_agents(file_path)
     expected = [
         '1.20.7-trusty-i386', '1.20.7-trusty-amd64',
         '1.20.8-trusty-amd64', '1.20.8-trusty-i386']
     self.assertEqual(expected, agents.keys())
开发者ID:mjs,项目名称:juju,代码行数:11,代码来源:test_validate_streams.py


示例20: test_delete_tmp_tsv

 def test_delete_tmp_tsv(self):
     dep_file = DependencyFile([])
     self.assertFalse(dep_file.delete_tmp_tsv())
     with temp_dir() as base_dir:
         dep_path = '%s/a.tsv' % base_dir
         with open(dep_path, 'w') as f:
             f.write('foo')
         dep_file.tmp_tsv = dep_path
         self.assertTrue(dep_file.delete_tmp_tsv())
         self.assertFalse(os.path.isfile(dep_path))
     self.assertIsNone(dep_file.tmp_tsv)
开发者ID:mjs,项目名称:juju,代码行数:11,代码来源:test_deptree.py



注:本文中的utils.temp_dir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.text_get函数代码示例发布时间:2022-05-26
下一篇:
Python utils.talosError函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap