diff --git a/python/testSrc/com/jetbrains/python/Py3CompletionTest.java b/python/testSrc/com/jetbrains/python/Py3CompletionTest.java index 360dea053df3..3572442e2bc3 100644 --- a/python/testSrc/com/jetbrains/python/Py3CompletionTest.java +++ b/python/testSrc/com/jetbrains/python/Py3CompletionTest.java @@ -28,7 +28,7 @@ import java.util.List; public class Py3CompletionTest extends PyTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } public void testPropertyDecorator() { @@ -423,12 +423,12 @@ public class Py3CompletionTest extends PyTestCase { // PY-42700 public void testFStringLikeCompletionInOrdinaryStringLiterals() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest); + doTest(); } // PY-42700 public void testFStringLikeCompletionPreservesParenthesesForCallables() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest); + doTest(); } // PY-42700 @@ -438,58 +438,56 @@ public class Py3CompletionTest extends PyTestCase { // PY-42700 public void testFStringLikeCompletionNotAvailableInByteLiterals() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest); + doNegativeTest(); } // PY-42700 public void testFStringLikeCompletionNotAvailableInUnicodeLiterals() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest); + doNegativeTest(); } // PY-42700 public void testFStringLikeCompletionNotAvailableInStrFormatCalls() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest); + doNegativeTest(); } // PY-42700 public void testFStringLikeCompletionNotAvailableAfterEscapedOpeningBrace() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest); + doNegativeTest(); } // PY-42700 public void testFStringLikeCompletionAvailableAfterOpeningBraceFollowingEscapedOne() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest); + doTest(); } // PY-42700 public void testFStringLikeCompletionDoesNotDuplicateClosingBrace() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest); + doTest(); } // PY-42700 public void testFStringLikeCompletionOnMultipleCaretsDoesNotDuplicatePrefix() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doTest); + doTest(); } // PY-42700 public void testFStringLikeCompletionDoesNotWorkInStringWithInjections() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest); + doNegativeTest(); } // EA-232631 public void testFStringLikeCompletionNotAvailableInStringElementsInSyntacticallyIllegalPosition() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doNegativeTest); + doNegativeTest(); } // PY-45459 public void testFStringLikeCompletionAvailableRightAfterOpeningBrace() { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - myFixture.configureByFile(getTestName(true) + ".py"); - LookupElement[] variants = myFixture.completeBasic(); - assertNotNull(variants); - assertTrue(variants.length > 0); - assertTrue(ContainerUtil.exists(variants, v -> v.getLookupString().equals("my_expr"))); - }); + myFixture.configureByFile(getTestName(true) + ".py"); + LookupElement[] variants = myFixture.completeBasic(); + assertNotNull(variants); + assertTrue(variants.length > 0); + assertTrue(ContainerUtil.exists(variants, v -> v.getLookupString().equals("my_expr"))); } // PY-46056 @@ -526,12 +524,10 @@ public class Py3CompletionTest extends PyTestCase { // PY-46054 public void testFromImportFromSameDirectoryModule() { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - myFixture.copyDirectoryToProject(getTestName(true), ""); - myFixture.configureByFile("foo_bar/sample.py"); - myFixture.completeBasic(); - myFixture.checkResultByFile(getTestName(true) + "/foo_bar/sample.after.py"); - }); + myFixture.copyDirectoryToProject(getTestName(true), ""); + myFixture.configureByFile("foo_bar/sample.py"); + myFixture.completeBasic(); + myFixture.checkResultByFile(getTestName(true) + "/foo_bar/sample.after.py"); } @Override diff --git a/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java b/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java index bf5e4b42babe..48b7dbed5baf 100644 --- a/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java +++ b/python/testSrc/com/jetbrains/python/Py3DeprecationTest.java @@ -23,6 +23,6 @@ public class Py3DeprecationTest extends PyTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } } diff --git a/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java b/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java index ad24ba769856..e190b1e95b2d 100644 --- a/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java +++ b/python/testSrc/com/jetbrains/python/Py3HighlightingTest.java @@ -29,7 +29,7 @@ public class Py3HighlightingTest extends PyTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } // PY-20770 diff --git a/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java b/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java index c6e27880be02..24e4ebe1be15 100644 --- a/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/Py3MethodOverridingInspectionTest.java @@ -27,7 +27,7 @@ public class Py3MethodOverridingInspectionTest extends PyInspectionTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } // PY-17828 diff --git a/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java b/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java index 0f4cf20ea48b..db3dd03eb80c 100644 --- a/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/Py3QuickFixTest.java @@ -34,7 +34,7 @@ import java.util.List; public class Py3QuickFixTest extends PyTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return PyTestCase.ourPy3Descriptor; + return PyTestCase.ourPyLatestDescriptor; } // PY-13685 diff --git a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java index 5cd81c8329ab..a2d88c5ec5cd 100644 --- a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java +++ b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java @@ -33,7 +33,7 @@ import com.jetbrains.python.pyi.PyiUtil; public class Py3ResolveTest extends PyResolveTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return PyTestCase.ourPy3Descriptor; + return PyTestCase.ourPyLatestDescriptor; } @Override @@ -843,22 +843,16 @@ public class Py3ResolveTest extends PyResolveTestCase { // PY-25832 public void testTypeVarBoundAttribute() { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - assertResolvesTo(PyFunction.class, "upper", "builtins.pyi"); - }); + assertResolvesTo(PyFunction.class, "upper", "builtins.pyi"); } // PY-25832 public void testTypeVarConstraintAttribute() { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - assertResolvesTo(PyFunction.class, "bit_length", "builtins.pyi"); - }); + assertResolvesTo(PyFunction.class, "bit_length", "builtins.pyi"); } // PY-25832 public void testTypeVarClassObjectBoundAttribute() { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - assertNull(doResolve()); - }); + assertNull(doResolve()); } } diff --git a/python/testSrc/com/jetbrains/python/Py3TypeTest.java b/python/testSrc/com/jetbrains/python/Py3TypeTest.java index 2be5da3a607f..a8684c777a6f 100644 --- a/python/testSrc/com/jetbrains/python/Py3TypeTest.java +++ b/python/testSrc/com/jetbrains/python/Py3TypeTest.java @@ -18,7 +18,7 @@ public class Py3TypeTest extends PyTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } // PY-6702 @@ -171,7 +171,7 @@ public class Py3TypeTest extends PyTestCase { "async def bar():\n" + " expr = await foo()\n")); } - + // PY-16987 public void testNoTypeInGoogleDocstringParamAnnotation() { runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" + @@ -181,7 +181,7 @@ public class Py3TypeTest extends PyTestCase { " \"\"\" \n" + " expr = x")); } - + // PY-16987 public void testUnfilledTypeInGoogleDocstringParamAnnotation() { runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" + @@ -191,7 +191,7 @@ public class Py3TypeTest extends PyTestCase { " \"\"\" \n" + " expr = x")); } - + // PY-16987 public void testNoTypeInNumpyDocstringParamAnnotation() { runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def f(x: int):\n" + @@ -203,7 +203,7 @@ public class Py3TypeTest extends PyTestCase { " \"\"\"\n" + " expr = x")); } - + // PY-17010 public void testAnnotatedReturnTypePrecedesDocstring() { runWithLanguageLevel(LanguageLevel.PYTHON34, () -> doTest("int", "def func() -> int:\n" + @@ -551,7 +551,7 @@ public class Py3TypeTest extends PyTestCase { // PY-22513 public void testGenericKwargs() { - doTest("Dict[str, Union[int, str]]", + doTest("dict[str, Union[int, str]]", "from typing import Any, Dict, TypeVar\n" + "\n" + "T = TypeVar('T')\n" + @@ -598,13 +598,13 @@ public class Py3TypeTest extends PyTestCase { // PY-24445 public void testIsSubclassInsideListComprehension() { - doTest("List[Type[A]]", + doTest("list[Type[A]]", "class A: pass\n" + "expr = [e for e in [] if issubclass(e, A)]"); } public void testIsInstanceInsideListComprehension() { - doTest("List[A]", + doTest("list[A]", "class A: pass\n" + "expr = [e for e in [] if isinstance(e, A)]"); } @@ -1091,44 +1091,38 @@ public class Py3TypeTest extends PyTestCase { // PY-27783 public void testApplyingSuperSubstitutionToGenericClass() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTest("dict[T, int]", - "from typing import TypeVar, Generic, Dict, List\n" + - "\n" + - "T = TypeVar('T')\n" + - "\n" + - "class A(Generic[T]):\n" + - " pass\n" + - "\n" + - "class B(A[List[T]], Generic[T]):\n" + - " def __init__(self) -> None:\n" + - " self.value_set: Dict[T, int] = {}\n" + - "\n" + - " def foo(self) -> None:\n" + - " expr = self.value_set") - ); + doTest("dict[T, int]", + "from typing import TypeVar, Generic, Dict, List\n" + + "\n" + + "T = TypeVar('T')\n" + + "\n" + + "class A(Generic[T]):\n" + + " pass\n" + + "\n" + + "class B(A[List[T]], Generic[T]):\n" + + " def __init__(self) -> None:\n" + + " self.value_set: Dict[T, int] = {}\n" + + "\n" + + " def foo(self) -> None:\n" + + " expr = self.value_set"); } // PY-27783 public void testApplyingSuperSubstitutionToBoundedGenericClass() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTest("dict[T, int]", - "from typing import TypeVar, Generic, Dict, List\n" + - "\n" + - "T = TypeVar('T', bound=str)\n" + - "\n" + - "class A(Generic[T]):\n" + - " pass\n" + - "\n" + - "class B(A[List[T]], Generic[T]):\n" + - " def __init__(self) -> None:\n" + - " self.value_set: Dict[T, int] = {}\n" + - "\n" + - " def foo(self) -> None:\n" + - " expr = self.value_set") - ); + doTest("dict[T, int]", + "from typing import TypeVar, Generic, Dict, List\n" + + "\n" + + "T = TypeVar('T', bound=str)\n" + + "\n" + + "class A(Generic[T]):\n" + + " pass\n" + + "\n" + + "class B(A[List[T]], Generic[T]):\n" + + " def __init__(self) -> None:\n" + + " self.value_set: Dict[T, int] = {}\n" + + "\n" + + " def foo(self) -> None:\n" + + " expr = self.value_set"); } // PY-13750 @@ -1165,28 +1159,22 @@ public class Py3TypeTest extends PyTestCase { // PY-29891 public void testContextManagerType() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTest("str", - "from typing import Type, ContextManager\n" + - "def example():\n" + - " manager: Type[ContextManager[str]]\n" + - " with manager() as m:\n" + - " expr = m") - ); + doTest("str", + "from typing import Type, ContextManager\n" + + "def example():\n" + + " manager: Type[ContextManager[str]]\n" + + " with manager() as m:\n" + + " expr = m"); } // PY-29891 public void testAsyncContextManager() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTest("str", - "from typing import AsyncContextManager\n" + - "async def example():\n" + - " manager: AsyncContextManager[str]\n" + - " async with manager as m:\n" + - " expr = m") - ); + doTest("str", + "from typing import AsyncContextManager\n" + + "async def example():\n" + + " manager: AsyncContextManager[str]\n" + + " async with manager as m:\n" + + " expr = m"); } private void doTest(final String expectedType, final String text) { diff --git a/python/testSrc/com/jetbrains/python/PyExternalDocTest.kt b/python/testSrc/com/jetbrains/python/PyExternalDocTest.kt index 057d3e7daedb..d65fa7a18938 100644 --- a/python/testSrc/com/jetbrains/python/PyExternalDocTest.kt +++ b/python/testSrc/com/jetbrains/python/PyExternalDocTest.kt @@ -82,7 +82,7 @@ abstract class PyExternalDocTest : PyTestCase() { moduleName)}.$elementName") } - override fun getProjectDescriptor() = ourPy3Descriptor + override fun getProjectDescriptor() = ourPyLatestDescriptor } class PyExternalDocTestPy3 : PyExternalDocTest() { diff --git a/python/testSrc/com/jetbrains/python/PyNavigationTest.kt b/python/testSrc/com/jetbrains/python/PyNavigationTest.kt index ad24fe3fd0d3..f25e89afe491 100644 --- a/python/testSrc/com/jetbrains/python/PyNavigationTest.kt +++ b/python/testSrc/com/jetbrains/python/PyNavigationTest.kt @@ -209,5 +209,5 @@ class PyNavigationTest : PyTestCase() { return super.getTestDataPath() + "/navigation" } - override fun getProjectDescriptor(): LightProjectDescriptor? = ourPy3Descriptor + override fun getProjectDescriptor(): LightProjectDescriptor? = ourPyLatestDescriptor } \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyOverloadsProcessingPerformanceTest.java b/python/testSrc/com/jetbrains/python/PyOverloadsProcessingPerformanceTest.java index 2bef601b708f..aa3287f56538 100644 --- a/python/testSrc/com/jetbrains/python/PyOverloadsProcessingPerformanceTest.java +++ b/python/testSrc/com/jetbrains/python/PyOverloadsProcessingPerformanceTest.java @@ -168,6 +168,6 @@ public class PyOverloadsProcessingPerformanceTest extends PyTestCase { @Override protected @Nullable LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } } diff --git a/python/testSrc/com/jetbrains/python/PyPackageIconTest.java b/python/testSrc/com/jetbrains/python/PyPackageIconTest.java index aa34f001bc7e..5fd135072cd8 100644 --- a/python/testSrc/com/jetbrains/python/PyPackageIconTest.java +++ b/python/testSrc/com/jetbrains/python/PyPackageIconTest.java @@ -21,7 +21,7 @@ public class PyPackageIconTest extends PyTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @Override diff --git a/python/testSrc/com/jetbrains/python/PyRegexpTest.java b/python/testSrc/com/jetbrains/python/PyRegexpTest.java index 1c30e1033cff..0d2ddd306132 100644 --- a/python/testSrc/com/jetbrains/python/PyRegexpTest.java +++ b/python/testSrc/com/jetbrains/python/PyRegexpTest.java @@ -233,7 +233,7 @@ public class PyRegexpTest extends PyTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return getName().endsWith("Py3") ? ourPy3Descriptor : super.getProjectDescriptor(); + return getName().endsWith("Py3") ? ourPyLatestDescriptor : super.getProjectDescriptor(); } @NotNull diff --git a/python/testSrc/com/jetbrains/python/PyRelativeImportResolveTest.java b/python/testSrc/com/jetbrains/python/PyRelativeImportResolveTest.java index cbc017da5a89..84772dfd3cfd 100644 --- a/python/testSrc/com/jetbrains/python/PyRelativeImportResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyRelativeImportResolveTest.java @@ -21,12 +21,10 @@ import com.intellij.psi.util.QualifiedName; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.PsiTestUtil; import com.jetbrains.python.fixtures.PyMultiFileResolveTestCase; -import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.namespacePackages.PyNamespacePackagesService; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyFunction; -import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; import com.jetbrains.python.psi.resolve.PyQualifiedNameResolveContext; import com.jetbrains.python.psi.resolve.PyResolveImportUtil; import org.jetbrains.annotations.NotNull; @@ -52,7 +50,7 @@ public class PyRelativeImportResolveTest extends PyMultiFileResolveTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return PyTestCase.ourPy3Descriptor; + return ourPyLatestDescriptor; } @Override @@ -69,14 +67,12 @@ public class PyRelativeImportResolveTest extends PyMultiFileResolveTestCase { protected void setUp() throws Exception { super.setUp(); myNamespacePackageDirectory = null; - PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.getLatest()); RegistryManager.getInstance().get("python.explicit.namespace.packages").resetToDefault(); } @Override protected void tearDown() throws Exception { try { - PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null); myNamespacePackageDirectory = null; } catch (Throwable e) { diff --git a/python/testSrc/com/jetbrains/python/PyTypingTest.java b/python/testSrc/com/jetbrains/python/PyTypingTest.java index b923939acebe..fc59e3c51fe4 100644 --- a/python/testSrc/com/jetbrains/python/PyTypingTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypingTest.java @@ -40,7 +40,7 @@ public class PyTypingTest extends PyTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @Override @@ -465,7 +465,7 @@ public class PyTypingTest extends PyTestCase { // PY-22620 public void testVariableTypeCommentInjectionTuple() { - doTestInjectedText("x, y = undefined() # type: int, int", + doTestInjectedText("x, y = undefined() # type: int, int", "int, int"); } @@ -483,14 +483,14 @@ public class PyTypingTest extends PyTestCase { // PY-22620 public void testVariableTypeCommentInjectionParenthesisedTuple() { - doTestInjectedText("x, y = undefined() # type: (int, int)", + doTestInjectedText("x, y = undefined() # type: (int, int)", "(int, int)"); } // PY-22620 public void testForTypeCommentInjectionTuple() { doTestInjectedText("for x, y in undefined(): # type: int, int\n" + - " pass", + " pass", "int, int"); } @@ -555,7 +555,7 @@ public class PyTypingTest extends PyTestCase { "def f(expr: Type):\n" + " pass\n"); } - + // PY-18254 public void testFunctionTypeComment() { doTest("(x: int, args: Tuple[float, ...], kwargs: Dict[str, str]) -> List[bool]", @@ -720,7 +720,7 @@ public class PyTypingTest extends PyTestCase { "\n" + "expr = f"); } - + // PY-18386 public void testRecursiveType() { doTest("Union[int, Any]", @@ -1022,7 +1022,7 @@ public class PyTypingTest extends PyTestCase { "def f(x: Type[MyClass]): \n" + " expr = x"); } - + // PY-20057 public void testConstrainedClassObjectTypeOfParam() { doTest("Type[T]", @@ -1033,7 +1033,7 @@ public class PyTypingTest extends PyTestCase { "def f(x: Type[T]):\n" + " expr = x"); } - + // PY-20057 public void testFunctionCreatesInstanceFromType() { doTest("int", @@ -1068,7 +1068,7 @@ public class PyTypingTest extends PyTestCase { "def f(x: Type):\n" + " expr = x"); } - + // PY-20057 public void testTypingTypeOfAnyMapsToBuiltinType() { doTest("type", @@ -1086,7 +1086,7 @@ public class PyTypingTest extends PyTestCase { "def f(x: Tuple[Type[42], Type[], Type[unresolved]]):\n" + " expr = x"); } - + // PY-20057 public void testUnionOfClassObjectTypes() { doTest("Type[Union[int, str]]", @@ -1529,31 +1529,23 @@ public class PyTypingTest extends PyTestCase { // PY-41847 public void testTypingAnnotated() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> { - doTest("int", - "from typing import Annotated\n" + - "A = Annotated[int, 'Some constraint']\n" + - "expr: A"); - doTest("int", - "from typing_extensions import Annotated\n" + - "expr: Annotated[int, 'Some constraint'] = '5'"); - doMultiFileStubAwareTest("int", - "from annotated import A\n" + - "expr: A = 'str'"); - } - ); + doTest("int", + "from typing import Annotated\n" + + "A = Annotated[int, 'Some constraint']\n" + + "expr: A"); + doTest("int", + "from typing_extensions import Annotated\n" + + "expr: Annotated[int, 'Some constraint'] = '5'"); + doMultiFileStubAwareTest("int", + "from annotated import A\n" + + "expr: A = 'str'"); } // PY-35370 public void testAnyArgumentsCallableInTypeComment() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestInjectedText("from typing import Callable\n" + - "a = b # type: Callable[..., int]", - "Callable[..., int]") - ); + doTestInjectedText("from typing import Callable\n" + + "a = b # type: Callable[..., int]", + "Callable[..., int]"); } // PY-42334 diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java index 08e4fdd21fca..3fcc9f87b61e 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java @@ -73,7 +73,7 @@ import java.util.function.Consumer; public abstract class PyTestCase extends UsefulTestCase { protected static final PyLightProjectDescriptor ourPyDescriptor = new PyLightProjectDescriptor(LanguageLevel.PYTHON27); - protected static final PyLightProjectDescriptor ourPy3Descriptor = new PyLightProjectDescriptor(LanguageLevel.PYTHON37); + protected static final PyLightProjectDescriptor ourPyLatestDescriptor = new PyLightProjectDescriptor(LanguageLevel.getLatest()); protected CodeInsightTestFixture myFixture; diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java index 2892bae2e73f..07a8b92c3c42 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3AbstractClassInspectionTest.java @@ -17,7 +17,7 @@ public class Py3AbstractClassInspectionTest extends PyInspectionTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @NotNull diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java index 810eab27a858..3ef82c3443ae 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3CompatibilityInspectionTest.java @@ -25,7 +25,7 @@ public class Py3CompatibilityInspectionTest extends PyInspectionTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } // PY-18965 diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3NoneFunctionAssignmentInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3NoneFunctionAssignmentInspectionTest.java index 7b46ea7b17cb..5f74112842ed 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3NoneFunctionAssignmentInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3NoneFunctionAssignmentInspectionTest.java @@ -25,7 +25,7 @@ public class Py3NoneFunctionAssignmentInspectionTest extends PyInspectionTestCas @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } // PY-28729 diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java index 24fcadbfb119..ad93b7046fe4 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3StringFormatInspectionTest.java @@ -30,7 +30,7 @@ public class Py3StringFormatInspectionTest extends PyInspectionTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } // PY-16938 diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java index f752822a2b4f..31c29953634a 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3TypeCheckerInspectionTest.java @@ -14,7 +14,7 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @NotNull @@ -33,18 +33,6 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { return TEST_DIRECTORY; } - @Override - protected void setUp() throws Exception { - super.setUp(); - setLanguageLevel(LanguageLevel.getLatest()); - } - - @Override - protected void tearDown() throws Exception { - setLanguageLevel(null); - super.tearDown(); - } - // PY-9289 public void testWithOpenBinaryPy3() { doTest(); @@ -437,67 +425,53 @@ public class Py3TypeCheckerInspectionTest extends PyInspectionTestCase { // PY-41847 public void testTypingAnnotatedType() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> { - doTestByText("from typing import Annotated\n" + - "A = Annotated[bool, 'Some constraint']\n" + - "a: A = 'str'\n" + - "b: A = True\n" + - "c: Annotated[bool, 'Some constraint'] = 'str'\n" + - "d: Annotated[str, 'Some constraint'] = 'str'\n"); - } - ); + doTestByText("from typing import Annotated\n" + + "A = Annotated[bool, 'Some constraint']\n" + + "a: A = 'str'\n" + + "b: A = True\n" + + "c: Annotated[bool, 'Some constraint'] = 'str'\n" + + "d: Annotated[str, 'Some constraint'] = 'str'\n"); } // PY-41847 public void testTypingAnnotatedTypeMultiFile() { - runWithLanguageLevel(LanguageLevel.getLatest(), this::doMultiFileTest); + doMultiFileTest(); } // PY-43838 public void testParameterizedClassAgainstType() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Type, Any, List\n" + - "\n" + - "def my_function(param: Type[Any]):\n" + - " pass\n" + - "\n" + - "my_function(List[str])") - ); + doTestByText("from typing import Type, Any, List\n" + + "\n" + + "def my_function(param: Type[Any]):\n" + + " pass\n" + + "\n" + + "my_function(List[str])"); } // PY-43838 public void testUnionAgainstType() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Type, Any, Union\n" + - "\n" + - "def my_function(param: Type[Any]):\n" + - " pass\n" + - "\n" + - "my_function(Union[int, str])") - ); + doTestByText("from typing import Type, Any, Union\n" + + "\n" + + "def my_function(param: Type[Any]):\n" + + " pass\n" + + "\n" + + "my_function(Union[int, str])"); } // PY-44575 public void testArgsCallableAgainstOneParameterCallable() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Any, Callable, Iterable, TypeVar\n" + - "_T1 = TypeVar(\"_T1\")\n" + - "def mymap(c: Callable[[_T1], Any], i: Iterable[_T1]) -> Iterable[_T1]:\n" + - " pass\n" + - "def myfoo(*args: int) -> int:\n" + - " pass\n" + - "mymap(myfoo, [1, 2, 3])\n") - ); + doTestByText("from typing import Any, Callable, Iterable, TypeVar\n" + + "_T1 = TypeVar(\"_T1\")\n" + + "def mymap(c: Callable[[_T1], Any], i: Iterable[_T1]) -> Iterable[_T1]:\n" + + " pass\n" + + "def myfoo(*args: int) -> int:\n" + + " pass\n" + + "mymap(myfoo, [1, 2, 3])\n"); } // PY-36062 public void testModuleTypeParameter() { // `types.ModuleType` class qualified name is `_importlib_modulespec.ModuleType` in Python 3 - runWithLanguageLevel(LanguageLevel.getLatest(), this::doMultiFileTest); + doMultiFileTest(); } } diff --git a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java index 02a7b0448031..05f793672bb5 100644 --- a/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/Py3UnresolvedReferencesInspectionTest.java @@ -42,7 +42,7 @@ public class Py3UnresolvedReferencesInspectionTest extends PyInspectionTestCase @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @NotNull diff --git a/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java index f1772da38490..ace137a4d7b6 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyAsyncCallInspectionTest.java @@ -73,6 +73,6 @@ public class PyAsyncCallInspectionTest extends PyInspectionTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyDataclassInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyDataclassInspectionTest.java index 1cb9111b81f5..9e29d6dda0ab 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyDataclassInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyDataclassInspectionTest.java @@ -5,7 +5,6 @@ package com.jetbrains.python.inspections; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyInspectionTestCase; -import com.jetbrains.python.psi.LanguageLevel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -317,20 +316,15 @@ public class PyDataclassInspectionTest extends PyInspectionTestCase { @Override protected void doTest() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> { - myFixture.copyFileToProject(getTestCaseDirectory() + "/dataclasses.py", "dataclasses.py"); - super.doTest(); - assertProjectFilesNotParsed(myFixture.getFile()); - } - ); + myFixture.copyFileToProject(getTestCaseDirectory() + "/dataclasses.py", "dataclasses.py"); + super.doTest(); + assertProjectFilesNotParsed(myFixture.getFile()); } @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @NotNull diff --git a/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java index 402efba7bf80..cc26c94f2e6a 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyTypeHintsInspectionTest.java @@ -547,110 +547,101 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-16853 public void testParenthesesAndTyping() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Union, TypeAlias\n" + - "\n" + - "def a(b: Union(int, str)):\n" + - " pass\n" + - "\n" + - "def c(d):\n" + - " # type: (Union(int, str)) -> None\n" + - " pass\n" + - "\n" + - "def e(f: Union()):\n" + - " pass\n" + - "\n" + - "def g(h):\n" + - " # type: (Union()) -> None\n" + - " pass\n" + - " \n" + - "v1 = Union(int, str)\n" + - "v2 = None # type: Union(int, str)\n" + - "\n" + - "U = Union\n" + - "def i(j: U(int, str)):\n" + - " pass\n" + - " \n" + - "v3 = U(int, str)\n" + - "\n" + - "with foo() as bar: # type: Union(int,str)\n" + - " pass\n" + - " \n" + - "for x in []: # type: Union(int,str)\n" + - " pass\n" + - " \n" + - "A1: TypeAlias = Union(int, str)\n" + - "A2: TypeAlias = 'Union(int, str)'\n" + - "A3 = Union(int, str) # type: TypeAlias\n" + - "A3 = 'Union(int, str)' # type: TypeAlias") - ); + doTestByText("from typing import Union, TypeAlias\n" + + "\n" + + "def a(b: Union(int, str)):\n" + + " pass\n" + + "\n" + + "def c(d):\n" + + " # type: (Union(int, str)) -> None\n" + + " pass\n" + + "\n" + + "def e(f: Union()):\n" + + " pass\n" + + "\n" + + "def g(h):\n" + + " # type: (Union()) -> None\n" + + " pass\n" + + " \n" + + "v1 = Union(int, str)\n" + + "v2 = None # type: Union(int, str)\n" + + "\n" + + "U = Union\n" + + "def i(j: U(int, str)):\n" + + " pass\n" + + " \n" + + "v3 = U(int, str)\n" + + "\n" + + "with foo() as bar: # type: Union(int,str)\n" + + " pass\n" + + " \n" + + "for x in []: # type: Union(int,str)\n" + + " pass\n" + + " \n" + + "A1: TypeAlias = Union(int, str)\n" + + "A2: TypeAlias = 'Union(int, str)'\n" + + "A3 = Union(int, str) # type: TypeAlias\n" + + "A3 = 'Union(int, str)' # type: TypeAlias"); } // PY-16853 public void testParenthesesAndCustom() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Generic, TypeVar, TypeAlias\n" + - "\n" + - "T = TypeVar(\"T\")\n" + - "\n" + - "class A(Generic[T]):\n" + - " def __init__(self, v):\n" + - " pass\n" + - "\n" + - "def a(b: A(int)):\n" + - " pass\n" + - "\n" + - "def c(d):\n" + - " # type: (A(int)) -> None\n" + - " pass\n" + - "\n" + - "def e(f: A()):\n" + - " pass\n" + - "\n" + - "def g(h):\n" + - " # type: (A()) -> None\n" + - " pass\n" + - " \n" + - "v1 = A(int)\n" + - "v2 = None # type: A(int)\n" + - "\n" + - "U = A\n" + - "def i(j: U(int)):\n" + - " pass\n" + - " \n" + - "v3 = None # type: U(int)\n" + - "\n" + - "A1: TypeAlias = A(int)\n" + - "A2: TypeAlias = 'A(int)'\n" + - "A3 = A(int) # type: TypeAlias\n" + - "A4 = 'A(int)' # type: TypeAlias") - ); + doTestByText("from typing import Generic, TypeVar, TypeAlias\n" + + "\n" + + "T = TypeVar(\"T\")\n" + + "\n" + + "class A(Generic[T]):\n" + + " def __init__(self, v):\n" + + " pass\n" + + "\n" + + "def a(b: A(int)):\n" + + " pass\n" + + "\n" + + "def c(d):\n" + + " # type: (A(int)) -> None\n" + + " pass\n" + + "\n" + + "def e(f: A()):\n" + + " pass\n" + + "\n" + + "def g(h):\n" + + " # type: (A()) -> None\n" + + " pass\n" + + " \n" + + "v1 = A(int)\n" + + "v2 = None # type: A(int)\n" + + "\n" + + "U = A\n" + + "def i(j: U(int)):\n" + + " pass\n" + + " \n" + + "v3 = None # type: U(int)\n" + + "\n" + + "A1: TypeAlias = A(int)\n" + + "A2: TypeAlias = 'A(int)'\n" + + "A3 = A(int) # type: TypeAlias\n" + + "A4 = 'A(int)' # type: TypeAlias"); } // PY-20530 public void testCallableParameters() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Callable, TypeAlias\n" + - "\n" + - "a: Callable[..., str]\n" + - "b: Callable[[int], str]\n" + - "c: Callable[[int, str], str]\n" + - "\n" + - "d: Callable[...]\n" + - "e: Callable[int, str]\n" + - "f: Callable[int, str, str]\n" + - "g: Callable[(int, str), str]\n" + - "h: Callable[int]\n" + - "h: Callable[(int), str]\n" + - "\n" + - "A1: TypeAlias = Callable[int]\n" + - "A2: TypeAlias = 'Callable[int]'\n" + - "A3 = Callable[int] # type: TypeAlias\n" + - "A4 = 'Callable[int]' # type: TypeAlias") - ); + doTestByText("from typing import Callable, TypeAlias\n" + + "\n" + + "a: Callable[..., str]\n" + + "b: Callable[[int], str]\n" + + "c: Callable[[int, str], str]\n" + + "\n" + + "d: Callable[...]\n" + + "e: Callable[int, str]\n" + + "f: Callable[int, str, str]\n" + + "g: Callable[(int, str), str]\n" + + "h: Callable[int]\n" + + "h: Callable[(int), str]\n" + + "\n" + + "A1: TypeAlias = Callable[int]\n" + + "A2: TypeAlias = 'Callable[int]'\n" + + "A3 = Callable[int] # type: TypeAlias\n" + + "A4 = 'Callable[int]' # type: TypeAlias"); } // PY-20530 @@ -963,30 +954,25 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-42418 public void testParameterizedBuiltinCollections() { - runWithLanguageLevel(LanguageLevel.getLatest(), () -> { - doTestByText("xs: type[str]\n" + - "ys: tuple[int, str]\n" + - "zs: dict[int, str]"); - }); + doTestByText("xs: type[str]\n" + + "ys: tuple[int, str]\n" + + "zs: dict[int, str]"); } // PY-41847 public void testAnnotated() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Annotated\n" + - "\n" + - "a: Annotated[1]\n" + - "b: Annotated[int, 1]\n" + - "c: Annotated[...]\n" + - "\n" + - "class A:\n" + - " pass\n" + - "\n" + - "d: Annotated[A, '']\n" + - "e: Annotated[Annotated[A, True]]\n" + - "f: Annotated[Annotated[A], '']") - ); + doTestByText("from typing import Annotated\n" + + "\n" + + "a: Annotated[1]\n" + + "b: Annotated[int, 1]\n" + + "c: Annotated[...]\n" + + "\n" + + "class A:\n" + + " pass\n" + + "\n" + + "d: Annotated[A, '']\n" + + "e: Annotated[Annotated[A, True]]\n" + + "f: Annotated[Annotated[A], '']"); } // PY-41847 @@ -1008,54 +994,46 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { // PY-41847 public void testAnnotatedWithoutArguments() { - runWithLanguageLevel( - LanguageLevel.getLatest(), - () -> doTestByText("from typing import Annotated\n" + - "a: Annotated = 1\n" + - "b = 2 # type: Annotated[int]") - ); + doTestByText("from typing import Annotated\n" + + "a: Annotated = 1\n" + + "b = 2 # type: Annotated[int]"); } // PY-42334 public void testParametrizedTypeAliasInExpression() { - runWithLanguageLevel(LanguageLevel.getLatest(), - () -> doTestByText("from typing import TypeAlias\n" + - "\n" + - "Alias = TypeAlias[int]")); + doTestByText("from typing import TypeAlias\n" + + "\n" + + "Alias = TypeAlias[int]"); } // PY-42334 public void testParametrizedTypeAliasInAnnotation() { - runWithLanguageLevel(LanguageLevel.getLatest(), - () -> doTestByText("from typing import TypeAlias\n" + - "\n" + - "Alias: TypeAlias[int]")); + doTestByText("from typing import TypeAlias\n" + + "\n" + + "Alias: TypeAlias[int]"); } // PY-42334 public void testNonTopLevelTypeAlias() { - runWithLanguageLevel(LanguageLevel.getLatest(), - () -> doTestByText("from typing import TypeAlias\n" + - "\n" + - "Alias: Final[TypeAlias] = str")); + doTestByText("from typing import TypeAlias\n" + + "\n" + + "Alias: Final[TypeAlias] = str"); } // PY-42334 public void testNotInitializedTypeAlias() { - runWithLanguageLevel(LanguageLevel.getLatest(), - () -> doTestByText("from typing import TypeAlias\n" + - "\n" + - "Alias: TypeAlias")); + doTestByText("from typing import TypeAlias\n" + + "\n" + + "Alias: TypeAlias"); } // PY-42334 public void testNotTopLevelTypeAlias() { - runWithLanguageLevel(LanguageLevel.getLatest(), - () -> doTestByText("from typing import TypeAlias\n" + - "\n" + - "def func():\n" + - " Alias: TypeAlias = str")); + doTestByText("from typing import TypeAlias\n" + + "\n" + + "def func():\n" + + " Alias: TypeAlias = str"); } @NotNull @@ -1066,6 +1044,6 @@ public class PyTypeHintsInspectionTest extends PyInspectionTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } } diff --git a/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java b/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java index eb5d89f04fd8..4438fc390bf4 100644 --- a/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java +++ b/python/testSrc/com/jetbrains/python/pyi/PyiTypeTest.java @@ -59,7 +59,7 @@ public class PyiTypeTest extends PyTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } @Override diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java b/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java index f34771b7352a..2058cf9d361f 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/quickFixes/PyAsyncCallQuickFixTest.java @@ -25,6 +25,6 @@ public class PyAsyncCallQuickFixTest extends PyQuickFixTestCase { @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return ourPyLatestDescriptor; } }