diff --git a/tests/test_configurations.py b/tests/test_configurations.py index 533c12229..93af0a0ef 100644 --- a/tests/test_configurations.py +++ b/tests/test_configurations.py @@ -1,13 +1,12 @@ from LSP.plugin.core.configurations import WindowConfigManager from test_mocks import DISABLED_CONFIG from test_mocks import TEST_CONFIG -from unittest import TestCase from unittest.mock import MagicMock -from unittesting import ViewTestCase import sublime +import unittest -class GlobalConfigManagerTests(TestCase): +class GlobalConfigManagerTests(unittest.TestCase): def test_empty_configs(self): window_mgr = WindowConfigManager(sublime.active_window(), {}) @@ -25,29 +24,35 @@ def test_override_config(self): self.assertFalse(list(window_mgr.all.values())[0].enabled) -class WindowConfigManagerTests(ViewTestCase): +class WindowConfigManagerTests(unittest.TestCase): def test_no_configs(self): - self.assertIsNotNone(self.view) - self.assertIsNotNone(self.window) - manager = WindowConfigManager(self.window, {}) - self.assertEqual(list(manager.match_view(self.view)), []) + view = sublime.active_window().active_view() + self.assertIsNotNone(view) + assert view + manager = WindowConfigManager(sublime.active_window(), {}) + self.assertEqual(list(manager.match_view(view)), []) def test_with_single_config(self): - self.assertIsNotNone(self.view) - self.assertIsNotNone(self.window) - manager = WindowConfigManager(self.window, {TEST_CONFIG.name: TEST_CONFIG}) - self.view.syntax = MagicMock(return_value=sublime.Syntax( + window = sublime.active_window() + view = window.active_view() + self.assertIsNotNone(view) + assert view + manager = WindowConfigManager(window, {TEST_CONFIG.name: TEST_CONFIG}) + view.syntax = MagicMock(return_value=sublime.Syntax( path="Packages/Text/Plain text.tmLanguage", name="Plain Text", scope="text.plain", hidden=False )) - self.view.settings().set("lsp_uri", "file:///foo/bar.txt") - self.assertEqual(list(manager.match_view(self.view)), [TEST_CONFIG]) + view.settings().set("lsp_uri", "file:///foo/bar.txt") + self.assertEqual(list(manager.match_view(view)), [TEST_CONFIG]) def test_applies_project_settings(self): - self.window.project_data = MagicMock(return_value={ + window = sublime.active_window() + view = window.active_view() + assert view + window.project_data = MagicMock(return_value={ "settings": { "LSP": { "test": { @@ -56,22 +61,24 @@ def test_applies_project_settings(self): } } }) - manager = WindowConfigManager(self.window, {DISABLED_CONFIG.name: DISABLED_CONFIG}) - self.view.syntax = MagicMock(return_value=sublime.Syntax( + manager = WindowConfigManager(window, {DISABLED_CONFIG.name: DISABLED_CONFIG}) + view.syntax = MagicMock(return_value=sublime.Syntax( path="Packages/Text/Plain text.tmLanguage", name="Plain Text", scope="text.plain", hidden=False )) - self.view.settings().set("lsp_uri", "file:///foo/bar.txt") - configs = list(manager.match_view(self.view)) + view.settings().set("lsp_uri", "file:///foo/bar.txt") + configs = list(manager.match_view(view)) self.assertEqual(len(configs), 1) config = configs[0] self.assertEqual(DISABLED_CONFIG.name, config.name) self.assertTrue(config.enabled) def test_disables_temporarily(self): - self.window.project_data = MagicMock(return_value={ + window = sublime.active_window() + view = window.active_view() + window.project_data = MagicMock(return_value={ "settings": { "LSP": { "test": { @@ -81,7 +88,7 @@ def test_disables_temporarily(self): } }) - manager = WindowConfigManager(self.window, {DISABLED_CONFIG.name: DISABLED_CONFIG}) + manager = WindowConfigManager(window, {DISABLED_CONFIG.name: DISABLED_CONFIG}) # disables config in-memory manager.disable_config(DISABLED_CONFIG.name, only_for_session=True) - self.assertFalse(any(manager.match_view(self.view))) + self.assertFalse(any(manager.match_view(view)))