當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。