当前位置: 首页>>代码示例>>Python>>正文


Python utility.temp_dir函数代码示例

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


在下文中一共展示了temp_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_download_files__suffix

 def test_download_files__suffix(self):
     keys = [KeyStub("test.txt", "foo"), KeyStub("test2.tar", "foo2")]
     with temp_dir() as dst:
         downloaded_files = download_files(keys, dst, suffix=".tar")
         self.assertItemsEqual(os.listdir(dst), ['test2.tar'])
         self.assertEqual("foo2", get_file_content('test2.tar', dst))
     self.assertItemsEqual(downloaded_files, ['test2.tar'])
开发者ID:mjs,项目名称:juju,代码行数:7,代码来源:test_download_juju.py

示例2: test_download

 def test_download(self):
     content = "hello"
     key = KeyStub("test", "hello")
     with temp_dir() as d:
         dst = os.path.join(d, "test.txt")
         _download(key, dst)
         self.assertEqual(content, get_file_content(dst))
开发者ID:mjs,项目名称:juju,代码行数:7,代码来源:test_download_juju.py

示例3: test_go_test_package

 def test_go_test_package(self):
     with temp_dir() as gopath:
         package_path = os.path.join(
             gopath, 'src', 'github.com', 'juju', 'juju')
         os.makedirs(package_path)
         with patch('gotesttarfile.run', return_value=0,
                    autospec=True) as run_mock:
             devnull = open(os.devnull, 'w')
             with patch('sys.stdout', devnull):
                 returncode = go_test_package(
                     'github.com/juju/juju', 'go', gopath)
     self.assertEqual(0, returncode)
     self.assertEqual(run_mock.call_count, 5)
     args, kwargs = run_mock.call_args_list[0]
     self.assertEqual((['go', 'version'],), args)
     args, kwargs = run_mock.call_args_list[1]
     self.assertEqual((['go', 'env'],), args)
     args, kwargs = run_mock.call_args_list[2]
     self.assertEqual((['go', 'test', '-i', './...'],), args)
     args, kwargs = run_mock.call_args_list[3]
     self.assertEqual(
         (['go', 'test', '-timeout=1200s', './...'],), args)
     self.assertEqual('amd64', kwargs['env'].get('GOARCH'))
     self.assertEqual(gopath, kwargs['env'].get('GOPATH'))
     run_mock.assert_called_with(['sudo', 'killall', '-SIGABRT', 'mongod'])
开发者ID:mjs,项目名称:juju,代码行数:25,代码来源:test_gotesttarfile.py

示例4: iter_steps

 def iter_steps(self, client):
     yield self.prepare.as_result()
     with temp_dir() as temp_repository:
         charm = Charm('mycharm', 'Test charm', series=['trusty'])
         charm.metadata['description'] = 'Charm for industrial testing.'
         charm_root = charm.to_repo_dir(temp_repository)
         charm_path = local_charm_path(
             charm='mycharm', juju_ver=client.version, series='trusty',
             repository=os.path.dirname(charm_root))
         client.deploy(charm_path, temp_repository)
         yield self.prepare.as_result()
         client.wait_for_started()
         yield self.prepare.as_result()
         charm.add_hook_script('config-changed', dedent("""\
             #!/bin/sh
             open-port 34
             """))
         charm.add_hook_script('upgrade-charm', dedent("""\
             #!/bin/sh
             open-port 42
             """))
         shutil.rmtree(charm_root)
         charm.to_repo_dir(temp_repository)
         yield self.prepare.as_result(True)
         yield self.upgrade.as_result()
         client.upgrade_charm('mycharm', charm_root)
         yield self.upgrade.as_result()
         for status in client.status_until(300):
             ports = status.get_open_ports('mycharm/0')
             if '42/tcp' in ports and '34/tcp' in ports:
                 break
         else:
             raise Exception('42 and/or 34 not opened.')
         yield self.upgrade.as_result(True)
开发者ID:mjs,项目名称:juju,代码行数:34,代码来源:industrial_test.py

示例5: test_main

 def test_main(self):
     with temp_dir() as tempdir:
         buildvars_path = os.path.join(tempdir, 'buildvars')
         with open(buildvars_path, 'w') as buildvars_file:
             json.dump({'foo': 'bar'}, buildvars_file)
         output_path = os.path.join(tempdir, 'output')
         envs = {'environments': {'foo': {'type': 'ec2'}}}
         with _temp_env(envs):
             with patch('subprocess.check_output', return_value='1.20'):
                 main([buildvars_path, 'foo', output_path])
         with open(output_path) as output_file:
             output = output_file.read()
         expected = dedent("""\
             {
               "environment": {
                 "name": "foo",\x20
                 "substrate": "AWS"
               },\x20
               "new_client": {
                 "buildvars": {
                   "foo": "bar"
                 },\x20
                 "type": "build"
               },\x20
               "old_client": {
                 "type": "release",\x20
                 "version": "1.20"
               }
             }
             """)
         self.assertEqual(output, expected)
