Skip to content

Commit

Permalink
Fix reuse of figure count (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Jan 11, 2024
2 parents c551c5f + 0befe71 commit 658e712
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions papyri/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ def _normalize_see_also(see_also: Section, qa: str):

class PapyriDocTestRunner(doctest.DocTestRunner):
def __init__(self, *args, gen, obj, qa, config, **kwargs):
self._count = count(0)
self.gen = gen
self.obj = obj
self.qa = qa
Expand Down Expand Up @@ -1082,14 +1083,14 @@ def _get_tok_entries(self, example):
tok_entries = [GenToken(*x) for x in entries] # type: ignore
return tok_entries

def _figure_names(self):
def _next_figure_name(self):
"""
File system can be case insensitive, we are not.
"""
for i in count(0):
pat = f"fig-{self.qa}-{i}"
sha = sha256(pat.encode()).hexdigest()[:8]
yield f"{pat}-{sha}.png"
i = next(self._count)
pat = f"fig-{self.qa}-{i}"
sha = sha256(pat.encode()).hexdigest()[:8]
return f"{pat}-{sha}.png"

def report_start(self, out, test, example):
pass
Expand All @@ -1103,13 +1104,12 @@ def report_success(self, out, test, example, got):
Code(tok_entries, got, ExecutionStatus.success)
)

figure_names = self._figure_names()

wait_for_show = self.config.wait_for_plt_show
fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()
figs = []
if fig_managers and (("plt.show" in example.source) or not wait_for_show):
for fig, figname in zip(fig_managers, figure_names):
for fig in fig_managers:
figname = self._next_figure_name()
buf = io.BytesIO()
fig.canvas.figure.savefig(buf, dpi=300) # , bbox_inches="tight"
buf.seek(0)
Expand Down

0 comments on commit 658e712

Please sign in to comment.