diff --git a/python/junit5Tests-framework/BUILD.bazel b/python/junit5Tests-framework/BUILD.bazel index fb50f084aefd..ace0ccae44cf 100644 --- a/python/junit5Tests-framework/BUILD.bazel +++ b/python/junit5Tests-framework/BUILD.bazel @@ -54,6 +54,11 @@ jvm_library( "@lib//:python-community-junit5_tests-framework-uk-webcompere-system-stubs-jupiter", "//platform/util/coroutines", "@lib//:byte-buddy", + "//platform/testFramework", + "//platform/testFramework:testFramework_test_lib", + "//platform/editor-ui-api:editor-ui", + "//platform/editor-ui-ex:editor-ex", + "//platform/analysis-impl", ], exports = [ "//python/setup-test-environment:community-testFramework-testEnv", diff --git a/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml b/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml index 02e89973831d..a8aac192e26d 100644 --- a/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml +++ b/python/junit5Tests-framework/intellij.python.community.junit5Tests.framework.iml @@ -65,5 +65,9 @@ + + + + \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/FolderTest.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/FolderTest.kt similarity index 89% rename from python/testSrc/com/jetbrains/python/fixtures/junit5/FolderTest.kt rename to python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/FolderTest.kt index 14accaa60942..7d1dedcc522f 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/FolderTest.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/FolderTest.kt @@ -1,9 +1,9 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5 +package com.intellij.python.junit5Tests.framework -import com.jetbrains.python.fixtures.junit5.metaInfo.TestMetaInfoExtension.Companion.getTestClassInfo -import com.jetbrains.python.fixtures.junit5.metaInfo.TestMetaInfoExtension.Companion.setTestCaseFilePath -import com.jetbrains.python.fixtures.junit5.metaInfo.resolveTestName +import com.intellij.python.junit5Tests.framework.metaInfo.TestMetaInfoExtension.Companion.getTestClassInfo +import com.intellij.python.junit5Tests.framework.metaInfo.TestMetaInfoExtension.Companion.setTestCaseFilePath +import com.intellij.python.junit5Tests.framework.metaInfo.resolveTestName import org.jetbrains.annotations.TestOnly import org.junit.jupiter.api.TestTemplate import org.junit.jupiter.api.extension.ExtendWith diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/PyDefaultTestApplication.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/PyDefaultTestApplication.kt similarity index 93% rename from python/testSrc/com/jetbrains/python/fixtures/junit5/PyDefaultTestApplication.kt rename to python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/PyDefaultTestApplication.kt index 4949fbafa6cf..5baf52a74d44 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/PyDefaultTestApplication.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/PyDefaultTestApplication.kt @@ -1,5 +1,5 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5 +package com.intellij.python.junit5Tests.framework import com.intellij.openapi.application.EDT import com.intellij.openapi.fileEditor.FileDocumentManager @@ -13,9 +13,9 @@ import com.intellij.testFramework.junit5.fixture.* import com.intellij.testFramework.junit5.fixture.LookupFixtureExtension.Companion.getLookupFixtureManager import com.intellij.testFramework.junit5.fixture.LookupFixtureExtension.Companion.registerImplicitFixtures import com.jetbrains.python.PyNames -import com.jetbrains.python.fixtures.junit5.metaInfo.TestMetaInfoExtension -import com.jetbrains.python.fixtures.junit5.metaInfo.TestMetaInfoExtension.Companion.getTestClassInfo -import com.jetbrains.python.fixtures.junit5.metaInfo.TestMetaInfoExtension.Companion.getTestMethodInfo +import com.intellij.python.junit5Tests.framework.metaInfo.TestMetaInfoExtension +import com.intellij.python.junit5Tests.framework.metaInfo.TestMetaInfoExtension.Companion.getTestClassInfo +import com.intellij.python.junit5Tests.framework.metaInfo.TestMetaInfoExtension.Companion.getTestMethodInfo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext diff --git a/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt index d3b621fb9449..85d6dda49237 100644 --- a/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/fixtures.kt @@ -1,15 +1,20 @@ package com.intellij.python.junit5Tests.framework import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.readAction import com.intellij.openapi.components.Service import com.intellij.openapi.components.service +import com.intellij.openapi.vfs.resolveFromRootOrRelative import com.intellij.platform.util.coroutines.childScope +import com.intellij.psi.PsiDirectory +import com.intellij.psi.PsiFile import com.intellij.testFramework.junit5.fixture.TestFixture import com.intellij.testFramework.junit5.fixture.testFixture import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.cancel import org.jetbrains.annotations.TestOnly -import java.util.UUID +import java.nio.file.Path +import java.util.* /** @@ -26,3 +31,14 @@ fun applicationScope(name: String = UUID.randomUUID().toString()): TestFixture.psiFileFixture(fileRelativePath: Path): TestFixture = testFixture { _ -> + val sourceRootDirectory = this@psiFileFixture.init() + val virtualFile = sourceRootDirectory.virtualFile.resolveFromRootOrRelative(fileRelativePath.toString()) + ?: error("Can't resolve VirtualFile for $fileRelativePath") + val psiFile = readAction { + sourceRootDirectory.manager.findFile(virtualFile) + ?: error("Can't find PsiFile for $virtualFile") + } + initialized(psiFile) {} +} \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/editor.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/helper/editor.kt similarity index 96% rename from python/testSrc/com/jetbrains/python/fixtures/junit5/editor.kt rename to python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/helper/editor.kt index b98fa6d4dead..64b302f60fce 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/editor.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/helper/editor.kt @@ -1,5 +1,5 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5 +package com.intellij.python.junit5Tests.framework.helper import com.intellij.codeInsight.daemon.impl.HighlightInfo import com.intellij.lang.annotation.HighlightSeverity diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/TestClassInfo.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/metaInfo/TestClassInfo.kt similarity index 97% rename from python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/TestClassInfo.kt rename to python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/metaInfo/TestClassInfo.kt index 7aa2d80266df..8131cc6ba8b6 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/TestClassInfo.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/metaInfo/TestClassInfo.kt @@ -1,5 +1,5 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5.metaInfo +package com.intellij.python.junit5Tests.framework.metaInfo import com.intellij.openapi.application.PathManager import com.intellij.openapi.application.PluginPathManager diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/TestMetaInfoExtension.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/metaInfo/TestMetaInfoExtension.kt similarity index 98% rename from python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/TestMetaInfoExtension.kt rename to python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/metaInfo/TestMetaInfoExtension.kt index 028fbdf8647d..23549d73596d 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/TestMetaInfoExtension.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/framework/metaInfo/TestMetaInfoExtension.kt @@ -1,5 +1,5 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5.metaInfo +package com.intellij.python.junit5Tests.framework.metaInfo import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.TestDataPath diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/PythonJUnit5ExampleTest.kt b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/unit/showCase/PythonJUnit5ExampleTest.kt similarity index 78% rename from python/testSrc/com/jetbrains/python/fixtures/junit5/PythonJUnit5ExampleTest.kt rename to python/junit5Tests-framework/src/com/intellij/python/junit5Tests/unit/showCase/PythonJUnit5ExampleTest.kt index 603d0e9835ae..e2d749d09555 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/PythonJUnit5ExampleTest.kt +++ b/python/junit5Tests-framework/src/com/intellij/python/junit5Tests/unit/showCase/PythonJUnit5ExampleTest.kt @@ -1,5 +1,5 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5 +package com.intellij.python.junit5Tests.unit.showCase import com.intellij.openapi.application.EDT import com.intellij.openapi.editor.Editor @@ -8,11 +8,14 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile +import com.intellij.python.junit5Tests.framework.FolderTest +import com.intellij.python.junit5Tests.framework.PyDefaultTestApplication +import com.intellij.python.junit5Tests.framework.helper.doHighlighting +import com.intellij.python.junit5Tests.framework.metaInfo.Repository +import com.intellij.python.junit5Tests.framework.metaInfo.TestClassInfo import com.intellij.testFramework.TestDataPath import com.intellij.testFramework.common.timeoutRunBlocking import com.intellij.testFramework.junit5.fixture.projectFixture -import com.jetbrains.python.fixtures.junit5.metaInfo.Repository -import com.jetbrains.python.fixtures.junit5.metaInfo.TestClassInfo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.junit.jupiter.api.Assertions @@ -20,10 +23,9 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.CsvSource - @PyDefaultTestApplication @TestClassInfo(Repository.PY_COMMUNITY) -@TestDataPath($$"$CONTENT_ROOT/../testData/example/junit5") +@TestDataPath($$"$CONTENT_ROOT/../junit5Tests-framework/testResources/example/junit5") class PythonJUnit5ExampleTest( val project: Project, /* class-level, the value is projectFixture.get(), might be declared implicitly */ val module: Module, /* class-level implicitly declared in PyWithDefaultFixturesExtension */ @@ -34,7 +36,7 @@ class PythonJUnit5ExampleTest( } /** - * test folder iteration is here [AllFilesInFolderTestCaseProvider.provideTestTemplateInvocationContexts] + * test folder iteration is here [com.intellij.python.junit5Tests.framework.AllFilesInFolderTestCaseProvider.provideTestTemplateInvocationContexts] */ @FolderTest // runs testMyFolderTest on each file in the '@TestDataPath/myFolderTest' folder, filtering by regex is supported fun testHighlighting( @@ -50,7 +52,7 @@ class PythonJUnit5ExampleTest( } /** - * resource recognition by test name is here [com.jetbrains.python.fixtures.junit5.metaInfo.TestClassInfoData.getTestResourcePath] + * resource recognition by test name is here [com.intellij.python.junit5Tests.framework.metaInfo.TestClassInfoData.getTestResourcePath] */ @Test fun testSingle( diff --git a/python/junit5Tests-framework/testResources/example/junit5/highlighting/foo.py b/python/junit5Tests-framework/testResources/example/junit5/highlighting/foo.py new file mode 100644 index 000000000000..baacca3b3a70 --- /dev/null +++ b/python/junit5Tests-framework/testResources/example/junit5/highlighting/foo.py @@ -0,0 +1,5 @@ +import hello_world + +if __name__ == "__main__": + main = Main() + print("Hello, World!") diff --git a/python/junit5Tests-framework/testResources/example/junit5/highlighting/hello_world.py b/python/junit5Tests-framework/testResources/example/junit5/highlighting/hello_world.py new file mode 100644 index 000000000000..1341a49391a6 --- /dev/null +++ b/python/junit5Tests-framework/testResources/example/junit5/highlighting/hello_world.py @@ -0,0 +1,2 @@ +class Main: + pass diff --git a/python/junit5Tests-framework/testResources/example/junit5/single.py b/python/junit5Tests-framework/testResources/example/junit5/single.py new file mode 100644 index 000000000000..eb46e4bf4c2b --- /dev/null +++ b/python/junit5Tests-framework/testResources/example/junit5/single.py @@ -0,0 +1 @@ +print("Hello, world!") diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/fixtures.kt b/python/testSrc/com/jetbrains/python/fixtures/junit5/fixtures.kt deleted file mode 100644 index 9208f5e0222f..000000000000 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/fixtures.kt +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.jetbrains.python.fixtures.junit5 - -import com.intellij.openapi.application.readAction -import com.intellij.openapi.vfs.resolveFromRootOrRelative -import com.intellij.psi.PsiDirectory -import com.intellij.psi.PsiFile -import com.intellij.testFramework.junit5.fixture.TestFixture -import com.intellij.testFramework.junit5.fixture.testFixture -import org.jetbrains.annotations.TestOnly -import java.nio.file.Path - - -@TestOnly -fun TestFixture.psiFileFixture(fileRelativePath: Path): TestFixture = testFixture { _ -> - val sourceRootDirectory = this@psiFileFixture.init() - val virtualFile = sourceRootDirectory.virtualFile.resolveFromRootOrRelative(fileRelativePath.toString()) - ?: error("Can't resolve VirtualFile for $fileRelativePath") - val psiFile = readAction { - sourceRootDirectory.manager.findFile(virtualFile) - ?: error("Can't find PsiFile for $virtualFile") - } - initialized(psiFile) {} -} \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/package-info.java b/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/package-info.java deleted file mode 100644 index 64b08a499c90..000000000000 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/metaInfo/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -@Internal -package com.jetbrains.python.fixtures.junit5.metaInfo; - -import static org.jetbrains.annotations.ApiStatus.Internal; diff --git a/python/testSrc/com/jetbrains/python/fixtures/junit5/package-info.java b/python/testSrc/com/jetbrains/python/fixtures/junit5/package-info.java deleted file mode 100644 index 866d2249cf71..000000000000 --- a/python/testSrc/com/jetbrains/python/fixtures/junit5/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -@Internal -package com.jetbrains.python.fixtures.junit5; - -import static org.jetbrains.annotations.ApiStatus.Internal;