开发者ID:mjs,项目名称:juju,代码行数:31,代码来源:test_write_industrial_test_metadata.py

示例6: test_encoded_copy_to_dir_many

 def test_encoded_copy_to_dir_many(self):
     output = "test one|K0ktLuECAA==\r\ntest two|K0ktLuECAA==\r\n\r\n"
     with temp_dir() as dest:
         WinRmRemote._encoded_copy_to_dir(dest, output)
         for name in ("test one", "test two"):
             with open(os.path.join(dest, name)) as f:
                 self.assertEqual(f.read(), "test\n")
开发者ID:mjs,项目名称:juju,代码行数:7,代码来源:test_remote.py

示例7: test_main

 def test_main(self):
     with temp_dir() as log_dir:
         argv = ["an-env", "/bin/juju", log_dir, "an-env-mod",
                 "both-proxied", "--verbose"]
         client = Mock(spec=["is_jes_enabled"])
         with patch("assess_proxy.configure_logging",
                    autospec=True) as mock_cl:
             with patch("assess_proxy.BootstrapManager.booted_context",
                        autospec=True) as mock_bc:
                 with patch('deploy_stack.client_from_config',
                            return_value=client) as mock_cfc:
                     with patch("assess_proxy.assess_proxy",
                                autospec=True) as mock_assess:
                         with patch("assess_proxy.check_network",
                                    autospec=True,
                                    return_value='FORWARD') as mock_check:
                             with patch("assess_proxy.set_firewall",
                                        autospec=True) as mock_set:
                                 with patch("assess_proxy.reset_firewall",
                                            autospec=True) as mock_reset:
                                     returecode = assess_proxy.main(argv)
     self.assertEqual(0, returecode)
     mock_cl.assert_called_once_with(logging.DEBUG)
     mock_cfc.assert_called_once_with(
         'an-env', "/bin/juju", debug=False, soft_deadline=None)
     mock_check.assert_called_once_with('eth0', 'lxdbr0')
     mock_set.assert_called_once_with(
         'both-proxied', 'eth0', 'lxdbr0', 'FORWARD')
     mock_reset.assert_called_once_with()
     self.assertEqual(mock_bc.call_count, 1)
     mock_assess.assert_called_once_with(client, 'both-proxied')
开发者ID:mjs,项目名称:juju,代码行数:31,代码来源:test_assess_proxy.py

示例8: test_write_openstack_config_file_writes_credentials_file

    def test_write_openstack_config_file_writes_credentials_file(self):
        """Ensure the file created contains the correct details."""
        credential_details = dict(
            os_tenant_name='tenant_name',
            os_password='password',
            os_auth_url='url',
            os_region_name='region')
        user = 'username'

        with temp_dir() as tmp_dir:
            credentials_file = aac.write_openstack_config_file(
                tmp_dir, user, credential_details)
            with open(credentials_file, 'r') as f:
                credential_contents = f.read()

        expected = dedent("""\
        export OS_USERNAME={user}
        export OS_PASSWORD={password}
        export OS_TENANT_NAME={tenant_name}
        export OS_AUTH_URL={auth_url}
        export OS_REGION_NAME={region}
        """.format(
            user=user,
            password=credential_details['os_password'],
            tenant_name=credential_details['os_tenant_name'],
            auth_url=credential_details['os_auth_url'],
            region=credential_details['os_region_name'],
            ))

        self.assertEqual(credential_contents, expected)
开发者ID:mjs,项目名称:juju,代码行数:30,代码来源:test_assess_autoload_credentials.py

示例9: assess_deploy_storage

def assess_deploy_storage(client, charm_series,
                          charm_name, provider_type, pool=None):
    """Set up the test for deploying charm with storage."""
    if provider_type == "block":
        storage = {
            "disks": {
                "type": provider_type,
                "multiple": {
                    "range": "0-10"
                }
            }
        }
    else:
        storage = {
            "data": {
                "type": provider_type,
                "location": "/srv/data"
            }
        }
    with temp_dir() as charm_dir:
        charm_root = create_storage_charm(charm_dir, charm_name,
                                          'Test charm for storage', storage)
        platform = 'ubuntu'
        charm = local_charm_path(charm=charm_name, juju_ver=client.version,
                                 series=charm_series,
                                 repository=os.path.dirname(charm_root),
                                 platform=platform)
        deploy_storage(client, charm, charm_series, pool, "1G", charm_dir)
开发者ID:mjs,项目名称:juju,代码行数:28,代码来源:assess_storage.py

