MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_savefig_to_stringio

Function test_savefig_to_stringio

lib/matplotlib/tests/test_backend_ps.py:44–115  ·  view source on GitHub ↗
(format, use_log, rcParams, orientation, papersize)

Source from the content-addressed store, hash-verified

42 'eps with usetex'
43])
44def test_savefig_to_stringio(format, use_log, rcParams, orientation, papersize):
45 mpl.rcParams.update(rcParams)
46 if mpl.rcParams["ps.usedistiller"] == "ghostscript":
47 try:
48 mpl._get_executable_info("gs")
49 except mpl.ExecutableNotFoundError as exc:
50 pytest.skip(str(exc))
51 elif mpl.rcParams["ps.usedistiller"] == "xpdf":
52 try:
53 mpl._get_executable_info("gs") # Effectively checks for ps2pdf.
54 mpl._get_executable_info("pdftops")
55 except mpl.ExecutableNotFoundError as exc:
56 pytest.skip(str(exc))
57
58 fig, ax = plt.subplots()
59
60 with io.StringIO() as s_buf, io.BytesIO() as b_buf:
61
62 if use_log:
63 ax.set_yscale('log')
64
65 ax.plot([1, 2], [1, 2])
66 title = "Déjà vu"
67 if not mpl.rcParams["text.usetex"]:
68 title += " \N{MINUS SIGN}\N{EURO SIGN}"
69 ax.set_title(title)
70 allowable_exceptions = []
71 if mpl.rcParams["text.usetex"]:
72 allowable_exceptions.append(RuntimeError)
73 if mpl.rcParams["ps.useafm"]:
74 allowable_exceptions.append(mpl.MatplotlibDeprecationWarning)
75 try:
76 fig.savefig(s_buf, format=format, orientation=orientation,
77 papertype=papersize)
78 fig.savefig(b_buf, format=format, orientation=orientation,
79 papertype=papersize)
80 except tuple(allowable_exceptions) as exc:
81 pytest.skip(str(exc))
82
83 assert not s_buf.closed
84 assert not b_buf.closed
85 s_val = s_buf.getvalue().encode('ascii')
86 b_val = b_buf.getvalue()
87
88 if format == 'ps':
89 # Default figsize = (8, 6) inches = (576, 432) points = (203.2, 152.4) mm.
90 # Landscape orientation will swap dimensions.
91 if mpl.rcParams["ps.usedistiller"] == "xpdf":
92 # Some versions specifically show letter/203x152, but not all,
93 # so we can only use this simpler test.
94 if papersize == 'figure':
95 assert b'letter' not in s_val.lower()
96 else:
97 assert b'letter' in s_val.lower()
98 elif mpl.rcParams["ps.usedistiller"] or mpl.rcParams["text.usetex"]:
99 width = b'432.0' if orientation == 'landscape' else b'576.0'
100 wanted = (b'-dDEVICEWIDTHPOINTS=' + width if papersize == 'figure'
101 else b'-sPAPERSIZE')

Callers

nothing calls this directly

Calls 6

updateMethod · 0.45
subplotsMethod · 0.45
set_yscaleMethod · 0.45
plotMethod · 0.45
set_titleMethod · 0.45
savefigMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…