[python][junit5] move PyDefaultTestApplication to the junit5Tests.framework module

Merge-request: IJ-MR-176009
Merged-by: Vitaly Legchilkin <Vitaly.Legchilkin@jetbrains.com>

GitOrigin-RevId: 4be35423f74375e1b37e0ea87fd6490a950060f6
This commit is contained in:
Vitaly Legchilkin
2025-09-20 13:14:32 +00:00
committed by intellij-monorepo-bot
parent 464bc08113
commit 0ce97b7649
15 changed files with 54 additions and 53 deletions
+5
View File
@@ -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",
@@ -65,5 +65,9 @@
</orderEntry>
<orderEntry type="module" module-name="intellij.platform.util.coroutines" scope="TEST" />
<orderEntry type="library" scope="TEST" name="byte-buddy" level="project" />
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.editor.ui" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.editor.ex" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.analysis.impl" scope="TEST" />
</component>
</module>
@@ -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
@@ -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
@@ -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<C
}
}
@TestOnly
fun TestFixture<PsiDirectory>.psiFileFixture(fileRelativePath: Path): TestFixture<PsiFile> = 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) {}
}
@@ -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
@@ -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
@@ -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
@@ -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(
@@ -0,0 +1,5 @@
import hello_world
if __name__ == "__main__":
main = Main()<caret>
print("Hello, World!")
@@ -0,0 +1,2 @@
class Main:
pass<caret>
@@ -0,0 +1 @@
print("Hello, world!")<caret>
@@ -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<PsiDirectory>.psiFileFixture(fileRelativePath: Path): TestFixture<PsiFile> = 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) {}
}
@@ -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;
@@ -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;