@@ -65,44 +65,71 @@ def test_resampled():
6565
6666
6767def test_register_cmap ():
68- new_cm = cm . get_cmap ( "viridis" )
68+ new_cm = mpl . colormaps [ "viridis" ]
6969 target = "viridis2"
70- cm .register_cmap (target , new_cm )
71- assert plt .get_cmap (target ) == new_cm
70+ with pytest .warns (
71+ PendingDeprecationWarning ,
72+ match = r"matplotlib\.colormaps\.register_cmap\(name\)"
73+ ):
74+ cm .register_cmap (target , new_cm )
75+ assert mpl .colormaps [target ] == new_cm
7276
7377 with pytest .raises (ValueError ,
7478 match = "Arguments must include a name or a Colormap" ):
75- cm .register_cmap ()
76-
77- cm .unregister_cmap (target )
79+ with pytest .warns (
80+ PendingDeprecationWarning ,
81+ match = r"matplotlib\.colormaps\.register_cmap\(name\)"
82+ ):
83+ cm .register_cmap ()
84+
85+ with pytest .warns (
86+ PendingDeprecationWarning ,
87+ match = r"matplotlib\.colormaps\.unregister_cmap\(name\)"
88+ ):
89+ cm .unregister_cmap (target )
7890 with pytest .raises (ValueError ,
7991 match = f'{ target !r} is not a valid value for name;' ):
80- cm .get_cmap (target )
81- # test that second time is error free
82- cm .unregister_cmap (target )
92+ with pytest .warns (
93+ PendingDeprecationWarning ,
94+ match = r"matplotlib\.colormaps\[name\]"
95+ ):
96+ cm .get_cmap (target )
97+ with pytest .warns (
98+ PendingDeprecationWarning ,
99+ match = r"matplotlib\.colormaps\.unregister_cmap\(name\)"
100+ ):
101+ # test that second time is error free
102+ cm .unregister_cmap (target )
83103
84104 with pytest .raises (TypeError , match = "'cmap' must be" ):
85- cm .register_cmap ('nome' , cmap = 'not a cmap' )
105+ with pytest .warns (
106+ PendingDeprecationWarning ,
107+ match = r"matplotlib\.colormaps\.register_cmap\(name\)"
108+ ):
109+ cm .register_cmap ('nome' , cmap = 'not a cmap' )
86110
87111
88112def test_double_register_builtin_cmap ():
89113 name = "viridis"
90114 match = f"Re-registering the builtin cmap { name !r} ."
91115 with pytest .raises (ValueError , match = match ):
92116 matplotlib .colormaps .register (
93- cm . get_cmap ( name ) , name = name , force = True
117+ mpl . colormaps [ name ] , name = name , force = True
94118 )
95119 with pytest .raises (ValueError , match = 'A colormap named "viridis"' ):
96- cm .register_cmap (name , cm .get_cmap (name ))
120+ with pytest .warns ():
121+ cm .register_cmap (name , mpl .colormaps [name ])
97122 with pytest .warns (UserWarning ):
98- cm .register_cmap (name , cm .get_cmap (name ), override_builtin = True )
123+ # TODO is warning more than once!
124+ cm .register_cmap (name , mpl .colormaps [name ], override_builtin = True )
99125
100126
101127def test_unregister_builtin_cmap ():
102128 name = "viridis"
103129 match = f'cannot unregister { name !r} which is a builtin colormap.'
104130 with pytest .raises (ValueError , match = match ):
105- cm .unregister_cmap (name )
131+ with pytest .warns ():
132+ cm .unregister_cmap (name )
106133
107134
108135def test_colormap_copy ():
0 commit comments