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

Function test_axes_clear_reference_cycle

lib/matplotlib/tests/test_axes.py:10031–10067  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10029 reason="https://github.com/python/cpython/issues/124538",
10030)
10031def test_axes_clear_reference_cycle():
10032 def assert_not_in_reference_cycle(start):
10033 # Breadth first search. Return True if we encounter the starting node
10034 to_visit = deque([start])
10035 explored = set()
10036 while len(to_visit) > 0:
10037 parent = to_visit.popleft()
10038 for child in gc.get_referents(parent):
10039 if id(child) in explored:
10040 continue
10041 assert child is not start
10042 explored.add(id(child))
10043 to_visit.append(child)
10044
10045 fig = Figure()
10046 ax = fig.add_subplot()
10047 points = np.random.rand(1000)
10048 ax.plot(points, points)
10049 ax.scatter(points, points)
10050 ax_children = ax.get_children()
10051 fig.clear() # This should break the reference cycle
10052
10053 # Care most about the objects that scale with number of points
10054 big_artists = [
10055 a for a in ax_children
10056 if isinstance(a, (Line2D, PathCollection))
10057 ]
10058 assert len(big_artists) > 0
10059 for big_artist in big_artists:
10060 assert_not_in_reference_cycle(big_artist)
10061 assert len(ax_children) > 0
10062 for child in ax_children:
10063 # Make sure this doesn't raise because the child is already removed.
10064 try:
10065 child.remove()
10066 except NotImplementedError:
10067 pass # not implemented is expected for some artists
10068
10069
10070def test_boxplot_tick_labels():

Callers

nothing calls this directly

Calls 8

clearMethod · 0.95
FigureClass · 0.90
add_subplotMethod · 0.80
plotMethod · 0.45
scatterMethod · 0.45
get_childrenMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…