From 16c5649dd45183fc564e03ce4971a3d9254ba1d8 Mon Sep 17 00:00:00 2001
From: Matthew Andrew <matthew.andrew@tessella.com>
Date: Thu, 26 Mar 2020 13:31:26 +0000
Subject: [PATCH] Updated return value of remove_workspace_artists Re  #28434

This function returns a bool which was previously being used to indicate two separate things. The return values could mean:
  * False: Either the workspace does not exist on the axis or it does but the axis is not empty after its' removal.
  * True: Workspace exists and was removed and axis is now empty

This made the value not very useful for determining whether a call to remove_workspace_artists had removed anything. A grep of the code base returned that this return value was not currently being used anywhere except in MantidAxes.cpp where it was assumed to indicate whether anything had been removed. As you can easily check whether an axis is empty by other means I have changed the return value so that it indicates whether the call resulted in any change to the plot which is harder to divine by other means and brings this function in line with replace_workspace_artist.
---
 Framework/PythonInterface/mantid/plots/mantidaxes.py   |  4 ++--
 .../test/python/mantid/plots/plots__init__Test.py      | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/Framework/PythonInterface/mantid/plots/mantidaxes.py b/Framework/PythonInterface/mantid/plots/mantidaxes.py
index a9c7f4482fa..8ad76112806 100644
--- a/Framework/PythonInterface/mantid/plots/mantidaxes.py
+++ b/Framework/PythonInterface/mantid/plots/mantidaxes.py
@@ -285,7 +285,7 @@ class MantidAxes(Axes):
         Remove the artists reference by this workspace (if any) and return True
         if the axes is then empty
         :param workspace: A Workspace object
-        :return: True if the axes is empty, false if artists remain or this workspace is not associated here
+        :return: True is an artist was removed False if one was not
         """
         try:
             # pop to ensure we don't hold onto an artist reference
@@ -296,7 +296,7 @@ class MantidAxes(Axes):
         for workspace_artist in artist_info:
             workspace_artist.remove(self)
 
-        return self.is_empty(self)
+        return True
 
     def remove_artists_if(self, unary_predicate):
         """
diff --git a/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py b/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py
index 781ba2262e2..6f4b1d2c4d4 100644
--- a/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py
+++ b/Framework/PythonInterface/test/python/mantid/plots/plots__init__Test.py
@@ -76,14 +76,15 @@ class Plots__init__Test(unittest.TestCase):
 
     def test_remove_workspace_artist_for_known_workspace_removes_plot(self):
         self.ax.plot(self.ws2d_histo, specNum=2, linewidth=6)
-        is_empty = self.ax.remove_workspace_artists(self.ws2d_histo)
-        self.assertEqual(True, is_empty)
+        workspace_removed = self.ax.remove_workspace_artists(self.ws2d_histo)
+        self.assertEqual(True, workspace_removed)
         self.assertEqual(0, len(self.ax.lines))
 
     def test_remove_workspace_artist_for_unknown_workspace_does_nothing(self):
         self.ax.plot(self.ws2d_histo, specNum=2, linewidth=6)
         unknown_ws = CreateSampleWorkspace()
-        self.ax.remove_workspace_artists(unknown_ws)
+        workspace_removed  = self.ax.remove_workspace_artists(unknown_ws)
+        self.assertEqual(False, workspace_removed)
         self.assertEqual(1, len(self.ax.lines))
 
     def test_remove_workspace_artist_for_removes_only_specified_workspace(self):
@@ -92,7 +93,8 @@ class Plots__init__Test(unittest.TestCase):
         line_second_ws = self.ax.plot(second_ws, specNum=5)[0]
         self.assertEqual(2, len(self.ax.lines))
 
-        self.ax.remove_workspace_artists(self.ws2d_histo)
+        workspace_removed = self.ax.remove_workspace_artists(self.ws2d_histo)
+        self.assertEqual(True, workspace_removed)
         self.assertEqual(1, len(self.ax.lines))
         self.assertTrue(line_ws2d_histo not in self.ax.lines)
         self.assertTrue(line_second_ws in self.ax.lines)
-- 
GitLab