@@ -37,7 +37,7 @@ def test_width_determine():
3737 ("ax" , None , "`ax` must be a Matplotlib AxesSubplot. The current `ax` is a <class 'NoneType'>" , ValueError ),
3838 ("order" , 5 , "`order` must be either an Iterable or None." , ValueError ),
3939 ("hue" , 5 , "`hue` must be either a string or None." , ValueError ),
40- ("palette" , None , "`palette` must be either a string or an Iterable." , ValueError ),
40+ ("palette" , None , "`palette` must be either a string indicating a color name or an Iterable." , ValueError ),
4141 ("zorder" , None , "`zorder` must be a scalar or float." , ValueError ),
4242 ("size" , None , "`size` must be a scalar or float." , ValueError ),
4343 ("side" , None , "Invalid `side`. Must be one of 'center', 'right', or 'left'." , ValueError ),
@@ -51,12 +51,11 @@ def test_width_determine():
5151 ("hue" , "c" , "c is not a column in `data`." , IndexError ),
5252 ("order" , ["Control 1" , "Test 2" ], "Test 2 in `order` is not in the 'group' column of `data`." , IndexError ),
5353 ("palette" , " " , "`palette` cannot be an empty string. It must be either a string indicating a color name or an Iterable." , ValueError ),
54- ("palette" , {"Control 1" : " " }, "The color mapping for Control 3 in `palette` is an empty string. It must contain a color name." , ValueError ),
55- ("palette" , {"Control 1 " : "black" }, "Control 3 in `palette` is not in the 'group' column of `data`." , IndexError ),
54+ ("palette" , {"Control 1" : " " }, "The color mapping for Control 1 in `palette` is an empty string. It must contain a color name." , ValueError ),
55+ ("palette" , {"Control 3 " : "black" }, "Control 3 in `palette` is not in the 'group' column of `data`." , IndexError ),
5656 # TODO: to add palette validation testing for when color_col is hue
5757 ("side" , "top" , "Invalid `side`. Must be one of 'center', 'right', or 'left'." , ValueError )
5858])
59- # fmt: on
6059def test_swarmplot_input_error_handling (param_name , param_value , error_msg , error_type ):
6160 with pytest .raises (error_type ) as excinfo :
6261 my_data = swarmplot (
@@ -78,7 +77,6 @@ def test_swarmplot_input_error_handling(param_name, param_value, error_msg, erro
7877 assert error_msg in str (excinfo .value )
7978
8079
81- # fmt: on
8280def test_swarmplot_warnings ():
8381 warning_msg = (
8482 "{0:.1f}% of the points cannot be placed. "
@@ -106,37 +104,33 @@ def test_swarmplot_order_params():
106104 # `order` should be able to handle customised order -> swapping of params in `order` list
107105 swarmplot (order = ["Control 1" , "Test 1" ], ** default_swarmplot_kwargs )
108106 swarmplot (order = ["Test 1" , "Control 1" ], ** default_swarmplot_kwargs )
107+
109108 # `order` should be able to handle None, where it will then be autogenerated
110109 swarmplot (order = None , ** default_swarmplot_kwargs )
111110
112111
113112def test_swarmplot_hue_params ():
114113 swarmplot (hue = "gender" , ** default_swarmplot_kwargs )
115114
116-
117- def test_swarmplot_palette_params ():
115+ @pytest .mark .parametrize ("hue, palette" , [
118116 # `palette` can be a string, list, tuple or a dict
119117 # Testing `palette` when color of swarms is based on `x` value
120- swarmplot (hue = None , palette = "black" , ** default_swarmplot_kwargs )
121- swarmplot (hue = None , palette = ["" , "red" ], ** default_swarmplot_kwargs )
122- swarmplot (hue = None , palette = ("black" , "red" ), ** default_swarmplot_kwargs )
123- swarmplot (
124- hue = None ,
125- palette = {"Control 1" : "black" , "Test 1" : "red" },
126- ** default_swarmplot_kwargs
127- )
118+ (None , "black" ),
119+ (None , ("black" , "red" )),
120+ (None , {"Control 1" : "black" , "Test 1" : "red" }),
121+
128122 # Testing `palette` when color of swarms is based on `hue` value
129- swarmplot (hue = "gender" , palette = "black" , ** default_swarmplot_kwargs )
130- swarmplot (hue = "gender" , palette = ["black" , "red" ], ** default_swarmplot_kwargs )
131- swarmplot (hue = "gender" , palette = ("black" , "red" ), ** default_swarmplot_kwargs )
132- swarmplot (
133- hue = "gender" ,
134- palette = {"Female" : "black" , "Male" : "red" },
135- ** default_swarmplot_kwargs
136- )
123+ ("gender" , "black" ),
124+ ("gender" , ["black" , "red" ]),
125+ ("gender" , ("black" , "red" )),
126+ ("gender" , {"Female" : "black" , "Male" : "red" }),
127+
137128 # Testing auto assignment of `palette` when `palette` is:
138129 # (list | tuple) and len(palette) != len(unique_color_groups)
139- swarmplot (hue = None , palette = ["black" ], ** default_swarmplot_kwargs )
130+ (None , ["black" ]),
131+ ])
132+ def test_swarmplot_palette_params (hue , palette ):
133+ swarmplot (hue = hue , palette = palette , ** default_swarmplot_kwargs )
140134
141135
142136def test_swarmplot_side_params ():
0 commit comments