當前位置: 首頁>>代碼示例>>Python>>正文


Python metadata_writer.MetadataFileContext類代碼示例

本文整理匯總了Python中pulp.plugins.util.metadata_writer.MetadataFileContext的典型用法代碼示例。如果您正苦於以下問題:Python MetadataFileContext類的具體用法?Python MetadataFileContext怎麽用?Python MetadataFileContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了MetadataFileContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_open_handle_file_exists

    def test_open_handle_file_exists(self):

        path = os.path.join(self.metadata_file_dir, 'overwriteme.xml')
        context = MetadataFileContext(path)

        with open(path, 'w') as h:
            h.flush()

        context._open_metadata_file_handle()
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:9,代碼來源:test_metadata_writer.py

示例2: test_exit_error

 def test_exit_error(self, mock_log):
     path = os.path.join(self.metadata_file_dir, 'test.xml')
     context = MetadataFileContext(path)
     try:
         raise Exception()
     except Exception:
         ex_type, ex, tb = sys.exc_info()
         context.__exit__(ex_type, ex, tb)
     self.assertEquals(1, mock_log.debug.call_count)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:9,代碼來源:test_metadata_writer.py

示例3: test_open_handle

    def test_open_handle(self):

        path = os.path.join(self.metadata_file_dir, 'open_handle.xml')
        context = MetadataFileContext(path)

        context._open_metadata_file_handle()

        self.assertTrue(os.path.exists(path))

        context._close_metadata_file_handle()
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:10,代碼來源:test_metadata_writer.py

示例4: test_finalize_closed_gzip_file

    def test_finalize_closed_gzip_file(self):
        # this test makes sure that we can properly detect the closed state of
        # a gzip file, because on python 2.6 we have to take special measures
        # to do so.
        path = os.path.join(os.path.dirname(__file__), '../../../data/foo.tar.gz')

        context = MetadataFileContext('/a/b/c')
        context.metadata_file_handle = gzip.open(path)
        context.metadata_file_handle.close()

        # just make sure this doesn't complain.
        context.finalize()
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:12,代碼來源:test_metadata_writer.py

示例5: test_initialize_double_call

 def test_initialize_double_call(self):
     path = os.path.join(self.metadata_file_dir, 'test.xml')
     context = MetadataFileContext(path)
     context.initialize()
     context._write_file_header = Mock()
     context.initialize()
     self.assertEquals(0, context._write_file_header.call_count)
     context.finalize()
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:8,代碼來源:test_metadata_writer.py

示例6: test_is_closed_gzip_file

    def test_is_closed_gzip_file(self):
        path = os.path.join(os.path.dirname(__file__), '../../../data/foo.tar.gz')

        file_object = gzip.open(path)
        file_object.close()

        self.assertTrue(MetadataFileContext._is_closed(file_object))
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:7,代碼來源:test_metadata_writer.py

示例7: test_initialize

    def test_initialize(self):

        path = os.path.join(self.metadata_file_dir, 'foo', 'header.xml')
        context = MetadataFileContext(path)

        context._write_file_header = Mock()

        context.initialize()

        context._write_file_header.assert_called_once_with()
        self.assertTrue(os.path.exists(path))

        with open(path) as h:
            content = h.read()
        expected_content = ''
        self.assertEqual(content, expected_content)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:16,代碼來源:test_metadata_writer.py

示例8: test_finalize_double_call

    def test_finalize_double_call(self):
        path = os.path.join(self.metadata_file_dir, 'test.xml')
        context = MetadataFileContext(path)

        context.initialize()
        context.finalize()
        context._write_file_footer = Mock(side_effect=Exception())
        context.finalize()
        self.assertEquals(context._write_file_footer.call_count, 0)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:9,代碼來源:test_metadata_writer.py

示例9: test_is_closed_file

    def test_is_closed_file(self):
        path = os.path.join(os.path.dirname(__file__), '../../../data/foo.tar.gz')

        # opening as a regular file, not with gzip
        file_object = open(path)
        file_object.close()

        self.assertTrue(MetadataFileContext._is_closed(file_object))
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:8,代碼來源:test_metadata_writer.py

示例10: test_finalize_error_on_close

    def test_finalize_error_on_close(self, mock_logger):

        path = os.path.join(self.metadata_file_dir, 'test.xml')
        context = MetadataFileContext(path)
        context._close_metadata_file_handle = Mock(side_effect=Exception('foo'))

        context._open_metadata_file_handle()
        context._write_file_header()

        context.finalize()

        self.assertTrue(mock_logger.called)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:12,代碼來源:test_metadata_writer.py

示例11: test_finalize_with_valid_checksum_type

    def test_finalize_with_valid_checksum_type(self):

        path = os.path.join(self.metadata_file_dir, 'test.xml')
        checksum_type = 'sha1'
        context = MetadataFileContext(path, checksum_type)

        context._open_metadata_file_handle()
        context._write_file_header()
        context.finalize()

        expected_metadata_file_name = context.checksum + '-' + 'test.xml'
        expected_metadata_file_path = os.path.join(self.metadata_file_dir,
                                                   expected_metadata_file_name)
        self.assertEquals(expected_metadata_file_path, context.metadata_file_path)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:14,代碼來源:test_metadata_writer.py

示例12: test_finalize_checksum_type_none

    def test_finalize_checksum_type_none(self):

        path = os.path.join(self.metadata_file_dir, 'test.xml')
        context = MetadataFileContext(path)

        context.initialize()
        context._write_file_footer = Mock()
        context.finalize()
        context._write_file_footer.assert_called_once_with()

        self.assertEqual(context.metadata_file_path, path)
        self.assertEqual(context.metadata_file_handle, None)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:12,代碼來源:test_metadata_writer.py

示例13: test_open_handle_gzip

    def test_open_handle_gzip(self):

        path = os.path.join(self.metadata_file_dir, 'test.xml.gz')
        context = MetadataFileContext(path)

        context._open_metadata_file_handle()

        self.assertTrue(os.path.exists(path))

        context._write_file_header()
        context._close_metadata_file_handle()

        try:
            h = gzip.open(path)

        except Exception, e:
            self.fail(e.message)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:17,代碼來源:test_metadata_writer.py

示例14: test_finalize_error_on_write_footer

    def test_finalize_error_on_write_footer(self):
        # Ensure that if the write_file_footer throws an exception we eat it so that
        # if multiple metadata files are being finalized, one error won't cause open
        # file handles on the others

        path = os.path.join(self.metadata_file_dir, 'test.xml')
        context = MetadataFileContext(path)

        context.initialize()
        context._write_file_footer = Mock(side_effect=Exception())
        context.finalize()
        context._write_file_footer.assert_called_once_with()

        self.assertEqual(context.metadata_file_path, path)
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:14,代碼來源:test_metadata_writer.py

示例15: test_enter

 def test_enter(self):
     path = os.path.join(self.metadata_file_dir, 'test.xml')
     context = MetadataFileContext(path)
     context.initialize = Mock()
     context.__enter__()
     context.initialize.assert_called_once_with()
開發者ID:CUXIDUMDUM,項目名稱:pulp,代碼行數:6,代碼來源:test_metadata_writer.py


注:本文中的pulp.plugins.util.metadata_writer.MetadataFileContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。