Last active
February 6, 2020 22:45
-
-
Save bstaletic/90f76428a401055744d14de89607bed8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ycmd/tests/java/conftest.py b/ycmd/tests/java/conftest.py | |
index fdb3ff4f..0e3edc52 100644 | |
--- a/ycmd/tests/java/conftest.py | |
+++ b/ycmd/tests/java/conftest.py | |
@@ -15,6 +15,7 @@ | |
# You should have received a copy of the GNU General Public License | |
# along with ycmd. If not, see <http://www.gnu.org/licenses/>. | |
+import contextlib | |
import os | |
import pytest | |
import shutil | |
@@ -24,6 +25,7 @@ from ycmd.tests.test_utils import ( BuildRequest, | |
IsolatedApp, | |
SetUpApp, | |
StopCompleterServer, | |
+ TemporaryTestDir, | |
WaitUntilCompleterServerReady ) | |
shared_app = None | |
SERVER_STARTUP_TIMEOUT = 120 # seconds | |
@@ -64,14 +66,15 @@ def app( request ): | |
assert which == 'isolated' or which == 'shared' | |
if which == 'isolated': | |
custom_options = request.param[ 1 ] | |
- wipe_ws_dir = custom_options.get( 'java_jdtls_workspace_root_path', None ) | |
- with IsolatedApp( custom_options ) as app: | |
- try: | |
- yield app | |
- finally: | |
- StopCompleterServer( app, 'java' ) | |
- if wipe_ws_dir: | |
- shutil.rmtree( wipe_ws_dir ) | |
+ create_dir = request.param[ 2 ] | |
+ with contextlib.ExitStack() as stack: | |
+ tmp_dir = stack.enter_context( TemporaryTestDir() ) if create_dir else '' | |
+ custom_options[ 'java_jdtls_workspace_root_path' ] = tmp_dir | |
+ with IsolatedApp( custom_options ) as app: | |
+ try: | |
+ yield app | |
+ finally: | |
+ StopCompleterServer( app, 'java' ) | |
else: | |
global shared_app | |
ClearCompletionsCache() | |
@@ -93,7 +96,7 @@ SharedYcmd = pytest.mark.parametrize( | |
indirect = True ) | |
-def IsolatedYcmd( custom_options = {} ): | |
+def IsolatedYcmd( custom_options = {}, tmp_dir = False ): | |
"""Defines a decorator to be attached to tests of this package. This decorator | |
passes a unique ycmd application as a parameter. It should be used on tests | |
that change the server state in a irreversible way (ex: a semantic subserver | |
@@ -113,7 +116,7 @@ def IsolatedYcmd( custom_options = {} ): | |
# Name of the fixture/function argument | |
'app', | |
# Fixture parameters, passed to app() as request.param | |
- [ ( 'isolated', custom_options ) ], | |
+ [ ( 'isolated', custom_options, tmp_dir ) ], | |
# Non-empty ids makes fixture parameters visible in pytest verbose output | |
ids = [ '' ], | |
# Execute the fixture, instead of passing parameters directly to the | |
diff --git a/ycmd/tests/java/server_management_test.py b/ycmd/tests/java/server_management_test.py | |
index 45c8bca1..00cd2683 100644 | |
--- a/ycmd/tests/java/server_management_test.py | |
+++ b/ycmd/tests/java/server_management_test.py | |
@@ -110,11 +110,7 @@ def ServerManagement_RestartServer_test( app ): | |
CompleterProjectDirectoryMatcher( maven_project ) ) | |
-# NOTE: TemporaryTestDir() makes no sense outside of a function. | |
-@IsolatedYcmd( { | |
- 'java_jdtls_use_clean_workspace': 1, | |
- 'java_jdtls_workspace_root_path': tempfile.mkdtemp() | |
-} ) | |
+@IsolatedYcmd( { 'java_jdtls_use_clean_workspace': 1, }, True ) | |
def ServerManagement_WipeWorkspace_NoConfig_test( app ): | |
StartJavaCompleterServerInDirectory( | |
app, PathToTestFile( 'simple_eclipse_project', 'src' ) ) | |
@@ -144,11 +140,7 @@ def ServerManagement_WipeWorkspace_NoConfig_test( app ): | |
CompleterProjectDirectoryMatcher( project ) ) | |
-# NOTE: TemporaryTestDir() makes no sense outside of a function. | |
-@IsolatedYcmd( { | |
- 'java_jdtls_use_clean_workspace': 1, | |
- 'java_jdtls_workspace_root_path': tempfile.mkdtemp() | |
-} ) | |
+@IsolatedYcmd( { 'java_jdtls_use_clean_workspace': 1, }, True ) | |
def ServerManagement_WipeWorkspace_WithConfig_test( app ): | |
StartJavaCompleterServerInDirectory( | |
app, PathToTestFile( 'simple_eclipse_project', 'src' ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment