diff --git a/tests/unit/plotting_tests/test_plot_legend.py b/tests/unit/plotting_tests/test_plot_legend.py index e53cc34f..ac7c5da6 100644 --- a/tests/unit/plotting_tests/test_plot_legend.py +++ b/tests/unit/plotting_tests/test_plot_legend.py @@ -31,12 +31,10 @@ def test_return_type_without_handles(self, dict_color): ax_returned = aa.plot_legend(ax=self.ax, dict_color=dict_color) assert isinstance(ax_returned, plt.Axes) - def test_legend_created(self, dict_color): ax = aa.plot_legend(ax=self.ax, dict_color=dict_color) assert ax.get_legend() is not None - def test_invalid_line_width(self, dict_color): with pytest.raises(ValueError): aa.plot_legend(ax=self.ax, dict_color=dict_color, lw="not right") @@ -48,7 +46,7 @@ def test_invalid_marker_size(self, marker_size, dict_color): aa.plot_legend(ax=self.ax, dict_color=dict_color, marker_size=marker_size) @settings(max_examples=5, deadline=500) - @given(marker=st.text(min_size=1, max_size=5)) + @given(marker=st.text(min_size=2, max_size=5)) @example(marker="invalid_marker") def test_invalid_marker(self, marker, dict_color): valid_markers = [None, "-"] + list(mlines.Line2D.markers.keys()) @@ -64,7 +62,6 @@ def test_plot_set_legend_n_cols(self, n_cols, dict_color): result = aa.plot_legend(ax=ax, n_cols=n_cols, dict_color=dict_color) assert isinstance(result, plt.Axes) - @settings(max_examples=5, deadline=500) @given(labelspacing=st.floats(0, 5)) def test_plot_set_legend_labelspacing(self, labelspacing, dict_color): @@ -73,7 +70,6 @@ def test_plot_set_legend_labelspacing(self, labelspacing, dict_color): result = aa.plot_legend(ax=ax, labelspacing=labelspacing, dict_color=dict_color) assert isinstance(result, plt.Axes) - @settings(max_examples=5, deadline=500) @given(columnspacing=st.floats(0, 5)) def test_plot_set_legend_columnspacing(self, columnspacing, dict_color): @@ -82,7 +78,6 @@ def test_plot_set_legend_columnspacing(self, columnspacing, dict_color): result = aa.plot_legend(ax=ax, columnspacing=columnspacing, dict_color=dict_color) assert isinstance(result, plt.Axes) - @settings(max_examples=5, deadline=500) @given(handletextpad=st.floats(0, 5)) def test_plot_set_legend_handletextpad(self, handletextpad, dict_color): @@ -91,14 +86,12 @@ def test_plot_set_legend_handletextpad(self, handletextpad, dict_color): result = aa.plot_legend(ax=ax, handletextpad=handletextpad, dict_color=dict_color) assert isinstance(result, plt.Axes) - def test_legend_positioning(self, dict_color): """Test the positioning with x, y, and loc_out.""" ax = plt.gca() result = aa.plot_legend(ax=ax, loc_out=True, x=0, y=0, dict_color=dict_color) assert isinstance(result, plt.Axes) - def test_plot_set_legend_loc_outside(self, dict_color): """Test 'loc_out' parameter.""" fig, ax = plt.subplots() @@ -106,7 +99,6 @@ def test_plot_set_legend_loc_outside(self, dict_color): aa.plot_legend(ax=ax, loc_out=True, dict_color=dict_color) assert ax.get_legend().get_bbox_to_anchor().y0 <= 0 - def test_plot_set_legend_invalid_fontsize(self, dict_color): """Test with 'fontsize' less than 0.""" fig, ax = plt.subplots() @@ -114,7 +106,6 @@ def test_plot_set_legend_invalid_fontsize(self, dict_color): with pytest.raises(ValueError): aa.plot_legend(ax=ax, dict_color=dict_color, fontsize=-5) - def test_plot_set_legend_invalid_marker_size(self, dict_color): """Test with negative 'marker_size'.""" fig, ax = plt.subplots() @@ -122,7 +113,6 @@ def test_plot_set_legend_invalid_marker_size(self, dict_color): with pytest.raises(ValueError): aa.plot_legend(ax=ax, dict_color=dict_color, marker_size=-10) - def test_plot_set_legend_color_and_category(self, dict_color): """Test 'dict_color' and 'list_cat' parameters together.""" fig, ax = plt.subplots() @@ -133,7 +123,6 @@ def test_plot_set_legend_color_and_category(self, dict_color): legend_texts = [text.get_text() for text in ax.get_legend().get_texts()] assert set(categories) == set(legend_texts) - def test_plot_set_legend_invalid_color_and_category(self, dict_color): """Test with invalid 'dict_color' and 'list_cat'.""" fig, ax = plt.subplots() @@ -143,7 +132,6 @@ def test_plot_set_legend_invalid_color_and_category(self, dict_color): with pytest.raises(ValueError): aa.plot_legend(ax=ax, dict_color=color_dict, list_cat=categories) - # Negative Test: check that if dict_color is not provided, it should raise an error def test_missing_dict_color(self): fig, ax = plt.subplots() @@ -151,7 +139,6 @@ def test_missing_dict_color(self): with pytest.raises(ValueError): aa.plot_legend(ax=ax, list_cat=['A']) - # Negative Test: check that if list_cat items are not in dict_color, it should raise an error @settings(max_examples=5, deadline=500) @given(random_cat=some.text()) @@ -159,8 +146,8 @@ def test_invalid_list_cat(self, random_cat): fig, ax = plt.subplots() ax.plot(range(5)) with pytest.raises(ValueError): - aa.plot_legend(ax=ax, dict_color={'A': 'red'}, list_cat=[random_cat]) - + if random_cat != "A": + aa.plot_legend(ax=ax, dict_color={'A': 'red'}, list_cat=[random_cat]) # II. Complex Cases Test Class @@ -176,14 +163,14 @@ def test_plot_set_legend_n_cols(self, n_cols): assert isinstance(result, plt.Axes) @settings(max_examples=5, deadline=500) - @given(st.lists(st.text(), min_size=1, max_size=5)) + @given(st.lists(st.text(), min_size=2, max_size=5)) def test_plot_set_legend_custom_labels(self, labels): fig, ax = plt.subplots() + labels = list(set(labels)) ax = aa.plot_legend(ax=ax, dict_color={label: "red" for label in labels}) legend_labels = [text.get_text() for text in ax.get_legend().get_texts()] assert set(legend_labels) == set(labels) - def test_handles_generation(self, dict_color): """Test handles based on dict_color and list_cat.""" ax = plt.gca() @@ -192,5 +179,3 @@ def test_handles_generation(self, dict_color): result = aa.plot_legend(ax=ax, dict_color=dict_color, list_cat=list_cat) assert isinstance(result, plt.Axes) - -