Пример #1
0
def test_latex_to_png_mpl_runs(s_wrap, context):
    """
    Test that latex_to_png_mpl just runs without error.
    """
    try:
        import matplotlib
    except ImportError:
        pytest.skip("This needs matplotlib to be available")
        return
    s, wrap = s_wrap
    with context():
        latextools.latex_to_png_mpl(s, wrap)
Пример #2
0
def test_latex_to_png_color():
    """
    Test color settings for latex_to_png.
    """
    latex_string = "$x^2$"
    default_value = latextools.latex_to_png(latex_string, wrap=False)
    default_hexblack = latextools.latex_to_png(latex_string, wrap=False,
                                               color='#000000')
    dvipng_default = latextools.latex_to_png_dvipng(latex_string, False)
    dvipng_black = latextools.latex_to_png_dvipng(latex_string, False, 'Black')
    assert dvipng_default == dvipng_black
    mpl_default = latextools.latex_to_png_mpl(latex_string, False)
    mpl_black = latextools.latex_to_png_mpl(latex_string, False, 'Black')
    assert mpl_default == mpl_black
    assert default_value in [dvipng_black, mpl_black]
    assert default_hexblack in [dvipng_black, mpl_black]

    # Test that dvips name colors can be used without error
    dvipng_maroon = latextools.latex_to_png_dvipng(latex_string, False,
                                                   'Maroon')
    # And that it doesn't return the black one
    assert dvipng_black != dvipng_maroon

    mpl_maroon = latextools.latex_to_png_mpl(latex_string, False, 'Maroon')
    assert mpl_black != mpl_maroon
    mpl_white = latextools.latex_to_png_mpl(latex_string, False, 'White')
    mpl_hexwhite = latextools.latex_to_png_mpl(latex_string, False, '#FFFFFF')
    assert mpl_white == mpl_hexwhite

    mpl_white_scale = latextools.latex_to_png_mpl(latex_string, False,
                                                  'White', 1.2)
    assert mpl_white != mpl_white_scale
Пример #3
0
def test_latex_to_png_color():
    """
    Test color settings for latex_to_png.
    """
    latex_string = "$x^2$"
    default_value = latextools.latex_to_png(latex_string, wrap=False)
    default_hexblack = latextools.latex_to_png(latex_string,
                                               wrap=False,
                                               color="#000000")
    dvipng_default = latextools.latex_to_png_dvipng(latex_string, False)
    dvipng_black = latextools.latex_to_png_dvipng(latex_string, False, "Black")
    nt.assert_equal(dvipng_default, dvipng_black)
    mpl_default = latextools.latex_to_png_mpl(latex_string, False)
    mpl_black = latextools.latex_to_png_mpl(latex_string, False, "Black")
    nt.assert_equal(mpl_default, mpl_black)
    nt.assert_in(default_value, [dvipng_black, mpl_black])
    nt.assert_in(default_hexblack, [dvipng_black, mpl_black])

    # Test that dvips name colors can be used without error
    dvipng_maroon = latextools.latex_to_png_dvipng(latex_string, False,
                                                   "Maroon")
    # And that it doesn't return the black one
    nt.assert_not_equal(dvipng_black, dvipng_maroon)

    mpl_maroon = latextools.latex_to_png_mpl(latex_string, False, "Maroon")
    nt.assert_not_equal(mpl_black, mpl_maroon)
    mpl_white = latextools.latex_to_png_mpl(latex_string, False, "White")
    mpl_hexwhite = latextools.latex_to_png_mpl(latex_string, False, "#FFFFFF")
    nt.assert_equal(mpl_white, mpl_hexwhite)

    mpl_white_scale = latextools.latex_to_png_mpl(latex_string, False, "White",
                                                  1.2)
    nt.assert_not_equal(mpl_white, mpl_white_scale)