本文整理汇总了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;未经允许,请勿转载。 |
请发表评论