You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixesDistrictDataLabs#1113 by handling some housekeeping issues. We've changed our master branch to the main branch and created a release issue template (though I don't think it is used automatically by GitHub). We've also checked the new pip resolver and all of our dependencies are compatible. This PR also updates our CI to test Python 3.8 and 3.9 to ensure we're testing on the latest version of Python.
This simple test case is an excellent start to a larger test package and we recommend starting with this test as you develop your visualizer. Once you've completed the development and prototyping you can start to include :ref:`test fixtures <fixtures>` and test various normal use cases and edge cases with unit tests, then build :ref:`image similarity tests <assert_images_similar>` to more thoroughly define the integration tests.
147
147
148
+
.. note:: In tests you should not call ``visualizer.show()`` because this will call ``plt.show()`` and trigger a matplotlib warning that the visualization cannot be displayed using the test backend ``Agg``. Calling ``visualizer.finalize()`` instead should produce the full image and make the tests faster and more readable.
149
+
148
150
149
151
Running the Test Suite
150
152
~~~~~~~~~~~~~~~~~~~~~~
@@ -157,9 +159,15 @@ The required dependencies for the test suite include testing utilities and libra
157
159
158
160
Tests can be run as follows from the project root::
159
161
160
-
$ make test
162
+
$ pytest
163
+
164
+
The ``pytest`` function is configured via ``setup.cfg`` with the correct arguments and runner, and therefore must be run from the project root. You can also use ``make test`` but this simply runs the ``pytest`` command.
165
+
166
+
The tests do take a while to run, so during normal development it is recommended that you only run the tests for the test file you're writing::
167
+
168
+
$ pytest tests/test_package/test_module.py
161
169
162
-
The Makefile uses the pytest runner and testing suite as well as the coverage library.
170
+
This will greatly simplify development and allow you to focus on the changes that you're making!
163
171
164
172
.. _assert_images_similar:
165
173
@@ -181,7 +189,7 @@ For example, create your test function located in ``tests/test_regressor/test_my
181
189
deftest_my_visualizer_output(self):
182
190
visualizer = MyVisualizer()
183
191
visualizer.fit(X)
184
-
visualizer.show()
192
+
visualizer.finalize()
185
193
self.assert_images_similar(visualizer)
186
194
187
195
The first time this test is run, there will be no baseline image to compare against, so the test will fail. Copy the output images (in this case ``tests/actual_images/test_regressor/test_myvisualizer/test_my_visualizer_output.png``) to the correct subdirectory of baseline_images tree in the source directory (in this case ``tests/baseline_images/test_regressor/test_myvisualizer/test_my_visualizer_output.png``). Put this new file under source code revision control (with git add). When rerunning the tests, they should now pass.
@@ -196,6 +204,20 @@ This will move all related test images from ``actual_images`` to ``baseline_imag
196
204
197
205
This is useful particularly if you're stuck trying to get an image comparison to work. For more information on the images helper script, use ``python -m tests.images --help``.
198
206
207
+
Finally, to reiterate a note from above; make sure that you do not call your visualizer's ``show()`` method, instead using ``finalize()`` directly. If you call ``show()``, it will in turn call ``plt.show()`` which will issue a warning due to the fact that the tests use the ``Agg`` backend. When testing quick methods you should pass the ``show=False`` argument to the quick method as follows:
Generally speaking, testing quick methods is identical to testing Visualizers except for the method of interaction because the quick method will return the visualizer or the axes object.
0 commit comments