diff --git a/python/testData/refactoring/rename/googleDocStringAttribute.py b/python/testData/refactoring/rename/googleDocStringAttribute.py new file mode 100644 index 000000000000..296cae63d5de --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringAttribute.py @@ -0,0 +1,8 @@ +class C: + """ + Attributes: + foo : ignored + """ + + def __init__(self): + self.foo = 42 diff --git a/python/testData/refactoring/rename/googleDocStringAttribute_after.py b/python/testData/refactoring/rename/googleDocStringAttribute_after.py new file mode 100644 index 000000000000..328f0e26a2e1 --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringAttribute_after.py @@ -0,0 +1,8 @@ +class C: + """ + Attributes: + bar : ignored + """ + + def __init__(self): + self.bar = 42 diff --git a/python/testData/refactoring/rename/googleDocStringParam.py b/python/testData/refactoring/rename/googleDocStringParam.py new file mode 100644 index 000000000000..1532e919faa3 --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringParam.py @@ -0,0 +1,6 @@ +def func(foo): + """ + Parameters: + foo : ignored + """ + pass diff --git a/python/testData/refactoring/rename/googleDocStringParamType.py b/python/testData/refactoring/rename/googleDocStringParamType.py new file mode 100644 index 000000000000..646f15705c4f --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringParamType.py @@ -0,0 +1,8 @@ +class Foo: pass + +def func(foo): + """ + Parameters: + foo (Foo): ignored + """ + pass diff --git a/python/testData/refactoring/rename/googleDocStringParamType_after.py b/python/testData/refactoring/rename/googleDocStringParamType_after.py new file mode 100644 index 000000000000..abb02c62fcbf --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringParamType_after.py @@ -0,0 +1,8 @@ +class Bar: pass + +def func(foo): + """ + Parameters: + foo (Bar): ignored + """ + pass diff --git a/python/testData/refactoring/rename/googleDocStringParam_after.py b/python/testData/refactoring/rename/googleDocStringParam_after.py new file mode 100644 index 000000000000..bfe80b4ee6b1 --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringParam_after.py @@ -0,0 +1,6 @@ +def func(bar): + """ + Parameters: + bar : ignored + """ + pass diff --git a/python/testData/refactoring/rename/googleDocStringReturnType.py b/python/testData/refactoring/rename/googleDocStringReturnType.py new file mode 100644 index 000000000000..32edb863df24 --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringReturnType.py @@ -0,0 +1,8 @@ +class Foo: pass + +def func(foo): + """ + Returns: + Foo: ignored + """ + pass diff --git a/python/testData/refactoring/rename/googleDocStringReturnType_after.py b/python/testData/refactoring/rename/googleDocStringReturnType_after.py new file mode 100644 index 000000000000..5a134a5e0404 --- /dev/null +++ b/python/testData/refactoring/rename/googleDocStringReturnType_after.py @@ -0,0 +1,8 @@ +class Bar: pass + +def func(foo): + """ + Returns: + Bar: ignored + """ + pass diff --git a/python/testData/resolve/GoogleDocstringParamType.py b/python/testData/resolve/GoogleDocstringParamType.py new file mode 100644 index 000000000000..412dfbcf55db --- /dev/null +++ b/python/testData/resolve/GoogleDocstringParamType.py @@ -0,0 +1,8 @@ +from datetime import datetime + +def f(param): + """ + Parameters: + param (datetime) : timestamp + + """ \ No newline at end of file diff --git a/python/testData/resolve/GoogleDocstringReturnType.py b/python/testData/resolve/GoogleDocstringReturnType.py new file mode 100644 index 000000000000..038d93a6f89a --- /dev/null +++ b/python/testData/resolve/GoogleDocstringReturnType.py @@ -0,0 +1,10 @@ +class MyClass: + pass + + +def f(param): + """ + Returns: + MyClass : new instance of MyClass + + """ \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index 27c7558970b9..a616c64dcda2 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -23,6 +23,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.UsefulTestCase; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil; +import com.jetbrains.python.documentation.DocStringFormat; import com.jetbrains.python.fixtures.PyResolveTestCase; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyPsiUtils; @@ -508,6 +509,24 @@ public class PyResolveTest extends PyResolveTestCase { public void testReferenceInDocstring() { assertResolvesTo(PyClass.class, "datetime"); } + + // PY-9795 + public void testGoogleDocstringParamType() { + runWithDocStringFormat(DocStringFormat.GOOGLE, new Runnable() { + public void run() { + assertResolvesTo(PyClass.class, "datetime"); + } + }); + } + + // PY-9795 + public void testGoogleDocstringReturnType() { + runWithDocStringFormat(DocStringFormat.GOOGLE, new Runnable() { + public void run() { + assertResolvesTo(PyClass.class, "MyClass"); + } + }); + } // PY-7541 public void testLoopToUpperReassignment() { diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java index 9a7c151a08fa..864ce614b867 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java @@ -61,6 +61,8 @@ import com.intellij.util.IncorrectOperationException; import com.jetbrains.python.PythonHelpersLocator; import com.jetbrains.python.PythonLanguage; import com.jetbrains.python.PythonTestUtil; +import com.jetbrains.python.documentation.DocStringFormat; +import com.jetbrains.python.documentation.PyDocumentationSettings; import com.jetbrains.python.formatter.PyCodeStyleSettings; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyClass; @@ -185,6 +187,18 @@ public abstract class PyTestCase extends UsefulTestCase { } } + protected void runWithDocStringFormat(@NotNull DocStringFormat format, @NotNull Runnable runnable) { + final PyDocumentationSettings settings = PyDocumentationSettings.getInstance(myFixture.getModule()); + final DocStringFormat oldFormat = settings.getFormat(); + settings.setFormat(format); + try { + runnable.run(); + } + finally { + settings.setFormat(oldFormat); + } + } + /** * Searches for quickfix itetion by its class * diff --git a/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java b/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java index beb203f246fa..10ab4e6cf0ba 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java @@ -603,20 +603,8 @@ public class PyIntentionTest extends PyTestCase { doTest(PyBundle.message("INTN.convert.static.method.to.function")); } - private void doWithDocStringFormat(@NotNull DocStringFormat format, @NotNull Runnable runnable) { - final PyDocumentationSettings settings = PyDocumentationSettings.getInstance(myFixture.getModule()); - final DocStringFormat oldFormat = settings.getFormat(); - settings.setFormat(format); - try { - runnable.run(); - } - finally { - settings.setFormat(oldFormat); - } - } - private void doDocStubTest(@NotNull DocStringFormat format) { - doWithDocStringFormat(format, new Runnable() { + runWithDocStringFormat(format, new Runnable() { @Override public void run() { CodeInsightSettings.getInstance().JAVADOC_STUB_ON_ENTER = true; @@ -626,7 +614,7 @@ public class PyIntentionTest extends PyTestCase { } private void doDocReferenceTest(@NotNull DocStringFormat format) { - doWithDocStringFormat(format, new Runnable() { + runWithDocStringFormat(format, new Runnable() { public void run() { doTest(PyBundle.message("INTN.specify.type")); } @@ -634,7 +622,7 @@ public class PyIntentionTest extends PyTestCase { } private void doDocReturnTypeTest(@NotNull DocStringFormat format) { - doWithDocStringFormat(format, new Runnable() { + runWithDocStringFormat(format, new Runnable() { public void run() { doTest(PyBundle.message("INTN.specify.return.type")); } diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java index fe170b8d4df0..7e17d3f9b59b 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement; import com.intellij.refactoring.BaseRefactoringProcessor; import com.intellij.testFramework.PlatformTestUtil; import com.jetbrains.python.PythonTestUtil; +import com.jetbrains.python.documentation.DocStringFormat; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.LanguageLevel; @@ -200,6 +201,34 @@ public class PyRenameTest extends PyTestCase { doTest("bar"); } + // PY-9795 + public void testGoogleDocStringParam() { + renameWithDocStringFormat("bar"); + } + + // PY-9795 + public void testGoogleDocStringAttribute() { + renameWithDocStringFormat("bar"); + } + + // PY-9795 + public void testGoogleDocStringParamType() { + renameWithDocStringFormat("Bar"); + } + + // PY-9795 + public void testGoogleDocStringReturnType() { + renameWithDocStringFormat("Bar"); + } + + private void renameWithDocStringFormat(final String newName) { + runWithDocStringFormat(DocStringFormat.GOOGLE, new Runnable() { + public void run() { + doTest(newName); + } + }); + } + private void doRenameConflictTest(String newName, String expectedConflict) { myFixture.configureByFile(RENAME_DATA_PATH + getTestName(true) + ".py"); try {