示例10: test_filter_command_include_command

 def test_filter_command_include_command(self):
     include_command = 'deny-all'
     with temp_dir() as directory:
         runner = Runner(directory, ChaosMonkey.factory())
         runner.filter_commands(include_command=include_command)
     self.assertEqual(len(runner.chaos_monkey.chaos), 1)
     self.assertEqual(runner.chaos_monkey.chaos[0].command_str, 'deny-all')
开发者ID:FoldingSkyCorporation,项目名称:chaos-monkey,代码行数:7,代码来源:test_runner.py

示例11: setup_extract_candidates

 def setup_extract_candidates(self, dry_run=False, verbose=False):
     version = '1.2.3'
     with temp_dir() as base_dir:
         artifacts_dir_path = os.path.join(base_dir, 'master-artifacts')
         os.makedirs(artifacts_dir_path)
         buildvars_path = os.path.join(artifacts_dir_path, 'buildvars.json')
         with open(buildvars_path, 'w') as bv:
             json.dump(dict(version=version), bv)
         os.utime(buildvars_path, (1426186437, 1426186437))
         master_dir_path = os.path.join(base_dir, version)
         os.makedirs(master_dir_path)
         package_path = os.path.join(master_dir_path, 'foo.deb')
         with patch('candidate.prepare_dir') as pd_mock:
             with patch('candidate.get_package',
                        return_value=package_path) as gp_mock:
                 with patch('subprocess.check_call') as cc_mock:
                     extract_candidates(
                         base_dir, dry_run=dry_run, verbose=verbose)
         copied_path = os.path.join(master_dir_path, 'buildvars.json')
         if not dry_run:
             self.assertTrue(os.path.isfile(copied_path))
             self.assertEqual(os.stat(copied_path).st_mtime, 1426186437)
         else:
             self.assertFalse(os.path.isfile(copied_path))
         return (pd_mock, gp_mock, cc_mock,
                 artifacts_dir_path, buildvars_path, master_dir_path,
                 package_path)
开发者ID:mjs,项目名称:juju,代码行数:27,代码来源:test_candidate.py

示例12: test_acquire_lock_fails_without_workspace

 def test_acquire_lock_fails_without_workspace(self):
     with temp_dir() as directory:
         runner = Runner(directory, None)
     # Call runner.acquire_lock at this level, at which point directory
     # will have already been cleaned up.
     with self.assertRaises(SystemExit):
         runner.acquire_lock()
开发者ID:FoldingSkyCorporation,项目名称:chaos-monkey,代码行数:7,代码来源:test_runner.py

示例13: test_filter_commands_exclude_incorrect_group

 def test_filter_commands_exclude_incorrect_group(self):
     exclude_group = 'net,killl'
     with temp_dir() as directory:
         runner = Runner(directory, ChaosMonkey.factory())
         with self.assertRaisesRegexp(
                 BadRequest, "Invalid value given on command line: killl"):
             runner.filter_commands(exclude_group=exclude_group)
开发者ID:FoldingSkyCorporation,项目名称:chaos-monkey,代码行数:7,代码来源:test_runner.py

示例14: test_acquire_lock_fails_when_existing_lockfile

 def test_acquire_lock_fails_when_existing_lockfile(self):
     with temp_dir() as directory:
         expected_file = os.path.join(directory, 'chaos_runner.lock')
         open(expected_file, 'a').close()
         runner = Runner(directory, None)
         with self.assertRaises(SystemExit):
             runner.acquire_lock()
开发者ID:FoldingSkyCorporation,项目名称:chaos-monkey,代码行数:7,代码来源:test_runner.py

示例15: test_calls_provided_test

    def test_calls_provided_test(self):
        client = fake_juju_client()
        with temp_dir() as juju_home:
            client.env.juju_home = juju_home
            bs_manager = make_bootstrap_manager(client)
            bs_manager.log_dir = os.path.join(juju_home, 'log-dir')
            os.mkdir(bs_manager.log_dir)

            timing = gpr.TimingData(datetime.utcnow(), datetime.utcnow())
            deploy_details = gpr.DeployDetails('test', dict(), timing)
            noop_test = Mock(return_value=deploy_details)

            pprof_collector = Mock()

            with patch.object(gpr, 'dump_performance_metrics_logs',
                              autospec=True):
                with patch.object(gpr, 'generate_reports', autospec=True):
                    with patch.object(
                            gpr, 'PPROFCollector', autospec=True) as p_pc:
                        p_pc.return_value = pprof_collector
                        gpr.run_perfscale_test(
                            noop_test,
                            bs_manager,
                            get_default_args())

            noop_test.assert_called_once_with(
                client, pprof_collector, get_default_args())
开发者ID:mjs,项目名称:juju,代码行数:27,代码来源:test_generate_perfscale_results.py


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