def test_pdfimages_output(self): zip_file = "tests/test_data/30-01-2019-RA-eLife-45644.zip" zip_lib.unzip_zip(zip_file, self.temp_dir) # run only if pdfimages is available if pdf_utils.pdfimages_exists(): pdf_file = os.path.join( self.temp_dir, "30-01-2019-RA-eLife-45644/Appendix 1figure 10.pdf" ) result = pdf_utils.pdfimages_output(pdf_file) self.assertIsNotNone(result.stdout)
def test_pdf_page_count_wand_runtime_error(self, mock_image_allocate): mock_image_allocate.side_effect = wand.exceptions.WandRuntimeError() zip_lib.unzip_zip( "tests/test_data/30-01-2019-RA-eLife-45644.zip", self.temp_dir ) pdf_path = "tests/tmp/30-01-2019-RA-eLife-45644/Appendix 1figure 10.pdf" with self.assertRaises(wand.exceptions.WandRuntimeError): self.assertIsNone(parse.pdf_page_count(pdf_path)) expected = ( "ERROR elifecleaner:parse:pdf_page_count: " "WandRuntimeError in pdf_page_count(), imagemagick may not be installed\n" ) log_file_lines = read_log_file_lines(self.log_file) self.assertEqual(log_file_lines[0], expected)
def test_file_list(self): zip_file = "tests/test_data/30-01-2019-RA-eLife-45644.zip" asset_file_name_map = zip_lib.unzip_zip(zip_file, self.temp_dir) xml_asset = parse.article_xml_asset(asset_file_name_map) root = parse.parse_article_xml(xml_asset[1]) expected = read_fixture("file_list_45644.py") files = parse.file_list(root) self.assertEqual(files, expected)
def test_article_xml_name(self): zip_file = "tests/test_data/30-01-2019-RA-eLife-45644.zip" asset_file_name_map = zip_lib.unzip_zip(zip_file, self.temp_dir) expected = ( "30-01-2019-RA-eLife-45644/30-01-2019-RA-eLife-45644.xml", "tests/tmp/30-01-2019-RA-eLife-45644/30-01-2019-RA-eLife-45644.xml", ) xml_asset = parse.article_xml_asset(asset_file_name_map) self.assertEqual(xml_asset, expected)
def check_ejp_zip(zip_file, tmp_dir): "check contents of ejp zip file" asset_file_name_map = zip_lib.unzip_zip(zip_file, tmp_dir) xml_asset = article_xml_asset(asset_file_name_map) root = parse_article_xml(xml_asset[1]) files = file_list(root) # use the zip file name as the identifier for log messages identifer = zip_file.split(os.sep)[-1] return check_files(files, asset_file_name_map, identifer)
def transform_ejp_zip(zip_file, tmp_dir, output_dir): "transform ejp zip file and write a new zip file output" zip_file_name = zip_file.split(os.sep)[-1] # profile the zip contents asset_file_name_map = zip_lib.unzip_zip(zip_file, tmp_dir) # start logging LOGGER.info("%s starting to transform", zip_file_name) new_asset_file_name_map = transform_ejp_files( asset_file_name_map, output_dir, zip_file_name ) # write new zip file new_zip_file_path = rezip(new_asset_file_name_map, output_dir, zip_file_name) return new_zip_file_path
def test_unzip_zip(self): zip_file = "tests/test_data/30-01-2019-RA-eLife-45644.zip" asset_file_name_map = zip_lib.unzip_zip(zip_file, self.temp_dir) expected = read_fixture("asset_file_name_map_45644.py") self.assertEqual(asset_file_name_map, expected)