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)
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)
def test_finalize_error_on_footer(self, mock_logger): path = os.path.join(self.metadata_file_dir, 'test.xml') context = MetadataFileContext(path) context._write_file_footer = Mock(side_effect=Exception('foo')) context._open_metadata_file_handle() context._write_file_header() context.finalize() self.assertTrue(mock_logger.called)
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)
def test_finalize_error_on_footer(self, mock_logger): path = os.path.join(self.metadata_file_dir, 'test.xml') context = MetadataFileContext(path) context._write_file_footer = Mock(side_effect=Exception('foo')) context._open_metadata_file_handle() context._write_file_header() context.finalize() self.assertTrue(mock_logger.called)
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)
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)
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)