PY-56609: Refactoring in quick documentation

Migrating PyQuickDocTest.py to Python 3

GitOrigin-RevId: 2ad69939a695066d92f7c8c937828f8097110a62
This commit is contained in:
Irina Fediaeva
2023-01-23 13:38:46 +00:00
committed by intellij-monorepo-bot
parent 98f4edc289
commit a143468daa
21 changed files with 86 additions and 190 deletions
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#AsyncFunctionQuickDoc">AsyncFunctionQuickDoc</a><br>async def <b>func</b>() -&gt; Any</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#AsyncFunctionQuickDoc">AsyncFunctionQuickDoc</a><br>async def <b>func</b>() -&gt; Coroutine[Any,&nbsp;Any,&nbsp;None]</pre></div></body></html>
@@ -1 +1 @@
async def func() -&gt; Any
async def func() -&gt; Coroutine[Any,&nbsp;Any,&nbsp;None]
+1 -1
View File
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#__builtin__">__builtin__</a><br>def <b>len</b>(__obj: Sized) -&gt; <a href="psi_element://#typename#int">int</a></pre></div><div class='content'>len(object)&nbsp;-&gt;&nbsp;integer<br><br>Return&nbsp;the&nbsp;number&nbsp;of&nbsp;items&nbsp;of&nbsp;a&nbsp;sequence&nbsp;or&nbsp;collection.</div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#builtins">builtins</a><br>def <b>len</b>(__obj: Sized) -&gt; <a href="psi_element://#typename#int">int</a></pre></div><div class='content'>len(object)&nbsp;-&gt;&nbsp;integer<br><br>Return&nbsp;the&nbsp;number&nbsp;of&nbsp;items&nbsp;of&nbsp;a&nbsp;sequence&nbsp;or&nbsp;collection.</div></body></html>
+1 -1
View File
@@ -1,4 +1,4 @@
<html><body><div class='definition'><pre><a href="psi_element://#typename#DefaultValues.C">DefaultValues.C</a><br>def <b>method</b>(self=42,
foo: List[<a href="psi_element://#typename#int">int</a>] = [1,
foo: <a href="psi_element://#typename#list">list</a>[<a href="psi_element://#typename#int">int</a>] = [1,
2],
bar: <a href="psi_element://#typename#str">str</a> = &quot;&lt;br/&gt;&quot;) -&gt; None</pre></div></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#EmptyTupleType">EmptyTupleType</a><br>def <b>func</b>() -&gt; Tuple</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#EmptyTupleType">EmptyTupleType</a><br>def <b>func</b>() -&gt; tuple</pre></div></body></html>
@@ -1,4 +1,4 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#FunctionWrapping">FunctionWrapping</a><br>def <b>maybe_add_numbers</b>(a: Optional[<a href="psi_element://#typename#int">int</a>],
b: Optional[<a href="psi_element://#typename#int">int</a>],
c: Optional[<a href="psi_element://#typename#int">int</a>],
d: Optional[<a href="psi_element://#typename#int">int</a>]) -&gt; Optional[<a href="psi_element://#typename#int">int</a>]</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#FunctionWrapping">FunctionWrapping</a><br>def <b>maybe_add_numbers</b>(a: <a href="psi_element://#typename#int">int</a>&nbsp;|&nbsp;None,
b: <a href="psi_element://#typename#int">int</a>&nbsp;|&nbsp;None,
c: <a href="psi_element://#typename#int">int</a>&nbsp;|&nbsp;None,
d: <a href="psi_element://#typename#int">int</a>&nbsp;|&nbsp;None) -&gt; <a href="psi_element://#typename#int">int</a>&nbsp;|&nbsp;None</pre></div></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#HeterogeneousTuple">HeterogeneousTuple</a><br>def <b>get_tuple</b>() -&gt; Tuple[<a href="psi_element://#typename#int">int</a>,&nbsp;<a href="psi_element://#typename#int">int</a>,&nbsp;<a href="psi_element://#typename#str">str</a>]</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#HeterogeneousTuple">HeterogeneousTuple</a><br>def <b>get_tuple</b>() -&gt; tuple[<a href="psi_element://#typename#int">int</a>,&nbsp;<a href="psi_element://#typename#int">int</a>,&nbsp;<a href="psi_element://#typename#str">str</a>]</pre></div></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#HomogeneousTuple">HomogeneousTuple</a><br>def <b>get_tuple</b>() -&gt; Tuple[<a href="psi_element://#typename#str">str</a>,&nbsp;...]</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#HomogeneousTuple">HomogeneousTuple</a><br>def <b>get_tuple</b>() -&gt; tuple[<a href="psi_element://#typename#str">str</a>,&nbsp;...]</pre></div></body></html>
@@ -1,2 +1,2 @@
variable &quot;x&quot;
Inferred type: Union[str, int]
Inferred type: str | int
@@ -1,2 +1,2 @@
@decorator1, @decorator2
def foo(param: Any) -&gt; Optional[Any]
def foo(param: Any) -&gt; Any&nbsp;|&nbsp;None
@@ -1,2 +1,2 @@
@decorator
def foo(param: Any) -&gt; Optional[Any]
def foo(param: Any) -&gt; Any&nbsp;|&nbsp;None
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#ManyDecoratorsFunction">ManyDecoratorsFunction</a><br>@<i>decorator1</i><br>@<i>decorator2</i><br>def <b>foo</b>(param: Any) -&gt; Optional[Any]</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#ManyDecoratorsFunction">ManyDecoratorsFunction</a><br>@<i>decorator1</i><br>@<i>decorator2</i><br>def <b>foo</b>(param: Any) -&gt; Any&nbsp;|&nbsp;None</pre></div></body></html>
+1 -1
View File
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#typename#Method.Foo">Method.Foo</a><br>@<i>deco</i><br>def <b>meth</b>(self) -&gt; Optional[Any]</pre></div><div class='content'>Doc&nbsp;of&nbsp;meth.</div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#typename#Method.Foo">Method.Foo</a><br>@<i>deco</i><br>def <b>meth</b>(self) -&gt; Any&nbsp;|&nbsp;None</pre></div><div class='content'>Doc&nbsp;of&nbsp;meth.</div></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#MultilineAssignedValueForTarget">MultilineAssignedValueForTarget</a><br>var: List[<a href="psi_element://#typename#int">int</a>] = [1,...</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#MultilineAssignedValueForTarget">MultilineAssignedValueForTarget</a><br>var: <a href="psi_element://#typename#list">list</a>[<a href="psi_element://#typename#int">int</a>] = [1,...</pre></div></body></html>
+1 -1
View File
@@ -1,3 +1,3 @@
def ones(shape: Union[<a href="psi_element://#typename#int">int</a>,&nbsp;Iterable[<a href="psi_element://#typename#int">int</a>]], dtype: Optional[<a href="psi_element://#typename#object">object</a>] = None, order: Optional[<a href="psi_element://#typename#str">str</a>] = &#39;C&#39;) -&gt; <a href="psi_element://#typename#ndarray">ndarray</a>
def ones(shape: <a href="psi_element://#typename#int">int</a>&nbsp;|&nbsp;Iterable[<a href="psi_element://#typename#int">int</a>], dtype: <a href="psi_element://#typename#object">object</a>&nbsp;|&nbsp;None = None, order: <a href="psi_element://#typename#str">str</a>&nbsp;|&nbsp;None = &#39;C&#39;) -&gt; <a href="psi_element://#typename#ndarray">ndarray</a>
**Test docstring**
Return a new array of given shape and type, filled with ones.
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#OneDecoratorFunction">OneDecoratorFunction</a><br>@<i>decorator</i><br>def <b>foo</b>(param: Any) -&gt; Optional[Any]</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#OneDecoratorFunction">OneDecoratorFunction</a><br>@<i>decorator</i><br>def <b>foo</b>(param: Any) -&gt; Any&nbsp;|&nbsp;None</pre></div></body></html>
@@ -1,2 +1,2 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#OptionalAndUnionTypesContainingTypeVars">OptionalAndUnionTypesContainingTypeVars</a><br>def <b>f</b>(x1: Optional[T],
x2: Union[T,&nbsp;Tuple[Any,&nbsp;Any]]) -&gt; None</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#OptionalAndUnionTypesContainingTypeVars">OptionalAndUnionTypesContainingTypeVars</a><br>def <b>f</b>(x1: T&nbsp;|&nbsp;None,
x2: T&nbsp;|&nbsp;tuple[Any,&nbsp;Any]) -&gt; None</pre></div></body></html>
@@ -1,2 +1,2 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#OptionalParameterType">OptionalParameterType</a><br>def <b>open</b>(encoding: Optional[<a href="psi_element://#typename#str">str</a>] = None,
errors: Optional[<a href="psi_element://#typename#str">str</a>] = None) -&gt; None</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#OptionalParameterType">OptionalParameterType</a><br>def <b>open</b>(encoding: <a href="psi_element://#typename#str">str</a>&nbsp;|&nbsp;None = None,
errors: <a href="psi_element://#typename#str">str</a>&nbsp;|&nbsp;None = None) -&gt; None</pre></div></body></html>
@@ -1 +1 @@
<html><body><div class='definition'><pre><a href="psi_element://#module#StandardCollectionTypesRenderedCapitalizedBefore39">StandardCollectionTypesRenderedCapitalizedBefore39</a><br>items: List[<a href="psi_element://#typename#int">int</a>] = [42]</pre></div></body></html>
<html><body><div class='definition'><pre><a href="psi_element://#module#StandardCollectionTypesRenderedCapitalizedBefore39">StandardCollectionTypesRenderedCapitalizedBefore39</a><br>items: <a href="psi_element://#typename#list">list</a>[<a href="psi_element://#typename#int">int</a>] = [42]</pre></div></body></html>
@@ -1,108 +0,0 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python;
import com.intellij.codeInsight.documentation.DocumentationManager;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.LightProjectDescriptor;
import com.jetbrains.python.documentation.PyDocumentationSettings;
import com.jetbrains.python.documentation.PythonDocumentationProvider;
import com.jetbrains.python.documentation.docstrings.DocStringFormat;
import com.jetbrains.python.fixtures.LightMarkedTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
public class Py3QuickDocTest extends LightMarkedTestCase {
private PythonDocumentationProvider myProvider;
private DocStringFormat myFormat;
@Override
protected @Nullable LightProjectDescriptor getProjectDescriptor() {
return ourPyLatestDescriptor;
}
@Override
protected void setUp() throws Exception {
super.setUp();
// the provider is stateless, can be reused, as in real life
myProvider = new PythonDocumentationProvider();
final PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getModule());
myFormat = documentationSettings.getFormat();
documentationSettings.setFormat(DocStringFormat.PLAIN);
}
@Override
public void tearDown() throws Exception {
try {
final PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getModule());
documentationSettings.setFormat(myFormat);
}
catch (Throwable e) {
addSuppressedException(e);
}
finally {
super.tearDown();
}
}
private void checkByHTML(@NotNull String text) {
assertSameLinesWithFile(getTestDataPath() + getTestName(false) + ".html", text);
}
@Override
protected Map<String, PsiElement> loadTest() {
return configureByFile(getTestName(false) + ".py");
}
protected void checkHTMLOnly() {
final Map<String, PsiElement> marks = loadTest();
final PsiElement originalElement = marks.get("<the_ref>");
assertNotNull("<the_ref> marker is missing in test data", originalElement);
final DocumentationManager manager = DocumentationManager.getInstance(myFixture.getProject());
final PsiElement target = manager.findTargetElement(myFixture.getEditor(),
originalElement.getTextOffset(),
myFixture.getFile(),
originalElement);
checkByHTML(myProvider.generateDoc(target, originalElement));
}
// PY-49935
public void testConcatenateInReturn() {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateInParam() {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateSeveralFirstParamInParam() {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateInGeneric() {
checkHTMLOnly();
}
public void testSeveralParamSpecs() {
checkHTMLOnly();
}
// PY-53104
public void testSelf() {
checkHTMLOnly();
}
// PY-53104
public void testTypingExtensionsSelf() {
checkHTMLOnly();
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/quickdoc/";
}
}
@@ -5,7 +5,6 @@ import com.intellij.codeInsight.documentation.DocumentationManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.testFramework.LightProjectDescriptor;
import com.jetbrains.python.documentation.PyDocumentationSettings;
import com.jetbrains.python.documentation.PythonDocumentationProvider;
import com.jetbrains.python.documentation.docstrings.DocStringFormat;
@@ -15,7 +14,6 @@ import com.jetbrains.python.psi.impl.PyBuiltinCache;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@@ -25,11 +23,6 @@ public class PyQuickDocTest extends LightMarkedTestCase {
private PythonDocumentationProvider myProvider;
private DocStringFormat myFormat;
@Override
protected @Nullable LightProjectDescriptor getProjectDescriptor() {
return ourPy2Descriptor;
}
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -170,27 +163,18 @@ public class PyQuickDocTest extends LightMarkedTestCase {
}
public void testPropNewSetter() {
runWithLanguageLevel(
LanguageLevel.PYTHON26,
() -> {
Map<String, PsiElement> marks = loadTest();
PsiElement referenceElement = marks.get("<the_ref>");
final PyDocStringOwner docStringOwner = (PyDocStringOwner)referenceElement.getParent().getReference().resolve();
checkByHTML(myProvider.generateDoc(docStringOwner, referenceElement));
}
);
Map<String, PsiElement> marks = loadTest();
PsiElement referenceElement = marks.get("<the_ref>");
final PyDocStringOwner docStringOwner = (PyDocStringOwner)referenceElement.getParent().getReference().resolve();
checkByHTML(myProvider.generateDoc(docStringOwner, referenceElement));
}
public void testPropNewDeleter() {
runWithLanguageLevel(
LanguageLevel.PYTHON26,
() -> {
Map<String, PsiElement> marks = loadTest();
PsiElement referenceElement = marks.get("<the_ref>");
final PyDocStringOwner docStringOwner = (PyDocStringOwner)((PyReferenceExpression)(referenceElement.getParent())).getReference().resolve();
checkByHTML(myProvider.generateDoc(docStringOwner, referenceElement));
}
);
Map<String, PsiElement> marks = loadTest();
PsiElement referenceElement = marks.get("<the_ref>");
final PyDocStringOwner docStringOwner =
(PyDocStringOwner)((PyReferenceExpression)(referenceElement.getParent())).getReference().resolve();
checkByHTML(myProvider.generateDoc(docStringOwner, referenceElement));
}
public void testPropOldGetter() {
@@ -302,23 +286,23 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-17705
public void testOptionalParameterType() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testHomogeneousTuple() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testHeterogeneousTuple() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testUnknownTuple() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testTypeVars() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-28808
@@ -328,7 +312,7 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-22730
public void testOptionalAndUnionTypesContainingTypeVars() {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-22685
@@ -423,42 +407,37 @@ public class PyQuickDocTest extends LightMarkedTestCase {
}
public void testClassWithAllKindSuperClassExpressions() {
runWithLanguageLevel(LanguageLevel.PYTHON34, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testHoverOverClassWithAllKindSuperClassExpressions() {
runWithLanguageLevel(LanguageLevel.PYTHON34, this::checkHover);
checkHover();
}
// PY-23247
public void testOverloads() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-23247
public void testHoverOverOverloads() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHover);
checkHover();
}
// PY-23247
public void testOverloadsAndImplementation() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-23247
public void testHoverOverOverloadsAndImplementation() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHover);
checkHover();
}
// PY-23247
public void testDocOnImplementationWithOverloads() {
runWithLanguageLevel(
LanguageLevel.PYTHON35,
() -> {
final PsiElement originalElement = loadTest().get("<the_ref>");
checkByHTML(myProvider.generateDoc(originalElement.getParent(), originalElement));
}
);
final PsiElement originalElement = loadTest().get("<the_ref>");
checkByHTML(myProvider.generateDoc(originalElement.getParent(), originalElement));
}
public void testPlainTextDocstringsQuotesPlacementDoesntAffectFormatting() {
@@ -492,22 +471,22 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-42334
public void testTypeOfExplicitTypeAlias() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-29339
public void testAsyncFunctionTooltip() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHover);
checkHover();
}
// PY-29339
public void testAsyncFunctionQuickDoc() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-30103
public void testFunctionWrapping() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-30103
@@ -517,12 +496,12 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-30103
public void testReturnTypeWrappedBecauseOfParameters() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-30103
public void testReturnTypeWrappedBecauseOfFunctionName() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testParamDescriptionOrder() {
@@ -571,7 +550,7 @@ public class PyQuickDocTest extends LightMarkedTestCase {
}
public void testKeywordArgsDescriptionForMissingParameter() {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testArgsKwargsTypes() {
@@ -579,7 +558,7 @@ public class PyQuickDocTest extends LightMarkedTestCase {
}
public void testExplicitlyAnnotatedSelfParamType() {
runWithLanguageLevel(LanguageLevel.PYTHON36, this::checkHTMLOnly);
checkHTMLOnly();
}
public void testExplicitlyAnnotatedClsParamType() {
@@ -628,7 +607,7 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-31862
public void testEscapedSummaryOfFunctionDocstringInQuickNavigationInfo() {
checkHover();
checkHover();
}
// PY-31862
@@ -643,21 +622,21 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-35512
public void testPositionalOnlyParameters() {
runWithLanguageLevel(LanguageLevel.PYTHON38, this::checkHover);
checkHover();
}
public void testStandardCollectionTypesRenderedCapitalizedBefore39() {
runWithLanguageLevel(LanguageLevel.PYTHON38, this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-42418
public void testStandardCollectionTypesRenderedWithOriginalCase() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-42418
public void testTupleTypeIsRenderedLowercased() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-52281
@@ -732,7 +711,7 @@ public class PyQuickDocTest extends LightMarkedTestCase {
// PY-55521
public void testTargetExpressionInsideTypeDeclaration() {
runWithLanguageLevel(LanguageLevel.getLatest(), this::checkHTMLOnly);
checkHTMLOnly();
}
// PY-33341
@@ -840,6 +819,31 @@ public class PyQuickDocTest extends LightMarkedTestCase {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateInReturn() {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateInParam() {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateSeveralFirstParamInParam() {
checkHTMLOnly();
}
// PY-49935
public void testConcatenateInGeneric() {
checkHTMLOnly();
}
// PY-49935
public void testSeveralParamSpecs() {
checkHTMLOnly();
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/quickdoc/";