14
14
from pylsp .workspace import Document , Workspace
15
15
16
16
# Local imports
17
- from pylsp_black .plugin import load_config , pylsp_format_document , pylsp_format_range
17
+ from pylsp_black .plugin import (
18
+ _load_config ,
19
+ load_config ,
20
+ pylsp_format_document ,
21
+ pylsp_format_range ,
22
+ )
18
23
19
24
here = Path (__file__ ).parent
20
25
fixtures_dir = here / "fixtures"
@@ -30,7 +35,9 @@ def workspace(tmpdir):
30
35
def config (workspace ):
31
36
"""Return a config object."""
32
37
cfg = Config (workspace .root_uri , {}, 0 , {})
33
- cfg ._plugin_settings = {"plugins" : {"black" : {"line_length" : 88 }}}
38
+ cfg ._plugin_settings = {
39
+ "plugins" : {"black" : {"line_length" : 88 }, "black" : {"cache_config" : True }}
40
+ }
34
41
return cfg
35
42
36
43
@@ -301,3 +308,19 @@ def test_pylsp_format_line_length(
301
308
"newText" : formatted_line_length .source ,
302
309
}
303
310
]
311
+
312
+
313
+ def test_cache_config (config , unformatted_document ):
314
+ # Cache should be working by default
315
+ for _ in range (5 ):
316
+ pylsp_format_document (config , unformatted_document )
317
+ assert _load_config .cache_info ().hits == 4
318
+
319
+ # Clear cache and disable it
320
+ _load_config .cache_clear ()
321
+ config .update ({"plugins" : {"black" : {"cache_config" : False }}})
322
+
323
+ # Cache should not be working now
324
+ for _ in range (5 ):
325
+ pylsp_format_document (config , unformatted_document )
326
+ assert _load_config .cache_info ().hits == 0
0 commit comments