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


Python tempfile.TemporaryDirectory方法代码示例

本文整理汇总了Python中backports.tempfile.TemporaryDirectory方法的典型用法代码示例。如果您正苦于以下问题:Python tempfile.TemporaryDirectory方法的具体用法?Python tempfile.TemporaryDirectory怎么用?Python tempfile.TemporaryDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backports.tempfile的用法示例。


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

示例1: test_state_is_ready___run_is_started

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_state_is_ready___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, input_file=fake_related_file(), settings_file=fake_related_file())
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.run_analysis_signature', PropertyMock(return_value=sig_res)):
                    analysis.run(initiator)

                    sig_res.link.assert_called_once_with(record_run_analysis_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_run_analysis_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例2: test_state_is_not_running___run_is_started

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_state_is_not_running___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis.generate_inputs(initiator)

                    sig_res.link.assert_called_once_with(record_generate_input_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_generate_input_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例3: test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'status': [
                        'Analysis status must be one of [NEW, INPUTS_GENERATION_ERROR, INPUTS_GENERATION_CANCELLED, READY, RUN_COMPLETED, RUN_CANCELLED, RUN_ERROR]'
                    ]}, ex.exception.detail)
                    self.assertEqual(status, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例4: test_settings_file_is_not_a_valid_format___response_is_400

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_settings_file_is_not_a_valid_format___response_is_400(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                analysis = fake_analysis()

                response = self.app.post(
                    analysis.get_absolute_settings_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.tar', b'content'),
                    ),
                    expect_errors=True,
                )

                self.assertEqual(400, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_api.py

示例5: test_settings_file_is_uploaded___file_can_be_retrieved

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_settings_file_is_uploaded___file_can_be_retrieved(self, file_content):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                analysis = fake_analysis()

                self.app.post(
                    analysis.get_absolute_settings_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.json', file_content),
                    ),
                )

                response = self.app.get(
                    analysis.get_absolute_settings_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                )

                self.assertEqual(response.body, file_content)
                self.assertEqual(response.content_type, 'application/json') 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:test_analysis_api.py

示例6: test_output_file_is_not_valid_format___post_response_is_405

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_output_file_is_not_valid_format___post_response_is_405(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                analysis = fake_analysis()

                response = self.app.post(
                    analysis.get_absolute_output_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.csv', b'content'),
                    ),
                    expect_errors=True,
                )

                self.assertEqual(405, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_api.py

示例7: test_accounts_file_is_not_a_valid_format___response_is_400

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_accounts_file_is_not_a_valid_format___response_is_400(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                response = self.app.post(
                    portfolio.get_absolute_accounts_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.tar', b'content'),
                    ),
                    expect_errors=True,
                )

                self.assertEqual(400, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_portfolio.py

示例8: test_accounts_file_is_uploaded___file_can_be_retrieved

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_accounts_file_is_uploaded___file_can_be_retrieved(self, file_content, content_type):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                self.app.post(
                    portfolio.get_absolute_accounts_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file{}'.format(mimetypes.guess_extension(content_type)), file_content),
                    ),
                )

                response = self.app.get(
                    portfolio.get_absolute_accounts_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                )

                self.assertEqual(response.body, file_content)
                self.assertEqual(response.content_type, content_type) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:test_portfolio.py

示例9: test_location_file_is_uploaded___file_can_be_retrieved

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_location_file_is_uploaded___file_can_be_retrieved(self, file_content, content_type):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                self.app.post(
                    portfolio.get_absolute_location_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file{}'.format(mimetypes.guess_extension(content_type)), file_content),
                    ),
                )

                response = self.app.get(
                    portfolio.get_absolute_location_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                )

                self.assertEqual(response.body, file_content)
                self.assertEqual(response.content_type, content_type) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:test_portfolio.py

示例10: test_reinsurance_scope_file_is_not_a_valid_format___response_is_400

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_reinsurance_scope_file_is_not_a_valid_format___response_is_400(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                response = self.app.post(
                    portfolio.get_absolute_reinsurance_scope_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.tar', b'content'),
                    ),
                    expect_errors=True,
                )

                self.assertEqual(400, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_portfolio.py

示例11: test_reinsurance_scope_file_is_uploaded___file_can_be_retrieved

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_reinsurance_scope_file_is_uploaded___file_can_be_retrieved(self, file_content, content_type):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                self.app.post(
                    portfolio.get_absolute_reinsurance_scope_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file{}'.format(mimetypes.guess_extension(content_type)), file_content),
                    ),
                )

                response = self.app.get(
                    portfolio.get_absolute_reinsurance_scope_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                )

                self.assertEqual(response.body, file_content)
                self.assertEqual(response.content_type, content_type) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:test_portfolio.py

示例12: test_reinsurance_info_file_is_not_a_valid_format___response_is_400

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_reinsurance_info_file_is_not_a_valid_format___response_is_400(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                response = self.app.post(
                    portfolio.get_absolute_reinsurance_info_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.tar', b'content'),
                    ),
                    expect_errors=True,
                )

                self.assertEqual(400, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_portfolio.py

示例13: test_reinsurance_info_file_is_uploaded___file_can_be_retrieved

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_reinsurance_info_file_is_uploaded___file_can_be_retrieved(self, file_content, content_type):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                portfolio = fake_portfolio()

                self.app.post(
                    portfolio.get_absolute_reinsurance_info_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file{}'.format(mimetypes.guess_extension(content_type)), file_content),
                    ),
                )

                response = self.app.get(
                    portfolio.get_absolute_reinsurance_info_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                )

                self.assertEqual(response.body, file_content)
                self.assertEqual(response.content_type, content_type) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:test_portfolio.py

示例14: testEndToEnd

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def testEndToEnd(self):
    with tempfile.TemporaryDirectory() as tmpdir:
      with engine.get_included_labels_file() as centroids:
        export_dir = os.path.join(tmpdir, 'export')
        export_kmeans_centroids.run(centroids.name, export_dir)

      # Now load the saved model.
      omr = engine.OMREngine(
          glyph_classifier_fn=saved_classifier.SavedConvolutional1DClassifier
          .glyph_classifier_fn(export_dir))
      filename = os.path.join(tf.resource_loader.get_data_files_path(),
                              '../testdata/IMSLP00747-000.png')
      notes = omr.run(filename, output_notesequence=True)
      # TODO(ringw): Fix the extra note that is detected before the actual
      # first eighth note.
      self.assertEqual(librosa.note_to_midi('C4'), notes.notes[1].pitch)
      self.assertEqual(librosa.note_to_midi('D4'), notes.notes[2].pitch)
      self.assertEqual(librosa.note_to_midi('E4'), notes.notes[3].pitch) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:20,代码来源:export_kmeans_centroids_test.py

示例15: test_db_file_corrupted

# 需要导入模块: from backports import tempfile [as 别名]
# 或者: from backports.tempfile import TemporaryDirectory [as 别名]
def test_db_file_corrupted():

    with tempfile.TemporaryDirectory() as cachedir:
        unc = 'sqlite:///' + cachedir + '/test.db'

        with mock.patch('ansibullbot.utils.sqlite_utils.C.DEFAULT_DATABASE_UNC', unc):

            # create the initial file
            ADB1 = AnsibullbotDatabase(cachedir=cachedir)
            unc_file = ADB1.unc
            unc_file = unc_file.replace('sqlite:///', '')
            with open(unc_file, 'w') as f:
                f.write('NULLNULLNULLNULL')

            # now try to init again
            ADB2 = AnsibullbotDatabase(cachedir=cachedir)

            assert os.path.exists(ADB2.dbfile) 
开发者ID:ansible,项目名称:ansibullbot,代码行数:20,代码来源:test_sqlite_tools.py


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