From 2737647dc8bec5b1cef61b752ba74233048f48bd Mon Sep 17 00:00:00 2001 From: MialLewis <95620982+MialLewis@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:42:07 +0100 Subject: [PATCH] extend tests to check return of vars --- src/mslice/scripting/helperfunctions.py | 4 ++-- tests/scripting_helperfunctions_test.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/mslice/scripting/helperfunctions.py b/src/mslice/scripting/helperfunctions.py index 563c73f6..22035e66 100644 --- a/src/mslice/scripting/helperfunctions.py +++ b/src/mslice/scripting/helperfunctions.py @@ -140,9 +140,9 @@ def add_cut_lines(script_lines, plot_handler, ax): cuts = plot_handler._cut_plotter_presenter._cut_cache_dict[ax] errorbars = plot_handler._canvas.figure.gca().containers intensity_correction = plot_handler.intensity_type - return_cut_vars = add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction) + return_ws_vars = add_cut_lines_with_width(errorbars, script_lines, cuts, intensity_correction) hide_lines(script_lines, plot_handler, ax) - return return_cut_vars + return return_ws_vars def hide_lines(script_lines, plot_handler, ax): diff --git a/tests/scripting_helperfunctions_test.py b/tests/scripting_helperfunctions_test.py index 56cf216a..b4c140f1 100644 --- a/tests/scripting_helperfunctions_test.py +++ b/tests/scripting_helperfunctions_test.py @@ -233,7 +233,9 @@ def test_that_add_cut_plot_statements_works_as_expected(self, gfm, add_cut_lines fig = mock.MagicMock() ax = fig.add_subplot(111, projection='mslice') - add_cut_plot_statements(script_lines, plot_handler, ax) + add_cut_lines.return_value = ['test_ws_var'] + + ret_val = add_cut_plot_statements(script_lines, plot_handler, ax) add_cut_lines.assert_called_once_with(script_lines, plot_handler, ax) add_plot_options.assert_called_once_with(script_lines, plot_handler) @@ -242,6 +244,7 @@ def test_that_add_cut_plot_statements_works_as_expected(self, gfm, add_cut_lines plot_handler.x_axis_min), script_lines) self.assertIn("ax.set_yscale('symlog', linthresh=pow(10, np.floor(np.log10({}))))\n".format( plot_handler.y_axis_min), script_lines) + self.assertEqual(['test_ws_var'], ret_val) @mock.patch('mslice.scripting.helperfunctions.add_cut_lines_with_width') @mock.patch('mslice.cli._mslice_commands.GlobalFigureManager') @@ -253,14 +256,17 @@ def test_that_add_cut_lines_works_as_expected(self, gfm, add_cut_lines_with_widt plot_handler.add_mock_spec(CutPlot) plot_handler.intensity_type = IntensityType.SCATTERING_FUNCTION + add_cut_lines_with_width.return_value = ['test_ws_var'] + script_lines = [] - add_cut_lines(script_lines, plot_handler, ax) + ret_val = add_cut_lines(script_lines, plot_handler, ax) cuts = plot_handler._cut_plotter_presenter._cut_cache_dict[ax] errorbars = plot_handler._canvas.figure.gca().containers add_cut_lines_with_width.assert_called_once_with(errorbars, script_lines, cuts, plot_handler.intensity_type) + self.assertEqual(['test_ws_var'], ret_val) @mock.patch('mslice.cli._mslice_commands.GlobalFigureManager') def test_that_add_plot_options_works_as_expected(self, gfm): @@ -307,7 +313,8 @@ def test_that_add_cut_lines_with_width_works_as_expected_without_intensity_range cuts = [cut] script_lines = [] - add_cut_lines_with_width(errorbars, script_lines, cuts, IntensityType.SCATTERING_FUNCTION) + ret_val = add_cut_lines_with_width(errorbars, script_lines, cuts, IntensityType.SCATTERING_FUNCTION) + pass self.assertIn( 'cut_ws_{} = mc.Cut(ws_{}, CutAxis="{}", IntegrationAxis="{}", NormToOne={}, IntensityCorrection={}, ' @@ -318,6 +325,8 @@ def test_that_add_cut_lines_with_width_works_as_expected_without_intensity_range 'ax.errorbar(cut_ws_{}, label="{}", color="{}", marker="{}", ls="{}", lw={}, plot_over={})\n\n'.format( 0, 'errorbar_label', 'blue', None, '-', 1.5, False), script_lines) + self.assertEqual(['cut_ws_0'], ret_val) + def test_that_add_cut_lines_with_width_works_as_expected_with_intensity_range(self): x_data, y_data = np.arange(0, 10), np.arange(0, 10) plt.errorbar(x_data, y_data, linestyle='-', linewidth=1.5, color='blue', label='errorbar_label') @@ -328,12 +337,13 @@ def test_that_add_cut_lines_with_width_works_as_expected_with_intensity_range(se cuts = [cut] script_lines = [] - add_cut_lines_with_width(errorbars, script_lines, cuts, IntensityType.SCATTERING_FUNCTION) + ret_val = add_cut_lines_with_width(errorbars, script_lines, cuts, IntensityType.SCATTERING_FUNCTION) self.assertIn( 'ax.errorbar(cut_ws_{}, label="{}", color="{}", marker="{}", ls="{}", lw={}, ' 'intensity_range={}, plot_over={})\n\n'.format(0, 'errorbar_label', 'blue', None, '-', 1.5, (1.0, 2.0), False), script_lines) + self.assertEqual(['cut_ws_0'], ret_val) def test_that_add_cut_lines_with_width_works_as_expected_with_multiple_cuts(self): x_data, y_data = np.arange(0, 10), np.arange(0, 10) @@ -349,7 +359,7 @@ def test_that_add_cut_lines_with_width_works_as_expected_with_multiple_cuts(self cuts = [cut_0, cut_2] script_lines = [] - add_cut_lines_with_width(errorbars, script_lines, cuts, IntensityType.SCATTERING_FUNCTION) + ret_val = add_cut_lines_with_width(errorbars, script_lines, cuts, IntensityType.SCATTERING_FUNCTION) self.assertIn( 'cut_ws_{} = mc.Cut(ws_{}, CutAxis="{}", IntegrationAxis="{}", NormToOne={}, IntensityCorrection={}, ' @@ -381,6 +391,8 @@ def test_that_add_cut_lines_with_width_works_as_expected_with_multiple_cuts(self 'intensity_range={}, plot_over={})\n\n'.format(2, 'error_label_2', 'blue', None, '-', 1.5, (1.0, 2.0), True), script_lines) + self.assertEqual(['cut_ws_0', 'cut_ws_1', 'cut_ws_2'], ret_val) + def test_show_or_hide_containers_in_script(self): fig, ax = plt.subplots() ax.errorbar([1], [2], [0.3], label="label1")