From 19c251b3320ce716072dd6ba6573c1c46bffdb2b Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Wed, 14 May 2014 15:08:50 +0400 Subject: [PATCH] fixed PY-12313 Incorrect __file__ value when running tests in a folder on Windows --- .../attest/PythonAtTestCommandLineState.java | 18 +++++++++++------- .../PythonNoseTestCommandLineState.java | 12 +++++++----- .../PythonUnitTestCommandLineState.java | 5 +++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java b/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java index b74d562bad5e..0770a1737012 100644 --- a/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/attest/PythonAtTestCommandLineState.java @@ -16,6 +16,7 @@ package com.jetbrains.python.testing.attest; import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.openapi.util.io.FileUtil; import com.jetbrains.python.testing.PythonTestCommandLineStateBase; import java.util.ArrayList; @@ -41,24 +42,27 @@ public class PythonAtTestCommandLineState extends PythonTestCommandLineStateBase protected List getTestSpecs() { List specs = new ArrayList(); + final String scriptName = FileUtil.toSystemDependentName(myConfig.getScriptName()); switch (myConfig.getTestType()) { case TEST_SCRIPT: - specs.add(myConfig.getScriptName()); + specs.add(scriptName); break; case TEST_CLASS: - specs.add(myConfig.getScriptName() + "::" + myConfig.getClassName()); + specs.add(scriptName + "::" + myConfig.getClassName()); break; case TEST_METHOD: - specs.add(myConfig.getScriptName() + "::" + myConfig.getClassName() + "::" + myConfig.getMethodName()); + specs.add(scriptName + "::" + myConfig.getClassName() + "::" + myConfig.getMethodName()); break; case TEST_FOLDER: - if (!myConfig.getPattern().isEmpty()) - specs.add(myConfig.getFolderName() + "/" + ";" + myConfig.getPattern()); + final String folderName = FileUtil.toSystemDependentName(myConfig.getFolderName() + "/"); + if (!myConfig.getPattern().isEmpty()) { + specs.add(folderName + ";" + myConfig.getPattern()); + } else - specs.add(myConfig.getFolderName() + "/"); + specs.add(folderName); break; case TEST_FUNCTION: - specs.add(myConfig.getScriptName() + "::::" + myConfig.getMethodName()); + specs.add(scriptName + "::::" + myConfig.getMethodName()); break; default: throw new IllegalArgumentException("Unknown test type: " + myConfig.getTestType()); diff --git a/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java b/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java index 80e36e22cc43..4d94ddf41986 100644 --- a/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/nosetest/PythonNoseTestCommandLineState.java @@ -19,6 +19,7 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.configurations.ParamsGroup; import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.jetbrains.python.testing.PythonTestCommandLineStateBase; @@ -45,21 +46,22 @@ public class PythonNoseTestCommandLineState extends PythonTestCommandLineStateBa protected List getTestSpecs() { List specs = new ArrayList(); + final String scriptName = FileUtil.toSystemDependentName(myConfig.getScriptName()); switch (myConfig.getTestType()) { case TEST_SCRIPT: - specs.add(myConfig.getScriptName()); + specs.add(scriptName); break; case TEST_CLASS: - specs.add(myConfig.getScriptName() + "::" + myConfig.getClassName()); + specs.add(scriptName + "::" + myConfig.getClassName()); break; case TEST_METHOD: - specs.add(myConfig.getScriptName() + "::" + myConfig.getClassName() + "::" + myConfig.getMethodName()); + specs.add(scriptName + "::" + myConfig.getClassName() + "::" + myConfig.getMethodName()); break; case TEST_FOLDER: - specs.add(myConfig.getFolderName() + "/"); + specs.add(FileUtil.toSystemDependentName(myConfig.getFolderName() + "/")); break; case TEST_FUNCTION: - specs.add(myConfig.getScriptName() + "::::" + myConfig.getMethodName()); + specs.add(scriptName + "::::" + myConfig.getMethodName()); break; default: throw new IllegalArgumentException("Unknown test type: " + myConfig.getTestType()); diff --git a/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java b/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java index 4d94d36cf2b3..c3fb85bf4025 100644 --- a/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java +++ b/python/src/com/jetbrains/python/testing/unittest/PythonUnitTestCommandLineState.java @@ -65,11 +65,12 @@ public class PythonUnitTestCommandLineState extends specs.add(scriptName + "::" + myConfig.getClassName() + "::" + myConfig.getMethodName()); break; case TEST_FOLDER: + final String folderName = FileUtil.toSystemDependentName(myConfig.getFolderName() + "/"); if (!StringUtil.isEmpty(myConfig.getPattern()) && myConfig.usePattern()) { - specs.add(myConfig.getFolderName() + "/" + ";" + myConfig.getPattern()); + specs.add(folderName + ";" + myConfig.getPattern()); } else { - specs.add(myConfig.getFolderName() + "/"); + specs.add(folderName); } break; case TEST_FUNCTION: