mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-20983 (partial fix): do not break if python target is module.
This fix is critical anyway, because running module as python is common
This commit is contained in:
@@ -292,6 +292,11 @@ data class ConfigurationTarget(@ConfigField var target: String, @ConfigField var
|
||||
val fileSystemPartOfTarget = (if (workingDir != null) VfsUtil.getRelativePath(elementFile, workingDir) else null)
|
||||
?: elementFile.path
|
||||
|
||||
if (pyTarget.componentCount == 0) {
|
||||
// If python part is empty we are launching file. To prevent junk like "foo.py::" we run it as file instead
|
||||
return listOf("--path", fileSystemPartOfTarget)
|
||||
}
|
||||
|
||||
return listOf("--target", "$fileSystemPartOfTarget::$pyTarget")
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
A = 1
|
||||
@@ -0,0 +1,9 @@
|
||||
import unittest
|
||||
|
||||
from .stubs import A
|
||||
|
||||
class TestSomeClass(unittest.TestCase):
|
||||
def test_some_class(self):
|
||||
some_class = A
|
||||
pass
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.python.testing.CreateConfigurationTestTask.PyConfigurationCreationTask;
|
||||
import com.jetbrains.env.ut.PyNoseTestProcessRunner;
|
||||
import com.jetbrains.env.ut.PyUnitTestProcessRunner;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import com.jetbrains.python.testing.PythonTestConfigurationsModel;
|
||||
import com.jetbrains.python.testing.universalTests.PyUniversalNoseTestConfiguration;
|
||||
@@ -36,6 +37,20 @@ public final class PythonNoseTestingTest extends PyEnvTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that python target pointing to module works correctly
|
||||
*/
|
||||
@Test
|
||||
public void testRunModuleAsFile() throws Exception {
|
||||
runPythonTest(new RunModuleAsFileTask<PyNoseTestProcessRunner>(){
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyNoseTestProcessRunner createProcessRunner() throws Exception {
|
||||
return new PyNoseTestProcessRunner(TARGET, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRerunSubfolder() throws Exception {
|
||||
runPythonTest(new RerunSubfolderTask<PyNoseTestProcessRunner>(2) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.intellij.util.PathUtil;
|
||||
import com.jetbrains.env.EnvTestTagsRequired;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.ut.PyNoseTestProcessRunner;
|
||||
import com.jetbrains.env.ut.PyTestTestProcessRunner;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
@@ -50,6 +51,21 @@ public final class PythonPyTestingTest extends PyEnvTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that python target pointing to module works correctly
|
||||
*/
|
||||
@Test
|
||||
public void testRunModuleAsFile() throws Exception {
|
||||
runPythonTest(new RunModuleAsFileTask<PyTestTestProcessRunner>(){
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyTestTestProcessRunner createProcessRunner() throws Exception {
|
||||
return new PyTestTestProcessRunner(TARGET, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRerunSubfolder() throws Exception {
|
||||
runPythonTest(new RerunSubfolderTask<PyTestTestProcessRunner>(2) {
|
||||
|
||||
+19
-3
@@ -23,8 +23,8 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.jetbrains.env.EnvTestTagsRequired;
|
||||
import com.jetbrains.env.ProcessWithConsoleRunner;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.ut.PyScriptTestProcessRunner;
|
||||
import com.jetbrains.env.ut.PyUnitTestProcessRunner;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
@@ -39,6 +39,7 @@ import org.junit.Test;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.jetbrains.env.ut.PyScriptTestProcessRunner.TEST_TARGET_PREFIX;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -59,6 +60,21 @@ public final class PythonUnitTestingTest extends PyEnvTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensures that python target pointing to module works correctly
|
||||
*/
|
||||
@Test
|
||||
public void testRunModuleAsFile() throws Exception {
|
||||
runPythonTest(new RunModuleAsFileTask<PyUnitTestProcessRunner>(){
|
||||
@NotNull
|
||||
@Override
|
||||
protected PyUnitTestProcessRunner createProcessRunner() throws Exception {
|
||||
return new PyUnitTestProcessRunner(TARGET, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRerunSubfolder() throws Exception {
|
||||
runPythonTest(new RerunSubfolderTask<PyUnitTestProcessRunner>(1) {
|
||||
@@ -443,7 +459,7 @@ public final class PythonUnitTestingTest extends PyEnvTestCase {
|
||||
@Test
|
||||
public void testClass() {
|
||||
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("/testRunner/env/unit",
|
||||
PyScriptTestProcessRunner.TEST_TARGET_PREFIX + "test_file.GoodTest") {
|
||||
TEST_TARGET_PREFIX + "test_file.GoodTest") {
|
||||
|
||||
@Override
|
||||
protected void checkTestResults(@NotNull final PyUnitTestProcessRunner runner,
|
||||
@@ -459,7 +475,7 @@ public final class PythonUnitTestingTest extends PyEnvTestCase {
|
||||
@Test
|
||||
public void testMethod() {
|
||||
runPythonTest(new PyUnitTestProcessWithConsoleTestTask("/testRunner/env/unit",
|
||||
PyScriptTestProcessRunner.TEST_TARGET_PREFIX +
|
||||
TEST_TARGET_PREFIX +
|
||||
"test_file.GoodTest.test_passes") {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.env.python.testing;
|
||||
|
||||
import com.jetbrains.env.PyAbstractTestProcessRunner;
|
||||
import com.jetbrains.env.PyProcessWithConsoleTestTask;
|
||||
import com.jetbrains.env.ut.PyScriptTestProcessRunner;
|
||||
import com.jetbrains.env.ut.PyUnitTestProcessRunner;
|
||||
import com.jetbrains.python.run.PythonProcessRunner;
|
||||
import com.jetbrains.python.sdkTools.SdkCreationType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Ensures that python target pointing to module works correctly
|
||||
* @author Ilya.Kazakevich
|
||||
*/
|
||||
abstract class RunModuleAsFileTask<T extends PyAbstractTestProcessRunner<?>> extends PyProcessWithConsoleTestTask<T> {
|
||||
|
||||
protected static final String TARGET = PyScriptTestProcessRunner.TEST_TARGET_PREFIX + "test_some_class";
|
||||
|
||||
RunModuleAsFileTask() {
|
||||
super("testRunner/env/runModuleAsFile", SdkCreationType.SDK_PACKAGES_ONLY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected final void checkTestResults(@NotNull final T runner,
|
||||
@NotNull final String stdout,
|
||||
@NotNull final String stderr,
|
||||
@NotNull final String all) {
|
||||
Assert.assertEquals(stderr, 1, runner.getAllTestsCount());
|
||||
Assert.assertEquals(stderr, 1, runner.getPassedTestsCount());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user