8000 SVG backend closes BytesIO on print if were `usetex=True` and `cleanup` decorator used · Issue #6926 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
SVG backend closes BytesIO on print if were usetex=True and cleanup decorator used #6926
Closed
@Kojoley

Description

@Kojoley
import matplotlib
matplotlib.use('svg')

from matplotlib.testing.decorators import cleanup


def make_svg(filename, usetex):
    from matplotlib import rc
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_svg import FigureCanvasSVG
    rc('text', usetex=usetex)

    fig = Figure()
    ax = fig.add_subplot(111)

    FigureCanvasSVG(fig).print_svg(filename)


@cleanup
def make_svg_with_cleanup(filename, usetex):
    make_svg(filename, usetex)


def do_test(cleanup, usetex):
    import io
    stream = io.BytesIO()
    if cleanup:
        make_svg_with_cleanup(stream, usetex)
    else:
        make_svg(stream, usetex)
    assert not stream.closed
    return stream.getvalue()


do_test(cleanup=False, usetex=True)
do_test(cleanup=True, usetex=True)
do_test(cleanup=False, usetex=False)
do_test(cleanup=True, usetex=False)

Bunch of seek(0) calls on BytesIO objects in different tests can be related to this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0