From 1baf2e00d59066bd98773eebd8f856c1efbcaa79 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 5 Dec 2019 14:55:44 +0100 Subject: [PATCH] Compactify a bit the EventCollection tests. - The getter tests can be all merged into a single test (note that this will also save a couple of (costly) figure creations). - Some setter tests can also be combined. - Docstrings stating that test_EventCollection__foo tests "that foo works correctly" really don't add much. --- .../EventCollection_plot__set_ls_dash.pdf | Bin 1656 -> 0 bytes .../EventCollection_plot__set_ls_dash.png | Bin 4769 -> 0 bytes .../EventCollection_plot__set_ls_dash.svg | 226 ------------------ lib/matplotlib/tests/test_collections.py | 176 +++----------- 4 files changed, 36 insertions(+), 366 deletions(-) delete mode 100644 lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.pdf delete mode 100644 lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.png delete mode 100644 lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg diff --git a/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.pdf b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.pdf deleted file mode 100644 index 3952787106ec2cc699da7173ddc9a24af4bd312c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1656 zcmZ`)eNa?Y6c@Cdo@Ur&&WKER2FO)|_uhWN0kT z&-tD6J1@D=U`%0Cl~nQv6QJ{BiUkZ1trb*O7NCo&-4M`v4slM=4(LM84n07Q0cN1p zQc$oFVETdsy9=xpkVhabfWZe4f|3AKWJ}S7lE_;i0wvg$!HC^M9|Cla3%lJGdh0{) z9Iyw_**;{lAPzyG3_7rsb2f)y2kM}EqbMMt2&^OFunabY6EI1l*9}N2dJCWpu*$(h zvk6~@cSRB>c-))>1-?3*Y7np0l3eiz6ik+)cS4(k+a~&O=)}D$O%0R^If+px2qN-e zJ6@ZiNAyZO=7?}&4m%~ZQM4Whi#>XPCh#p1FxiLWH9DM_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*YMbnA0LyA-v9blwdVTk6tT~batc7b$vNEb ziaOFCzdxT@U!V7Qe>tqceZT*|-Mu}Pn_s5_`^xfrs=w#$sry@X{qzh~#!c=dbf`hy kS$s9{XbM7YFaKvRD|{`#b#~f9U`#T2y85}Sb4q9e00k{dqyPW_ diff --git a/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg deleted file mode 100644 index bd15342acb1e..000000000000 --- a/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg +++ /dev/null @@ -1,226 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 0983283ec078..36acd378b458 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -59,82 +59,33 @@ def generate_EventCollection_plot(): @image_comparison(['EventCollection_plot__default']) -def test__EventCollection__get_segments(): - ''' - check to make sure the default segments have the correct coordinates - ''' +def test__EventCollection__get_props(): _, coll, props = generate_EventCollection_plot() + # check that the default segments have the correct coordinates check_segments(coll, props['positions'], props['linelength'], props['lineoffset'], props['orientation']) - - -def test__EventCollection__get_positions(): - ''' - check to make sure the default positions match the input positions - ''' - _, coll, props = generate_EventCollection_plot() + # check that the default positions match the input positions np.testing.assert_array_equal(props['positions'], coll.get_positions()) - - -def test__EventCollection__get_orientation(): - ''' - check to make sure the default orientation matches the input - orientation - ''' - _, coll, props = generate_EventCollection_plot() + # check that the default orientation matches the input orientation assert props['orientation'] == coll.get_orientation() - - -def test__EventCollection__is_horizontal(): - ''' - check to make sure the default orientation matches the input - orientation - ''' - _, coll, _ = generate_EventCollection_plot() + # check that the default orientation matches the input orientation assert coll.is_horizontal() - - -def test__EventCollection__get_linelength(): - ''' - check to make sure the default linelength matches the input linelength - ''' - _, coll, props = generate_EventCollection_plot() + # check that the default linelength matches the input linelength assert props['linelength'] == coll.get_linelength() - - -def test__EventCollection__get_lineoffset(): - ''' - check to make sure the default lineoffset matches the input lineoffset - ''' - _, coll, props = generate_EventCollection_plot() + # check that the default lineoffset matches the input lineoffset assert props['lineoffset'] == coll.get_lineoffset() - - -def test__EventCollection__get_linestyle(): - ''' - check to make sure the default linestyle matches the input linestyle - ''' - _, coll, _ = generate_EventCollection_plot() + # check that the default linestyle matches the input linestyle assert coll.get_linestyle() == [(None, None)] - - -def test__EventCollection__get_color(): - ''' - check to make sure the default color matches the input color - ''' - _, coll, props = generate_EventCollection_plot() - np.testing.assert_array_equal(props['color'], coll.get_color()) - check_allprop_array(coll.get_colors(), props['color']) + # check that the default color matches the input color + for color in [coll.get_color(), *coll.get_colors()]: + np.testing.assert_array_equal(color, props['color']) @image_comparison(['EventCollection_plot__set_positions']) def test__EventCollection__set_positions(): - ''' - check to make sure set_positions works properly - ''' splt, coll, props = generate_EventCollection_plot() new_positions = np.hstack([props['positions'], props['extra_positions']]) coll.set_positions(new_positions) @@ -149,9 +100,6 @@ def test__EventCollection__set_positions(): @image_comparison(['EventCollection_plot__add_positions']) def test__EventCollection__add_positions(): - ''' - check to make sure add_positions works properly - ''' splt, coll, props = generate_EventCollection_plot() new_positions = np.hstack([props['positions'], props['extra_positions'][0]]) @@ -168,9 +116,6 @@ def test__EventCollection__add_positions(): @image_comparison(['EventCollection_plot__append_positions']) def test__EventCollection__append_positions(): - ''' - check to make sure append_positions works properly - ''' splt, coll, props = generate_EventCollection_plot() new_positions = np.hstack([props['positions'], props['extra_positions'][2]]) @@ -187,9 +132,6 @@ def test__EventCollection__append_positions(): @image_comparison(['EventCollection_plot__extend_positions']) def test__EventCollection__extend_positions(): - ''' - check to make sure extend_positions works properly - ''' splt, coll, props = generate_EventCollection_plot() new_positions = np.hstack([props['positions'], props['extra_positions'][1:]]) @@ -206,9 +148,6 @@ def test__EventCollection__extend_positions(): @image_comparison(['EventCollection_plot__switch_orientation']) def test__EventCollection__switch_orientation(): - ''' - check to make sure switch_orientation works properly - ''' splt, coll, props = generate_EventCollection_plot() new_orientation = 'vertical' coll.switch_orientation() @@ -226,10 +165,10 @@ def test__EventCollection__switch_orientation(): @image_comparison(['EventCollection_plot__switch_orientation__2x']) def test__EventCollection__switch_orientation_2x(): - ''' - check to make sure calling switch_orientation twice sets the - orientation back to the default - ''' + """ + Check that calling switch_orientation twice sets the orientation back to + the default. + """ splt, coll, props = generate_EventCollection_plot() coll.switch_orientation() coll.switch_orientation() @@ -247,9 +186,6 @@ def test__EventCollection__switch_orientation_2x(): @image_comparison(['EventCollection_plot__set_orientation']) def test__EventCollection__set_orientation(): - ''' - check to make sure set_orientation works properly - ''' splt, coll, props = generate_EventCollection_plot() new_orientation = 'vertical' coll.set_orientation(new_orientation) @@ -267,9 +203,6 @@ def test__EventCollection__set_orientation(): @image_comparison(['EventCollection_plot__set_linelength']) def test__EventCollection__set_linelength(): - ''' - check to make sure set_linelength works properly - ''' splt, coll, props = generate_EventCollection_plot() new_linelength = 15 coll.set_linelength(new_linelength) @@ -285,9 +218,6 @@ def test__EventCollection__set_linelength(): @image_comparison(['EventCollection_plot__set_lineoffset']) def test__EventCollection__set_lineoffset(): - ''' - check to make sure set_lineoffset works properly - ''' splt, coll, props = generate_EventCollection_plot() new_lineoffset = -5. coll.set_lineoffset(new_lineoffset) @@ -301,62 +231,38 @@ def test__EventCollection__set_lineoffset(): splt.set_ylim(-6, -4) -@image_comparison(['EventCollection_plot__set_linestyle']) -def test__EventCollection__set_linestyle(): - ''' - check to make sure set_linestyle works properly - ''' - splt, coll, _ = generate_EventCollection_plot() - new_linestyle = 'dashed' - coll.set_linestyle(new_linestyle) - assert coll.get_linestyle() == [(0, (6.0, 6.0))] - splt.set_title('EventCollection: set_linestyle') - - -@image_comparison(['EventCollection_plot__set_ls_dash'], remove_text=True) -def test__EventCollection__set_linestyle_single_dash(): - ''' - check to make sure set_linestyle accepts a single dash pattern - ''' - splt, coll, _ = generate_EventCollection_plot() - new_linestyle = (0, (6., 6.)) - coll.set_linestyle(new_linestyle) - assert coll.get_linestyle() == [(0, (6.0, 6.0))] - splt.set_title('EventCollection: set_linestyle') - - -@image_comparison(['EventCollection_plot__set_linewidth']) -def test__EventCollection__set_linewidth(): - ''' - check to make sure set_linestyle works properly - ''' - splt, coll, _ = generate_EventCollection_plot() - new_linewidth = 5 - coll.set_linewidth(new_linewidth) - assert coll.get_linewidth() == new_linewidth - splt.set_title('EventCollection: set_linewidth') +@image_comparison([ + 'EventCollection_plot__set_linestyle', + 'EventCollection_plot__set_linestyle', + 'EventCollection_plot__set_linewidth', +]) +def test__EventCollection__set_prop(): + for prop, value, expected in [ + ('linestyle', 'dashed', [(0, (6.0, 6.0))]), + ('linestyle', (0, (6., 6.)), [(0, (6.0, 6.0))]), + ('linewidth', 5, 5), + ]: + splt, coll, _ = generate_EventCollection_plot() + coll.set(**{prop: value}) + assert plt.getp(coll, prop) == expected + splt.set_title(f'EventCollection: set_{prop}') @image_comparison(['EventCollection_plot__set_color']) def test__EventCollection__set_color(): - ''' - check to make sure set_color works properly - ''' splt, coll, _ = generate_EventCollection_plot() new_color = np.array([0, 1, 1, 1]) coll.set_color(new_color) - np.testing.assert_array_equal(new_color, coll.get_color()) - check_allprop_array(coll.get_colors(), new_color) + for color in [coll.get_color(), *coll.get_colors()]: + np.testing.assert_array_equal(color, new_color) splt.set_title('EventCollection: set_color') def check_segments(coll, positions, linelength, lineoffset, orientation): - ''' - check to make sure all values in the segment are correct, given a - particular set of inputs - - note: this is not a test, it is used by tests - ''' + """ + Test helper checking that all values in the segment are correct, given a + particular set of inputs. + """ segments = coll.get_segments() if (orientation.lower() == 'horizontal' or orientation.lower() == 'none' or orientation is None): @@ -378,16 +284,6 @@ def check_segments(coll, positions, linelength, lineoffset, orientation): assert segment[1, pos2] == positions[i] -def check_allprop_array(values, target): - ''' - check to make sure all values match the given target if arrays - - note: this is not a test, it is used by tests - ''' - for value in values: - np.testing.assert_array_equal(value, target) - - def test_null_collection_datalim(): col = mcollections.PathCollection([]) col_data_lim = col.get_datalim(mtransforms.IdentityTransform())