本文整理汇总了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()
示例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)
示例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()
示例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()
示例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()
示例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))
示例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)
示例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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()