Skip to content

Commit e1af82b

Browse files
committed
Put tests inside functions
1 parent f65333a commit e1af82b

File tree

10 files changed

+1460
-1540
lines changed

10 files changed

+1460
-1540
lines changed

proplot/tests/test_1dplots.py

Lines changed: 273 additions & 276 deletions
Large diffs are not rendered by default.

proplot/tests/test_2dplots.py

Lines changed: 255 additions & 260 deletions
Large diffs are not rendered by default.

proplot/tests/test_backends.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

proplot/tests/test_children.py

Lines changed: 110 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -6,110 +6,113 @@
66

77
import proplot as pplt
88

9-
# ## Twin axes
10-
#
11-
# Adjust twin axis positions. Should allow easily switching the location.
12-
13-
fig = pplt.figure()
14-
ax = fig.subplot()
15-
ax.format(
16-
ycolor='blue', ylabel='original',
17-
ylabelcolor='blue9', labelweight='bold', xlabel='xlabel'
18-
)
19-
alt = ax.alty(
20-
loc='left', color='red', labelcolor='red9', label='alternative', labelweight='bold'
21-
)
22-
23-
# A simple example but doesn't quite work
24-
# Figure out how to specify left vs. right spines for 'offset'
25-
# locations... maybe needs another keyword.
26-
fig, ax = pplt.subplots()
27-
ax.format(ymax=10, ylabel='Reference')
28-
ax.alty(color='green', label='Green', max=8)
29-
ax.alty(color='red', label='Red', max=15, loc=('axes', -0.2))
30-
ax.alty(color='blue', label='Blue', max=5, loc=('axes', 1.2), ticklabeldir='out')
31-
32-
# A worked example from Riley Brady
33-
# Uses auto-adjusting limits
34-
fig, ax = pplt.subplots()
35-
axs = [ax, ax.twinx(), ax.twinx()]
36-
axs[-1].spines['right'].set_position(('axes', 1.2))
37-
colors = ('Green', 'Red', 'Blue')
38-
for ax, color in zip(axs, colors):
39-
data = np.random.random(1) * np.random.random(10)
40-
ax.plot(data, marker='o', linestyle='none', color=color)
41-
ax.format(ylabel='%s Thing' % color, ycolor=color)
42-
axs[0].format(xlabel='xlabel')
43-
44-
# ## Including panels
45-
#
46-
# Test label sharing for `includepanels=True`.
47-
48-
# %matplotlib inline
49-
50-
for b in range(3):
51-
for ncols in range(1, 3):
52-
fig, axs = pplt.subplots(ncols=ncols, refwidth=1.5, includepanels=(b == 2))
53-
if b:
54-
for _ in range(3):
55-
axs[0].panel('l')
56-
axs.format(xlabel='xlabel\nxlabel\nxlabel', ylabel='ylabel', suptitle='Title')
57-
58-
# ## Inset colors
59-
#
60-
# Test color application for zoom boxes.
61-
62-
fig, ax = pplt.subplots()
63-
ax.format(xlim=(0, 100), ylim=(0, 100))
64-
ix = ax.inset_axes(
65-
(0.5, 0.5, 0.3, 0.3), zoom=True, zoom_kw={'color': 'r', 'fc': 'r', 'ec': 'b'}
66-
) # zoom_kw={'alpha': 1})
67-
# ix = ax.inset_axes((40, 40, 20, 20), zoom=True, transform='data')
68-
ix.format(xlim=(10, 20), ylim=(10, 20), grid=False)
69-
70-
fig, ax = pplt.subplots()
71-
ax.format(xlim=(0, 100), ylim=(0, 100))
72-
ix = ax.inset_axes(
73-
(0.3, 0.5, 0.5, 0.3), zoom=True,
74-
zoom_kw={'lw': 3, 'ec': 'red9', 'a': 1, 'c': pplt.set_alpha('red4', 0.5)}
75-
)
76-
ix.format(xlim=(10, 20), ylim=(10, 20))
77-
78-
# ## Inset zoom update
79-
#
80-
# Test automatic limit adjusment with successive changes. Without the extra lines in
81-
# `draw()` and `get_tight_bbox()` this fails.
82-
83-
fig, ax = pplt.subplots()
84-
ax.format(xlim=(0, 100), ylim=(0, 100))
85-
ix = ax.inset_axes((40, 40, 20, 20), zoom=True, transform='data')
86-
ix.format(xlim=(10, 20), ylim=(10, 20), grid=False)
87-
88-
ix.format(xlim=(10, 20), ylim=(10, 30))
89-
fig.show()
90-
91-
ax.format(ylim=(0, 300))
92-
fig.show()
93-
94-
# ## Panels with sharing
95-
#
96-
# Previously the below text would hide the second y label.
97-
98-
fig, axs = pplt.subplots(ncols=2, share=False, refwidth=1.5)
99-
pxs = axs.panel('left')
100-
fig.format(ylabel='ylabel', xlabel='xlabel')
101-
102-
# ## Panels without sharing
103-
#
104-
# What should happen if `share=False` but figure-wide sharing enabled? Strange use case
105-
# but behavior appears "correct."
106-
107-
fig, axs = pplt.subplots(ncols=2, share=True, refwidth=1.5, includepanels=False)
108-
pxs = axs.panel('left', share=False)
109-
fig.format(ylabel='ylabel', xlabel='xlabel')
110-
111-
fig, axs = pplt.subplots(ncols=2, refwidth=1.5, includepanels=True)
112-
for _ in range(3):
113-
p = axs[0].panel('l', space=0)
114-
p.format(xlabel='label')
115-
fig.format(xlabel='xlabel')
9+
10+
def test_twin_axes():
11+
"""
12+
Adjust twin axis positions. Should allow easily switching the location.
13+
"""
14+
# Improve layout
15+
fig = pplt.figure()
16+
ax = fig.subplot()
17+
ax.format(
18+
ycolor='blue', ylabel='orig', ylabelcolor='blue9',
19+
labelweight='bold', xlabel='xlabel'
20+
)
21+
ax.alty(loc='l', color='r', labelcolor='red9', label='other', labelweight='bold')
22+
23+
# A simple example but doesn't quite work
24+
# Figure out how to specify left vs. right spines for 'offset'
25+
# locations... maybe needs another keyword.
26+
fig, ax = pplt.subplots()
27+
ax.format(ymax=10, ylabel='Reference')
28+
ax.alty(color='green', label='Green', max=8)
29+
ax.alty(color='red', label='Red', max=15, loc=('axes', -0.2))
30+
ax.alty(color='blue', label='Blue', max=5, loc=('axes', 1.2), ticklabeldir='out')
31+
32+
# A worked example from Riley Brady
33+
# Uses auto-adjusting limits
34+
fig, ax = pplt.subplots()
35+
axs = [ax, ax.twinx(), ax.twinx()]
36+
axs[-1].spines['right'].set_position(('axes', 1.2))
37+
colors = ('Green', 'Red', 'Blue')
38+
for ax, color in zip(axs, colors):
39+
data = np.random.random(1) * np.random.random(10)
40+
ax.plot(data, marker='o', linestyle='none', color=color)
41+
ax.format(ylabel='%s Thing' % color, ycolor=color)
42+
axs[0].format(xlabel='xlabel')
43+
44+
45+
def test_including_panels():
46+
"""
47+
Test label sharing for `includepanels=True`.
48+
"""
49+
for b in range(3):
50+
for ncols in range(1, 3):
51+
fig, axs = pplt.subplots(ncols=ncols, refwidth=1.5, includepanels=(b == 2))
52+
if b:
53+
for _ in range(3):
54+
axs[0].panel('l')
55+
axs.format(xlabel='xlabel\nxlabel\nxlabel', ylabel='ylabel', suptitle='sup')
56+
57+
58+
def test_inset_colors():
59+
"""
60+
Test color application for zoom boxes.
61+
"""
62+
fig, ax = pplt.subplots()
63+
ax.format(xlim=(0, 100), ylim=(0, 100))
64+
ix = ax.inset_axes(
65+
(0.5, 0.5, 0.3, 0.3), zoom=True, zoom_kw={'color': 'r', 'fc': 'r', 'ec': 'b'}
66+
) # zoom_kw={'alpha': 1})
67+
# ix = ax.inset_axes((40, 40, 20, 20), zoom=True, transform='data')
68+
ix.format(xlim=(10, 20), ylim=(10, 20), grid=False)
69+
70+
fig, ax = pplt.subplots()
71+
ax.format(xlim=(0, 100), ylim=(0, 100))
72+
ix = ax.inset_axes(
73+
(0.3, 0.5, 0.5, 0.3), zoom=True,
74+
zoom_kw={'lw': 3, 'ec': 'red9', 'a': 1, 'c': pplt.set_alpha('red4', 0.5)}
75+
)
76+
ix.format(xlim=(10, 20), ylim=(10, 20))
77+
78+
79+
def test_inset_zoom_update():
80+
"""
81+
Test automatic limit adjusment with successive changes. Without the extra
82+
lines in `draw()` and `get_tight_bbox()` this fails.
83+
"""
84+
fig, ax = pplt.subplots()
85+
ax.format(xlim=(0, 100), ylim=(0, 100))
86+
ix = ax.inset_axes((40, 40, 20, 20), zoom=True, transform='data')
87+
ix.format(xlim=(10, 20), ylim=(10, 20), grid=False)
88+
89+
ix.format(xlim=(10, 20), ylim=(10, 30))
90+
fig.show()
91+
92+
ax.format(ylim=(0, 300))
93+
fig.show()
94+
95+
96+
def test_panels_with_sharing():
97+
"""
98+
Previously the below text would hide the second y label.
99+
"""
100+
fig, axs = pplt.subplots(ncols=2, share=False, refwidth=1.5)
101+
axs.panel('left')
102+
fig.format(ylabel='ylabel', xlabel='xlabel')
103+
104+
105+
def test_panels_without_sharing():
106+
"""
107+
What should happen if `share=False` but figure-wide sharing enabled?
108+
Strange use case but behavior appears "correct."
109+
"""
110+
fig, axs = pplt.subplots(ncols=2, share=True, refwidth=1.5, includepanels=False)
111+
axs.panel('left', share=False)
112+
fig.format(ylabel='ylabel', xlabel='xlabel')
113+
114+
fig, axs = pplt.subplots(ncols=2, refwidth=1.5, includepanels=True)
115+
for _ in range(3):
116+
p = axs[0].panel('l', space=0)
117+
p.format(xlabel='label')
118+
fig.format(xlabel='xlabel')

0 commit comments

Comments
 (0)