Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reuse of figure count #373

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading