本文整理汇总了Python中pulp_rpm.plugins.distributors.yum.metadata.metadata.MetadataFileContext类的典型用法代码示例。如果您正苦于以下问题:Python MetadataFileContext类的具体用法?Python MetadataFileContext怎么用?Python MetadataFileContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetadataFileContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()
示例2: 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(DATA_DIR, '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()
示例3: 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()
try:
context._open_metadata_file_handle()
except Exception, e:
self.fail(e.message)
示例4: 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._open_metadata_file_handle()
context._write_xml_header()
context._close_metadata_file_handle()
context.finalize()
self.assertEqual(context.metadata_file_path, path)
示例5: test_finalize_for_repomd_file_with_valid_checksum_type
def test_finalize_for_repomd_file_with_valid_checksum_type(self):
path = os.path.join(self.metadata_file_dir, 'repomd.xml')
checksum_type = 'sha1'
context = MetadataFileContext(path, checksum_type)
context._open_metadata_file_handle()
context._write_xml_header()
context._close_metadata_file_handle()
context.finalize()
self.assertEqual(context.metadata_file_path, path)
示例6: test_is_closed_gzip_file
def test_is_closed_gzip_file(self):
path = os.path.join(DATA_DIR, 'foo.tar.gz')
file_object = gzip.open(path)
file_object.close()
self.assertTrue(MetadataFileContext._is_closed(file_object))
示例7: test_is_closed_file
def test_is_closed_file(self):
path = os.path.join(DATA_DIR, '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))
示例8: 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_xml_header()
context._close_metadata_file_handle()
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.assertEqual(expected_metadata_file_path, context.metadata_file_path)
示例9: test_write_xml_header
def test_write_xml_header(self):
path = os.path.join(self.metadata_file_dir, 'header.xml')
context = MetadataFileContext(path)
context._open_metadata_file_handle()
context._write_xml_header()
context._close_metadata_file_handle()
self.assertTrue(os.path.exists(path))
with open(path) as h:
content = h.read()
expected_content = '<?xml version="1.0" encoding="UTF-8"?>\n'
self.assertEqual(content, expected_content)
示例10: 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_xml_header()
context._close_metadata_file_handle()
try:
h = gzip.open(path)
except Exception, e:
self.fail(e.message)