Skip to content

Commit

Permalink
Revert "sometimes things dont need to make sense"
Browse files Browse the repository at this point in the history
This reverts commit f9bab9f.
  • Loading branch information
predragnikolic committed Apr 7, 2024
1 parent f9bab9f commit ea47498
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions tests/test_configurations.py
Original file line number Diff line number Diff line change
@@ -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(), {})
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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)))

0 comments on commit ea47498

Please sign in to comment.