Skip to content

Commit a2671e8

Browse files
timhoffmstory645
andauthored
Apply suggestions from code review
Co-authored-by: hannah <story645@gmail.com>
1 parent efb3382 commit a2671e8

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

doc/devel/testing.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,41 +103,40 @@ to the folder where the baseline test images are stored. The triage tool require
103103
Writing tests
104104
-------------
105105
Tests are located in :file:`lib/matplotlib/tests`. They are organized to mirror
106-
the structure of the main code in :file:`lib/matplotlib`. For example, tests for
106+
the structure of the code in :file:`lib/matplotlib`. For example, tests for
107107
the ``mathtext.py`` module are in :file:`lib/matplotlib/tests/test_mathtext.py`.
108108

109109
Naming follows standard pytest conventions:
110110

111111
- files begin with ``"test_"``
112112
- test functions begin with ``"test_"``
113-
- test class begin ``"Test"``.
113+
- test classes begin ``"Test"``.
114114

115115
We prefer simple test functions, but test classes are also acceptable.
116116
Test function names should be descriptive of what they are testing, and long names
117117
like ``test_to_rgba_array_accepts_color_alpha_tuple_with_multiple_colors()`` are
118118
perfectly fine.
119119

120-
Simple unit tests
120+
unit tests
121121
^^^^^^^^^^^^^^^^^
122122

123123
Many elements of Matplotlib can be tested using simple unit tests, e.g. ::
124124

125125
def test_to_rgba_explicit_alpha_overrides_tuple_alpha():
126126
assert mcolors.to_rgba(('red', 0.1), alpha=0.9) == (1, 0, 0, 0.9)
127127

128-
Data in tests
128+
Data
129129
^^^^^^^^^^^^^
130-
Try to use minimal explicit data. Often you can use explicit values like
131-
``[1, 2, 3]``, ``range(5)`` or ``np.arange(5)``. This is cheap and
130+
Try to use minimal explicit data, such as
131+
``[1, 2, 3]``, ``range(5)`` or ``np.arange(5)``, because it
132132
makes the test more readable.
133133

134134
When you need more and non-trivial data, generate it programmatically, e.g. ::
135135

136136
x = np.linspace(0, 2*np.pi, 101)
137137
y = 2 * np.sin(x) + 1
138138

139-
Use random numbers only, if an algorihmical way to generate the data is not
140-
possible or too cumbersome. In this case, set the seed to a fixed value to make
139+
Use random numbers only when an algorithmic way to generate the data is too cumbersome or impossible. In this case, set the seed to a fixed value to make
141140
the test deterministic. For numpy's default random number generator use ::
142141

143142
import numpy as np
@@ -149,7 +148,7 @@ The seed is :ref:`John Hunter's <project_history>` birthday.
149148

150149
Test cleanup
151150
^^^^^^^^^^^^
152-
We often need figures or modify `.rcParams` to test some functionality. Cleanup
151+
We often need to create figures or to modify `.rcParams` to test some functionality. Cleanup
153152
of such side effects is handled automatically through the the pytest fixture
154153
``matplotlib.testing.conftest.mpl_test_settings``.
155154

@@ -182,7 +181,7 @@ and asserts in one test, e.g.::
182181
assert mcolors.same_color(coll.get_facecolor(), fcolor)
183182

184183
Assert values rather than visual results when feasible. This is clearer,
185-
less expensive and less fragile than comparing images, e.g. ::
184+
less computationally expensive and less fragile than comparing images, e.g. ::
186185

187186
def test_savefig_preserve_layout_engine():
188187
fig = plt.figure(layout='compressed')

0 commit comments

Comments
 (0)