diff --git a/python/src/com/jetbrains/python/testing/universalTests/PyUniversalTests.kt b/python/src/com/jetbrains/python/testing/universalTests/PyUniversalTests.kt index a086188889a8..737262664aca 100644 --- a/python/src/com/jetbrains/python/testing/universalTests/PyUniversalTests.kt +++ b/python/src/com/jetbrains/python/testing/universalTests/PyUniversalTests.kt @@ -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") } diff --git a/python/testData/testRunner/env/runModuleAsFile/unittests/__init__.py b/python/testData/testRunner/env/runModuleAsFile/unittests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/testData/testRunner/env/runModuleAsFile/unittests/stubs.py b/python/testData/testRunner/env/runModuleAsFile/unittests/stubs.py new file mode 100644 index 000000000000..2946e5875b87 --- /dev/null +++ b/python/testData/testRunner/env/runModuleAsFile/unittests/stubs.py @@ -0,0 +1 @@ +A = 1 \ No newline at end of file diff --git a/python/testData/testRunner/env/runModuleAsFile/unittests/test_some_class.py b/python/testData/testRunner/env/runModuleAsFile/unittests/test_some_class.py new file mode 100644 index 000000000000..25f057af691c --- /dev/null +++ b/python/testData/testRunner/env/runModuleAsFile/unittests/test_some_class.py @@ -0,0 +1,9 @@ +import unittest + +from .stubs import A + +class TestSomeClass(unittest.TestCase): + def test_some_class(self): + some_class = A + pass + \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonNoseTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonNoseTestingTest.java index ff5a5b217346..f400c846161b 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonNoseTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonNoseTestingTest.java @@ -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(){ + @NotNull + @Override + protected PyNoseTestProcessRunner createProcessRunner() throws Exception { + return new PyNoseTestProcessRunner(TARGET, 0); + } + }); + } + @Test public void testRerunSubfolder() throws Exception { runPythonTest(new RerunSubfolderTask(2) { diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java index e142f99d4d68..f9180d4592c7 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonPyTestingTest.java @@ -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(){ + @NotNull + @Override + protected PyTestTestProcessRunner createProcessRunner() throws Exception { + return new PyTestTestProcessRunner(TARGET, 0); + } + }); + } + + @Test public void testRerunSubfolder() throws Exception { runPythonTest(new RerunSubfolderTask(2) { diff --git a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java index 4bbbe19877da..281fef011f51 100644 --- a/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java +++ b/python/testSrc/com/jetbrains/env/python/testing/PythonUnitTestingTest.java @@ -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(){ + @NotNull + @Override + protected PyUnitTestProcessRunner createProcessRunner() throws Exception { + return new PyUnitTestProcessRunner(TARGET, 0); + } + }); + } + @Test public void testRerunSubfolder() throws Exception { runPythonTest(new RerunSubfolderTask(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 diff --git a/python/testSrc/com/jetbrains/env/python/testing/RunModuleAsFileTask.java b/python/testSrc/com/jetbrains/env/python/testing/RunModuleAsFileTask.java new file mode 100644 index 000000000000..57c409e49bf8 --- /dev/null +++ b/python/testSrc/com/jetbrains/env/python/testing/RunModuleAsFileTask.java @@ -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> extends PyProcessWithConsoleTestTask { + + 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()); + } +}