コード例 #1
0
ファイル: tydoc_test.py プロジェクト: simsong/ctools
def test_tydoc_latex(tmpdir):
    """Create a document that tries lots of features and then make a LaTeX document and run LaTeX"""

    doc = tydoc()
    doc.h1("Table demo")

    d2 = doc.table()
    d2.set_option(OPTION_TABLE)
    d2.add_head(['State', 'Abbreviation', 'Population'])
    d2.add_data(['Virginia', 'VA', 8001045])
    d2.add_data(['California', 'CA', 37252895])

    d2 = doc.table()
    d2.set_option(OPTION_LONGTABLE)
    d2.add_head(['State', 'Abbreviation', 'Population'])
    d2.add_data(['Virginia', 'VA', 8001045])
    d2.add_data(['California', 'CA', 37252895])

    doc.save(os.path.join(tmpdir, "tydoc.tex"), format="latex")

    if no_latex():
        warnings.warn("Cannot run LaTeX tests")
        return
    try:
        run_latex(os.path.join(tmpdir, "tydoc.tex"))
    except LatexException as e:
        warnings.warn("LatexException: " + str(e))
コード例 #2
0
def test_run_latex():
    if latex_tools.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
    try:
        latex_tools.run_latex(HELLO_TEX,delete_tempfiles=False)
    except latex_tools.LatexException as e:
        warnings.warn("No "+latex_tools.LATEX_EXE+": Tests involving running LaTeX will not be return")
        return
    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)
コード例 #3
0
def test_extract_pdf_pages():
    if latex_tools.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)
    try:
        latex_tools.extract_pdf_pages(EXTRACT_PDF,FIVEPAGES_PDF,pagelist=[1])
    except latex_tools.LatexException as e:
        warnings.warn("LatexException: "+str(e))
        return

    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)
コード例 #4
0
def test_inspect_pdf():
    if latex_tools.no_latex():
        warnings.warn("No "+latex_tools.LATEX_EXE+": Tests involving running LaTeX will not be return")
        return
    try:
        assert latex_tools.count_pdf_pages(FIVEPAGES_PDF) == 5
    except ModuleNotFoundError as e:
        warnings.warn("Module not found: "+str(e))
    except latex_tools.LatexException as e:
        warnings.warn("LatexException: "+str(e))
コード例 #5
0
def test_count_pdf_pages_pypdf():
    if latex_tools.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,ModuleNotFoundError):
        logging.warning("PyPDF2 is not available")
    except FileNotFoundError:
        logging.warning("no output file created")
コード例 #6
0
def test_count_pdf_pages():
    if latex_tools.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

    try:
        pages = latex_tools.count_pdf_pages(FIVEPAGES_PDF)
    except latex_tools.LatexException as e:
        warnings.warn("LatexException: "+str(e))
        return
                      
    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