Skip to content

Commit 9c96d16

Browse files
Darylgoldenbehackljsonvillanueva
authored
Copyedited the document on testing in our documentation (#1217)
* Copyediting testing.rst * More copyediting * Clarifications on how to generate control test data * More copyediting * removed one whitespace * More fixes * Minor fix Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Jason Villanueva <[email protected]>
1 parent f3bd42f commit 9c96d16

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

docs/source/contributing/testing.rst

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
============
22
Adding Tests
33
============
4-
When adding a new feature, it should always be tested. Tests prevent
5-
manim from breaking at each new feature added by checking if any other
4+
If you are adding new features to manim, you should add appropriate tests for them. Tests prevent
5+
manim from breaking at each change by checking that no other
66
feature has been broken and/or been unintentionally modified.
77

88
How Manim Tests
99
---------------
1010

11-
To conduct our tests, we use ``pytest``. Running ``pytest`` in the root of
12-
the project will start the testing process, and will show if there is
13-
something wrong.
11+
Manim uses pytest as its testing framework.
12+
To start the testing process, go to the root directory of the project and run pytest in your terminal.
13+
Any errors that occur during testing will be displayed in the terminal.
1414

1515
Some useful pytest flags:
16-
- ``-x``, that will make pytest stop at the first fail,
17-
- ``-s``, that will make pytest display all the print messages (including those during scene generation, like DEBUG messages).
18-
- ``--skip_slow`` will skip the (arbitrarly) slow tests.
19-
- ``--show_diff`` will show a visual comparison in case an unit test is
20-
failing.
16+
17+
- ``-x`` will make pytest stop at the first failure it encounters
18+
19+
- ``-s`` will make pytest display all the print messages (including those during scene generation, like DEBUG messages)
20+
21+
- ``--skip_slow`` will skip the (arbitrarily) slow tests
22+
23+
- ``--show_diff`` will show a visual comparison in case an unit test is failing.
24+
2125

2226
How it Works
2327
~~~~~~~~~~~~
@@ -26,30 +30,28 @@ At the moment there are three type of tests:
2630

2731
#. Unit Tests:
2832

29-
Basically test for pretty much everything. For example, there a test for
30-
``Mobject``, that checks if it can be added to a Scene, etc ..
33+
Tests for most of the basic functionalities of manim. For example, there a test for
34+
``Mobject``, that checks if it can be added to a Scene, etc.
3135

3236
#. Graphical unit tests:
3337

34-
Because ``manim`` is a video library, we tests frames. To do so, we take a
35-
frame of control data for each feature and compare the last frame of the
36-
feature rendered (in the form of a numpy array). If it matches, the tests
37-
are successful. If one wants to visually see the what has changed, you can
38-
use ``--show_diff`` flag along with ``pytest`` to be able to visualize
39-
what is different.
38+
Because ``manim`` is a graphics library, we test frames. To do so, we create test scenes that render a specific feature.
39+
When pytest runs, it compares the last frame of every render to the control data; If it matches, the tests
40+
pass. If the test and control data differ, the tests fail. You can
41+
use ``--show_diff`` flag with ``pytest`` to visually see the differences.
4042

4143
#. Videos format tests:
4244

43-
As Manim is a video library, we have to test videos as well. Unfortunalty,
44-
we can't test directly video content as manim outputs videos that can
45-
differ slightly from one system to another (for reasons related to
46-
ffmpeg). As such, we just compare videos configuration values, exported in
45+
As Manim is a video library, we have to test videos as well. Unfortunately,
46+
we cannot directly test video content as rendered videos can
47+
differ slightly depending on system (for reasons related to
48+
ffmpeg). Therefore, we only compare video configuration values, exported in
4749
.json.
4850

4951
Architecture
5052
------------
5153

52-
``manim/tests`` directory looks like this:
54+
The ``manim/tests`` directory looks like this:
5355

5456
::
5557

@@ -123,29 +125,27 @@ The Main Directories
123125

124126
- ``control_data/``:
125127

126-
Here control data is saved. These are generally frames
127-
that we expect to see. In ``control_data/graphical_units_data/`` are all the
128-
.npz (represented the last frame) used in graphical unit tests videos, and in
129-
``control_data/videos_data/`` some .json used to check videos.
128+
The directory containing control data. ``control_data/graphical_units_data/`` contains the expected and correct frame data for graphical tests, and
129+
``control_data/videos_data/`` contains the .json files used to check videos.
130130

131131
- ``test_graphical_units/``:
132132

133-
For tests related to visual items that can appear in media
133+
Contains graphical tests.
134134

135135
- ``test_scene_rendering/``:
136136

137-
For tests that need to render a scene in a way or another. For example, CLI
137+
For tests that need to render a scene in some way, such as tests for CLI
138138
flags (end-to-end tests).
139139

140140
- ``utils/``:
141141

142-
Useful internal functions used by pytest to test.
142+
Useful internal functions used by pytest.
143143

144144
.. Note:: fixtures are not contained here, they are in ``conftest.py``.
145145

146146
- ``helpers/``:
147147

148-
Helper function for developers to setup graphical/video tests.
148+
Helper functions for developers to setup graphical/video tests.
149149

150150
Adding a New Test
151151
-----------------
@@ -154,21 +154,21 @@ Unit Tests
154154
~~~~~~~~~~
155155

156156
Pytest determines which functions are tests by searching for files whose
157-
names begin with "test\_" and then within those files for functions
158-
beginning with "test" or classes beginning with "Test". These kind of
157+
names begin with "test\_", and then within those files for functions
158+
beginning with "test" and classes beginning with "Test". These kind of
159159
tests must be in ``tests/`` (e.g. ``tests/test_container.py``).
160160

161161
Graphical Unit Test
162162
~~~~~~~~~~~~~~~~~~~
163163

164-
The test must be written in the correct file and follow the structure
164+
The test must be written in the correct file (i.e. the file that corresponds to the appropriate category the feature belongs to) and follow the structure
165165
of unit tests.
166166

167167
For example, to test the ``Circle`` VMobject which resides in
168168
``manim/mobject/geometry.py``, add the CircleTest to
169169
``test/test_geometry.py``.
170170

171-
In ``test_geometry.py``:
171+
In ``test_geometry.py``, add:
172172

173173
.. code:: python
174174
@@ -183,7 +183,7 @@ we are testing whether Circle properly shows up with the generic
183183

184184
.. Note::
185185

186-
If the file already exists, just add to its content. The
186+
If the file already exists, edit it and add the test within the file. The
187187
``Scene`` will be tested thanks to the ``GraphicalUnitTester`` that lives
188188
in ``tests/utils/GraphicalUnitTester.py``. Import it with ``from
189189
..utils.GraphicalUnitTester import GraphicalUnitTester``.
@@ -202,14 +202,14 @@ It is used to run a test function several times with different
202202
parameters. Here, we pass in all the scenes as arguments.
203203

204204
.. warning::
205-
If you run pytest now, you will get a ``FileNotFound`` error. It's because
206-
you haven't created control data for your test.
205+
If you run pytest now, you will get a ``FileNotFound`` error. This is because
206+
you have not created control data for your test.
207207

208208
Next, we'll want to create control data for ``CircleTest``. In
209-
``tests/template_generate_graphical_units_data.py``, there exist the
209+
``tests/template_generate_graphical_units_data.py``, there exists the
210210
function, ``set_test_scene``, for this purpose.
211211

212-
It will looks like this :
212+
It will look something like this:
213213

214214
.. code:: python
215215
@@ -220,17 +220,17 @@ It will looks like this :
220220
221221
set_test_scene(CircleTest, "geometry")
222222
223-
``set_test_scene`` takes two parameters : the scene to test, and the
224-
module name. It will automatically generate the control data at the
225-
right place (in this case,
223+
``set_test_scene`` takes two parameters: the scene to test, and the
224+
module name. You can generate the test data by running the file (it suffices to type the name of the file in terminal; you do not have to run
225+
it like how you would normally run manim files). It will automatically generate the control data in the
226+
right directory (in this case,
226227
``tests/control_data/graphical_units_data/geometry/CircleTest.npz``).
227228

228-
That's all there is to it. Please make sure to add the control data to git as
229-
soon as it is produced with ``git add <your-control-data.npz>`` but do NOT
230-
include changes to the template script in your pull request so that others
231-
may continue to use the template file
232-
(template\_generate\_graphical\_units\_data.py) will be still available for
233-
others.
229+
Please make sure to add the control data to git as
230+
soon as it is produced with ``git add <your-control-data.npz>``. However, do not
231+
include changes to the template script (template\_generate\_graphical\_units\_data.py) in your pull request so that others
232+
may continue to use the unmodified file to generate their own tests.
233+
234234

235235
Videos tests
236236
~~~~~~~~~~~~
@@ -258,9 +258,9 @@ To test videos generated, we use the decorator
258258
out, err, exit_code = capture(command)
259259
assert exit_code == 0, err
260260
261-
.. Note:: ``assert exit*\ code == 0, err`` is used in case of the command fails
262-
to run. The decorator takes two arguments: json name and the path
263-
to where the video should be generated, starting from the ``medias/`` dir.
261+
.. Note:: ``assert exit*\ code == 0, err`` is used in case of the command fails
262+
to run. The decorator takes two arguments: json name and the path
263+
to where the video should be generated, starting from the ``medias/`` dir.
264264

265265
Note the fixtures here:
266266

@@ -282,11 +282,11 @@ you're done. Then run:
282282

283283
.. code:: python
284284
285-
save_control_data_from_video(<path-to-video>, "SquareToCircleWithlFlag.json").
285+
save_control_data_from_video(<path-to-video>, "SquareToCircleWithlFlag.json")
286286
287287
Running this will save
288-
``control_data/videos_data/SquareToCircleWithlFlag.json``, whoch will
289-
looks like this :
288+
``control_data/videos_data/SquareToCircleWithlFlag.json``, which will
289+
look like this:
290290

291291
.. code:: json
292292
@@ -302,5 +302,5 @@ looks like this :
302302
}
303303
}
304304
305-
If you have any question don't hesitate to ask on `Discord
306-
<https://discord.gg/mMRrZQW>`_, in your pull request, or open an issue.
305+
If you have any questions, please don't hesitate to ask on `Discord
306+
<https://discord.gg/mMRrZQW>`_, in your pull request, or in an issue.

0 commit comments

Comments
 (0)