def test_write_file_header_fast_forward_small_buffer_gzip(self): shutil.copy(os.path.join(self.metadata_dir, 'test.xml.gz'), os.path.join(self.working_dir, 'test.xml.gz')) test_file = os.path.join(self.working_dir, 'test.xml.gz') test_content = '' test_file_handle = gzip.open(test_file) content = test_file_handle.read() while content: test_content += content content = test_file_handle.read() test_file_handle.close() test_content = test_content[:test_content.rfind('</metadata')] context = FastForwardXmlFileContext(test_file, self.tag, 'package', self.attributes) context._open_metadata_file_handle() # Ensure the context doesn't find the opening tag during the initial search context._write_file_header() context.metadata_file_handle.close() created_content = '' test_file_handle = gzip.open(test_file) content = test_file_handle.read() while content: created_content += content content = test_file_handle.read() test_file_handle.close() self.assertEquals(test_content, created_content)
def test_write_file_header_fast_forward_small_buffer_gzip(self): test_file = os.path.join(self.working_dir, 'test.xml.gz') test_content = '' test_file_handle = gzip.open(test_file) content = test_file_handle.read() while content: test_content += content content = test_file_handle.read() test_file_handle.close() test_content = test_content[:test_content.rfind('</metadata')] context = FastForwardXmlFileContext(test_file, self.tag, 'package', self.attributes) context._open_metadata_file_handle() # Ensure the context doesn't find the opening tag during the initial search context._write_file_header() context.metadata_file_handle.close() created_content = '' test_file_handle = gzip.open(test_file) content = test_file_handle.read() while content: created_content += content content = test_file_handle.read() test_file_handle.close() self.assertEquals(test_content, created_content)
def test_write_file_header_no_fast_forward(self, mock_generator): context = FastForwardXmlFileContext(os.path.join(self.working_dir, 'aa.xml'), self.tag, self.attributes) context._open_metadata_file_handle() context._write_file_header() mock_generator.return_value.startDocument.assert_called_once_with()
def _test_fast_forward(self, test_file, test_content=None): """ :param test_file: The name of the file in the data/metadata/* directory to use for testing :type test_file: str :param test_content: The string to compare against. If not specified the content of test_file is used :type test_content: str """ test_file = os.path.join(self.working_dir, test_file) if test_content is None: test_content = '' with open(test_file) as test_file_handle: content = test_file_handle.read() while content: test_content += content content = test_file_handle.read() test_content = test_content[:test_content.rfind('</metadata')] context = FastForwardXmlFileContext(test_file, self.tag, 'package', self.attributes) context._open_metadata_file_handle() # Ensure the context doesn't find the opening tag during the initial search context._write_file_header() context.metadata_file_handle.close() created_content = '' with open(test_file) as test_file_handle: content = test_file_handle.read() while content: created_content += content content = test_file_handle.read() self.assertEquals(test_content, created_content)