diff --git a/plugin/utils/output_panel_handler.py b/plugin/utils/output_panel_handler.py index 3b6246d3..a3320000 100644 --- a/plugin/utils/output_panel_handler.py +++ b/plugin/utils/output_panel_handler.py @@ -1,26 +1,28 @@ """Handle everything related to the output panel.""" +import time import sublime class OutputPanelHandler(): """Handle the output panel.""" - _PANEL_TAG = "ECC" + PANEL_TAG = "ECC" + PANEL_NAME = "output." + PANEL_TAG @staticmethod def hide_panel(): """Hide the output panel.""" window = sublime.active_window() - window.run_command( - "hide_panel", {"panel": "output." + OutputPanelHandler._PANEL_TAG}) + if window.active_panel() == OutputPanelHandler.PANEL_NAME: + window.run_command( + "hide_panel", {"panel": OutputPanelHandler.PANEL_NAME}) @staticmethod def show(text): """Show the panel with text.""" - import time window = sublime.active_window() - window.destroy_output_panel(OutputPanelHandler._PANEL_TAG) + window.destroy_output_panel(OutputPanelHandler.PANEL_TAG) panel_view = window.create_output_panel( - OutputPanelHandler._PANEL_TAG) + OutputPanelHandler.PANEL_TAG) while panel_view.is_loading(): time.sleep(0.1) panel_view.run_command("select_all") @@ -34,5 +36,5 @@ def show(text): panel_view.show(panel_view.size()) window.run_command( - "show_panel", {"panel": "output." + OutputPanelHandler._PANEL_TAG}) + "show_panel", {"panel": OutputPanelHandler.PANEL_NAME}) panel_view.set_read_only(True) diff --git a/tests/test_bazel.py b/tests/test_bazel.py index f0fe8601..d47526a7 100644 --- a/tests/test_bazel.py +++ b/tests/test_bazel.py @@ -98,7 +98,7 @@ def test_bad_project(self): future = MockFuture(output) Bazel.compdb_generated(future) window = sublime.active_window() - panel_view = window.find_output_panel(OutputPanelHandler._PANEL_TAG) + panel_view = window.find_output_panel(OutputPanelHandler.PANEL_TAG) panel_content = panel_view.substr(sublime.Region(0, panel_view.size())) split_output = output.split('\n') split_panel_content = panel_content.split('\n') diff --git a/tests/test_output_panel_handler.py b/tests/test_output_panel_handler.py index b4fe1701..e4160c24 100644 --- a/tests/test_output_panel_handler.py +++ b/tests/test_output_panel_handler.py @@ -3,8 +3,9 @@ from EasyClangComplete.plugin.utils import output_panel_handler from unittest import TestCase -import sublime +import time import imp +import sublime imp.reload(output_panel_handler) @@ -24,15 +25,34 @@ def test_panel_creation(self): OutputPanelHandler.show("hello world") window = sublime.active_window() self.assertIsNotNone(window.active_panel()) - self.assertEquals(window.active_panel(), "output.ECC") - panel_view = window.find_output_panel(OutputPanelHandler._PANEL_TAG) + self.assertEqual(window.active_panel(), OutputPanelHandler.PANEL_NAME) + panel_view = window.find_output_panel(OutputPanelHandler.PANEL_TAG) contents = panel_view.substr(sublime.Region(0, panel_view.size())) - self.assertEquals(contents, "hello world") + self.assertEqual(contents, "hello world") def test_panel_closing(self): """Test that we can close a panel.""" OutputPanelHandler.show("hello world") window = sublime.active_window() - self.assertEquals(window.active_panel(), "output.ECC") + self.assertEqual(window.active_panel(), OutputPanelHandler.PANEL_NAME) OutputPanelHandler.hide_panel() self.assertIsNone(window.active_panel()) + + def test_not_closing_panel(self): + """Test that we don't close a panel with a wrong name.""" + window = sublime.active_window() + test_panel_name = "test_panel" + panel_view = window.create_output_panel(test_panel_name) + while panel_view.is_loading(): + time.sleep(0.1) + if not window.active_panel(): + # We cannot initialize a panel probably because of a CI quirk. + return + self.assertIsNotNone(window.active_panel()) + self.assertNotEqual(window.active_panel(), + OutputPanelHandler.PANEL_NAME) + OutputPanelHandler.hide_panel() + self.assertIsNotNone(window.active_panel()) + self.assertNotEqual(window.active_panel(), + OutputPanelHandler.PANEL_NAME) + window.destroy_output_panel(test_panel_name)