def test_run_latex(): if no_latex(): warnings.warn("No " + latex_tools.LATEX_EXE + ": Tests involving running LaTeX will not be return") return # Make sure the input file exists; if not, create it if not os.path.exists(HELLO_TEX): with open(HELLO_TEX, "w") as f: f.write(HELLO_TEX_CONTENTS) assert os.path.exists(HELLO_TEX) # Make sure that the output file does not exist if os.path.exists(HELLO_PDF): os.unlink(HELLO_PDF) # Run LaTeX. Make sure that delete_tempfiles=False leaves temp files latex_tools.run_latex(HELLO_TEX, delete_tempfiles=False) assert os.path.exists(HELLO_PDF) assert os.path.exists(HELLO_AUX) os.unlink(HELLO_AUX) # Run LaTeX. Make sure that delete_tempfiles=False deletes the temp files latex_tools.run_latex(HELLO_TEX, delete_tempfiles=True) assert os.path.exists(HELLO_PDF) assert not os.path.exists(HELLO_AUX) # Finally, delete HELLO_TEX and HELLO_PDF os.unlink(HELLO_TEX) os.unlink(HELLO_PDF)
def test_count_pdf_pages_pypdf(): if no_latex(): warnings.warn("No " + latex_tools.LATEX_EXE + ": Tests involving running LaTeX will not be return") return try: assert os.path.exists(ONEPAGE_PDF) # we need this file assert latex_tools.count_pdf_pages_pypdf(ONEPAGE_PDF) == 1 assert os.path.exists(FIVEPAGES_PDF) # we need this file assert latex_tools.count_pdf_pages_pypdf(FIVEPAGES_PDF) == 5 except ImportError: logging.warning("PyPDF2 is not available")
def test_count_pdf_pages(): if no_latex(): warnings.warn("No " + latex_tools.LATEX_EXE + ": Tests involving running LaTeX will not be return") return assert os.path.exists(FIVEPAGES_PDF) # we need this file assert not os.path.exists(FIVEPAGES_AUX) # we do not want this assert not os.path.exists(FIVEPAGES_OUT) # we do not want this pages = latex_tools.count_pdf_pages(FIVEPAGES_PDF) assert pages == 5 assert os.path.exists(FIVEPAGES_PDF) # make sure file is still there assert not os.path.exists(FIVEPAGES_AUX) # we do not want this assert not os.path.exists(FIVEPAGES_OUT) # we do not want this
def test_extract_pdf_pages(): if no_latex(): warnings.warn("No " + latex_tools.LATEX_EXE + ": Tests involving running LaTeX will not be return") return if os.path.exists(EXTRACT_PDF): os.unlink(EXTRACT_PDF) assert not os.path.exists(EXTRACT_PDF) assert os.path.exists(FIVEPAGES_PDF) if os.path.exists(EXTRACT_PDF): os.unlink(EXTRACT_PDF) latex_tools.extract_pdf_pages(EXTRACT_PDF, FIVEPAGES_PDF, pagelist=[1]) assert os.path.exists(EXTRACT_PDF) assert os.path.exists(FIVEPAGES_PDF) # Make sure precisely one page was extracted count = latex_tools.count_pdf_pages(EXTRACT_PDF) if count != 1: raise RuntimeError("{} does not have {} pages; it has {}".format( EXTRACT_PDF, 1, count)) # Finally, delete the extracted file os.unlink(EXTRACT_PDF)
def test_inspect_pdf(): if no_latex(): warnings.warn("No " + latex_tools.LATEX_EXE + ": Tests involving running LaTeX will not be return") return assert latex_tools.count_pdf_pages(FIVEPAGES_PDF) == 5