@@ -9,7 +9,7 @@ class TestPlot(unittest.TestCase):
99 def test_plot (self , mock_plt ):
1010 # Arrange
1111 x_values = np .array ([1 , 2 , 3 , 4 , 5 ])
12- y_values = np .array ([1 , 2 , 3 , 4 , 5 ])
12+ means = np .array ([1 , 2 , 3 , 4 , 5 ])
1313 upper_bands = np .array ([2 , 3 , 4 , 5 , 6 ])
1414 lower_bands = np .array ([0 , 1 , 2 , 3 , 4 ])
1515 mock_ax = MagicMock ()
@@ -18,12 +18,13 @@ def test_plot(self, mock_plt):
1818 # Act
1919 result_ax = plot (
2020 x_values ,
21- y_values ,
22- upper_bands ,
21+ means ,
2322 lower_bands ,
23+ upper_bands ,
2424 title = "Test Title" ,
2525 xlabel = "X Axis" ,
2626 ylabel = "Y Axis" ,
27+ chart_type = "line" ,
2728 )
2829
2930 # Assert
@@ -34,7 +35,7 @@ def test_plot(self, mock_plt):
3435 plot_args , plot_kwargs = plot_call
3536 x_values_arg , y_values_arg = plot_args
3637 self .assertTrue (np .array_equal (x_values_arg , x_values ))
37- self .assertTrue (np .array_equal (y_values_arg , y_values ))
38+ self .assertTrue (np .array_equal (y_values_arg , means ))
3839 fill_between_args , fill_between_kwargs = fill_between_call
3940 x_fill , lower_fill , upper_fill = fill_between_args
4041 self .assertTrue (np .array_equal (x_fill , x_values_arg ))
@@ -46,8 +47,30 @@ def test_plot(self, mock_plt):
4647 mock_ax .set_title .assert_called_once_with ("Test Title" )
4748 mock_ax .set_xlabel .assert_called_once_with ("X Axis" )
4849 mock_ax .set_ylabel .assert_called_once_with ("Y Axis" )
49- mock_ax .legend .assert_called_once ()
5050
51+ def test_plot_fail_unknown_chart_type (self ):
52+ # Arrange
53+ x_values = np .array ([1 , 2 , 3 , 4 , 5 ])
54+ means = np .array ([1 , 2 , 3 , 4 , 5 ])
55+ upper_bands = np .array ([2 , 3 , 4 , 5 , 6 ])
56+ lower_bands = np .array ([0 , 1 , 2 , 3 , 4 ])
57+
58+ # Act, Assert
59+ with self .assertRaises (ValueError ) as cm :
60+ plot (
61+ x_values ,
62+ means ,
63+ lower_bands ,
64+ upper_bands ,
65+ title = "Test Title" ,
66+ xlabel = "X Axis" ,
67+ ylabel = "Y Axis" ,
68+ chart_type = "other" ,
69+ )
70+ self .assertEqual (
71+ str (cm .exception ),
72+ "Chart type other is not supported" ,
73+ )
5174
5275if __name__ == "__main__" :
5376 unittest .main ()
0 commit comments