Skip to content

Commit 92d9aa0

Browse files
committed
add tests
1 parent 2c94a19 commit 92d9aa0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/plot_test.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22

33
import numpy as np
4+
import pytest
45

56
import matplotgl.pyplot as plt
67

@@ -60,3 +61,90 @@ def test_imshow():
6061
im = ax.images[0]
6162
assert np.allclose(im._array, data)
6263
assert im.get_extent() == [0, 10, 0, 5]
64+
65+
66+
def test_set_xscale_log():
67+
_, ax = plt.subplots()
68+
x = np.arange(50.0)
69+
y = np.sin(0.2 * x)
70+
71+
ax.plot(x, y, lw=2)
72+
ax.set_xscale('log')
73+
74+
assert ax.get_xscale() == 'log'
75+
76+
77+
def test_set_yscale_log():
78+
_, ax = plt.subplots()
79+
x = np.arange(50.0)
80+
y = np.sin(0.2 * x)
81+
82+
ax.plot(x, y, lw=2)
83+
ax.set_yscale('log')
84+
85+
assert ax.get_yscale() == 'log'
86+
87+
88+
def test_set_xscale_invalid():
89+
_, ax = plt.subplots()
90+
with pytest.raises(ValueError, match="Scale must be 'linear' or 'log'"):
91+
ax.set_xscale('invalid_scale')
92+
93+
94+
def test_set_yscale_invalid():
95+
_, ax = plt.subplots()
96+
with pytest.raises(ValueError, match="Scale must be 'linear' or 'log'"):
97+
ax.set_yscale('invalid_scale')
98+
99+
100+
def test_set_xscale_log_before_plot():
101+
_, ax = plt.subplots()
102+
x = np.arange(50.0)
103+
y = np.sin(0.2 * x)
104+
105+
ax.set_xscale('log')
106+
ax.plot(x, y, lw=2)
107+
108+
assert ax.get_xscale() == 'log'
109+
110+
111+
def test_set_yscale_log_before_plot():
112+
_, ax = plt.subplots()
113+
x = np.arange(50.0)
114+
y = np.sin(0.2 * x)
115+
116+
ax.set_yscale('log')
117+
ax.plot(x, y, lw=2)
118+
119+
assert ax.get_yscale() == 'log'
120+
121+
122+
def test_semilogx():
123+
_, ax = plt.subplots()
124+
x = np.arange(1.0, 50.0)
125+
y = np.sin(0.2 * x)
126+
127+
ax.semilogx(x, y, lw=2)
128+
129+
assert ax.get_xscale() == 'log'
130+
131+
132+
def test_semilogy():
133+
_, ax = plt.subplots()
134+
x = np.arange(50.0)
135+
y = np.exp(0.1 * x)
136+
137+
ax.semilogy(x, y, lw=2)
138+
139+
assert ax.get_yscale() == 'log'
140+
141+
142+
def test_loglog():
143+
_, ax = plt.subplots()
144+
x = np.arange(1.0, 50.0)
145+
y = np.exp(0.1 * x)
146+
147+
ax.loglog(x, y, lw=2)
148+
149+
assert ax.get_xscale() == 'log'
150+
assert ax.get_yscale() == 'log'

0 commit comments

Comments
 (0)