[python] add pyproject.toml unsatisfied requirement inspection test (PY-72985)

GitOrigin-RevId: f301151302e212bffa06b678c469417a2555d38c
This commit is contained in:
Vitaly Legchilkin
2025-03-18 21:50:59 +00:00
committed by intellij-monorepo-bot
parent 133bb61a1d
commit e5fdee826d
2 changed files with 22 additions and 1 deletions
@@ -0,0 +1,7 @@
[project]
dependencies = [
"<warning descr="Package mypy is not installed">mypy</warning>"
]
[build-system]
requires = ["<warning descr="Package poetry-core is not installed">poetry-core</warning>"]
@@ -2,14 +2,28 @@
package com.jetbrains.python.requirements
import com.intellij.codeInspection.ex.InspectionProfileImpl
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.testFramework.TestDataPath
import com.jetbrains.python.sdk.pythonSdk
@TestDataPath("\$CONTENT_ROOT/../testData/requirements/inspections")
class UnsatisfiedRequirementInspectionTest : PythonDependencyTestCase() {
fun testUnsatisfiedRequirement() {
doMultiFileTest("requirements.txt")
assertContainsElements(myFixture.availableIntentions.map { it.text }, "Install package mypy", "Install all missing packages", "Run 'pip install -e .'")
}
fun testPyProjectTomlUnsatisfiedRequirement() {
doMultiFileTest("pyproject.toml")
val warnings = myFixture.doHighlighting(HighlightSeverity.WARNING)
listOf("mypy", "poetry-core").forEach { unsatisfiedPackage ->
val warning = warnings.single { it.text == unsatisfiedPackage }
assertEquals("Package $unsatisfiedPackage is not installed", warning.description)
}
}
fun testEmptyRequirementsFile() {
doMultiFileTest("requirements.txt")
assertContainsElements(myFixture.availableIntentions.map { it.text }, "Add imported packages to requirements…")
@@ -19,7 +33,7 @@ class UnsatisfiedRequirementInspectionTest : PythonDependencyTestCase() {
myFixture.copyDirectoryToProject(getTestName(false), "")
myFixture.configureFromTempProjectFile(filename)
myFixture.enableInspections(UnsatisfiedRequirementInspection::class.java)
myFixture.checkHighlighting(true, false, true)
myFixture.checkHighlighting(true, false, true, false)
}
override fun setUp() {