diff --git a/python/build/pycharm_build.gant b/python/build/pycharm_build.gant index 6e01a350fc51..2f70b699905f 100644 --- a/python/build/pycharm_build.gant +++ b/python/build/pycharm_build.gant @@ -329,7 +329,7 @@ private layoutFull(Map args, String target, Set usedJars) { } jar("pycharm-openapi-src.zip") { fileset(dir: "$pythonCommunityHome/openapi/src") - fileset(dir: "$pythonCommunityHome/python/psi-api/src") + fileset(dir: "$pythonCommunityHome/psi-api/src") } } } diff --git a/python/build/pycharm_community_build.gant b/python/build/pycharm_community_build.gant index f1b56a81bada..c2ddd0eab8f5 100644 --- a/python/build/pycharm_community_build.gant +++ b/python/build/pycharm_community_build.gant @@ -308,7 +308,11 @@ private layoutFull(Map args, String target, Set usedJars) { } dir("license") { - fileset(dir: "$home/community/license") + fileset(dir: "$ch/license") + fileset(dir: "$ch") { + include(name: "LICENSE.txt") + include(name: "NOTICE.txt") + } } layoutPlugins(superLayouts) diff --git a/python/build/python_common.gant b/python/build/python_common.gant index 8a0a93f952e0..10bcc809fd83 100644 --- a/python/build/python_common.gant +++ b/python/build/python_common.gant @@ -15,7 +15,7 @@ private List listTopLevelModules(String root) { binding.setVariable("buildDebuggerEgg", {String sandbox, String pythonHome, String buildName -> return buildEgg(sandbox, pythonHome, buildName, "pycharm-debug", { - ant.fileset(dir: "$pythonHome/helpers/pydev") { + ant.fileset(dir: "$pythonHome/community/helpers/pydev") { include(name: "**/*.py") } }) @@ -23,7 +23,7 @@ binding.setVariable("buildDebuggerEgg", {String sandbox, String pythonHome, Stri binding.setVariable("buildDebuggerEggPy3K", {String sandbox, String pythonHome, String buildName -> return buildEgg(sandbox, pythonHome, buildName, "pycharm-debug-py3k") { - ant.fileset(dir: "$pythonHome/helpers/pydev") { + ant.fileset(dir: "$pythonHome/community/helpers/pydev") { include(name: "**/*.py") exclude(name:"**/_pydev_BaseHTTPServer.py") exclude(name:"**/_pydev_SimpleXMLRPCServer.py") diff --git a/python/build/python_plugin_build.gant b/python/build/python_plugin_build.gant index 9af44d3659f3..a1215f64dcaa 100644 --- a/python/build/python_plugin_build.gant +++ b/python/build/python_plugin_build.gant @@ -1,13 +1,12 @@ import static org.jetbrains.jps.idea.IdeaProjectLoader.guessHome setProperty("projectHome", guessHome(this as Script)) +setProperty("home", projectHome) includeTargets << new File("${projectHome}/community/build/scripts/utils.gant") -includeTargets << new File("${projectHome}/python/build/python_common.gant") -setProperty("contribHome", "${projectHome}/contrib") setProperty("outDir", "${projectHome}/out/python") -setProperty("ideaDir", "${outDir}/idea") +setProperty("ideaDir", "${outDir}/ideaCE") setProperty("ideaHome", "${ideaDir}/jdk16") //compiled idea @@ -16,35 +15,25 @@ setProperty("pluginHelp", "${outDir}/help") setProperty("buildNumber", requireProperty("build.number", snapshot)) setProperty("ideaBuildNumber", requireProperty("idea.build.number")) -setProperty("pluginHome", "${projectHome}/python") +setProperty("pluginHome", "${projectHome}/python/community") setProperty("pluginRevision", "${buildNumber}") setProperty("ideaLib", "${ideaHome}/lib") setProperty("ideaPlugins", "${ideaHome}/plugins") //compiled plugins -setProperty("output", "${projectHome}/python/dist") +setProperty("output", "${projectHome}/python/distCE") setProperty("zipdir", "${output}/zip") setProperty("plugindir", "${zipdir}/python") -setProperty("zipname", "python-${pluginRevision}.zip") +setProperty("zipname", "python-community-${pluginRevision}.zip") setProperty("srcDir", "${pluginHome}/src") -setProperty("restSrcDir", "${pluginHome}/community/rest/src") -setProperty("localizationSrcDir", "${pluginHome}/localization/src") setProperty("resourcesDir", "${pluginHome}/resources") -setProperty("restResourcesDir", "${pluginHome}/rest/resources") -setProperty("localizationResourcesDir", "${pluginHome}/localization/resources") -setProperty("pluginResourcesDir", "${pluginHome}/pluginResources") setProperty("classesRootDir", "${outDir}/classes") setProperty("classesDir", "${classesRootDir}/python") -setProperty("restClassesDir", "${classesRootDir}/rest") -setProperty("localizationClassesDir", "${classesRootDir}/localization") - -setProperty("restJarName", "${output}/rest-${buildNumber}.jar") -setProperty("localizationJarName", "${output}/localization-${buildNumber}.jar") //Compiler options setProperty("compilerDebug", "on") @@ -70,10 +59,6 @@ ant.patternset(id: "resources.pt") { exclude(name: "**/plugin.xml") } -def connectorPlugins = ["django-db-config", "python-javascript-debugger", "python-uml", "python-localization", "python-rest", - "python-remote-interpreter"] -def contribPlugins = ["pycharm-flask", "pycharm-numpy"] - target(name: "clean", description: "Cleanup output") { ant.echo("Cleaning ${output}") ant.delete(dir: "${output}", failonerror: "false") @@ -85,188 +70,19 @@ target(name: "clean", description: "Cleanup output") { target(name: "unzip") { ant.mkdir(dir: "${ideaHome}") - ant.unzip(src: "${ideaDir}/ideaIU-${ideaBuildNumber}.zip", dest: "${ideaHome}") + ant.unzip(src: "${ideaDir}/ideaIC-${ideaBuildNumber}.win.zip", dest: "${ideaHome}") } -def patchPluginXml(path) { - ant.replaceregexp(file: path, - match: "since-build=\"\\d+\\.\\d+\"", - replace: "since-build=\"${ideaBuildNumber}\"") - ant.replaceregexp(file: path, - match: "\\d+\\.SNAPSHOT", - replace: "${ideaBuildNumber}") - -} - -target(name: "compileRest", description: "Compile module rest") { - depends("unzip") - ant.path(id: "classpath.lib") { - fileset(dir: "${ideaLib}") { - include(name: "?*.jar") - } - } - - //The task requires the following libraries from IntelliJ IDEA distribution: - //javac2.jar; jdom.jar; asm.jar; asm-commons.jar - ant.taskdef(name: "javac2", classname: "com.intellij.ant.Javac2") { - classpath(refid: "classpath.lib") - } - - ant.mkdir(dir: "${restClassesDir}") - - //compile - ant.javac2(destdir: "${restClassesDir}", - debug: "${compilerDebug}", - nowarn: "${compilerGenerateNoWarnings}", - memorymaximumsize: "${compilerMaxMemory}", - fork: "true") { - compilerarg(line: "${compilerArgs}") - classpath(refid: "classpath.lib") - src { - pathelement(location: "${restSrcDir}") - } - } - - //copy resources - ant.copy(todir: "${restClassesDir}") { - fileset(dir: "${restSrcDir}") { - patternset(refid: "resources.pt") - type(type: "file") - } - } - ant.copy(todir: "${restClassesDir}") { - fileset(dir: "${restResourcesDir}") { - patternset(refid: "resources.pt") - type(type: "file") - } - } - - //copy plugin.xml - ant.mkdir(dir: "${restClassesDir}/META-INF") - ant.copy(todir: "${restClassesDir}/META-INF") { - fileset(dir: "${pluginHome}/rest/resources/META-INF") - } - - patchPluginXml("${restClassesDir}/META-INF/plugin.xml") -} - -target(name: "jarRest", description: "Generate jar file for ReST plugin") { - depends("compileRest") - ant.mkdir(dir: "${output}") - ant.jar(destfile: "${restJarName}", basedir: "${restClassesDir}") { - manifest() { - attribute(name: "Revision", value: "${pluginRevision}") - // - } - } -} - -target(name: "compileLocalization", description: "Compile module localization") { - depends("unzip") - ant.path(id: "classpath.lib") { - fileset(dir: "${ideaLib}") { - include(name: "?*.jar") - } - } - - ant.path(id: "sourcepath") { - dirset(dir: "${pluginHome}") { - include(name: "localization/src") - } - } - //The task requires the following libraries from IntelliJ IDEA distribution: - //javac2.jar; jdom.jar; asm.jar; asm-commons.jar - ant.taskdef(name: "javac2", classname: "com.intellij.ant.Javac2") { - classpath(refid: "classpath.lib") - } - - ant.mkdir(dir: "${localizationClassesDir}") - - //compile - ant.javac2(destdir: "${localizationClassesDir}", - debug: "${compilerDebug}", - nowarn: "${compilerGenerateNoWarnings}", - memorymaximumsize: "${compilerMaxMemory}", - fork: "true") { - compilerarg(line: "${compilerArgs}") - classpath(refid: "classpath.lib") - src { - pathelement(location: "${localizationSrcDir}") - } - } - - //copy resources - ant.copy(todir: "${localizationClassesDir}") { - fileset(dir: "${localizationSrcDir}") { - patternset(refid: "resources.pt") - type(type: "file") - } - } - ant.copy(todir: "${localizationClassesDir}") { - fileset(dir: "${localizationResourcesDir}") { - patternset(refid: "resources.pt") - type(type: "file") - } - } - - //copy plugin.xml - ant.mkdir(dir: "${localizationClassesDir}/META-INF") - ant.copy(todir: "${localizationClassesDir}/META-INF") { - fileset(dir: "${pluginHome}/localization/resources/META-INF") - } - - patchPluginXml("${localizationClassesDir}/META-INF/plugin.xml") -} - -target(name: "jarLocalization", description: "Generate jar file for localization plugin") { - depends("compileLocalization") - ant.mkdir(dir: "${output}") - ant.jar(destfile: "${localizationJarName}", basedir: "${localizationClassesDir}") { - manifest() { - attribute(name: "Revision", value: "${pluginRevision}") - // - } - } -} - - target(name: "compile", description: "Compile module python") { depends("unzip") - depends("jarRest") - depends("jarLocalization") ant.path(id: "classpath.lib") { fileset(dir: "${ideaLib}") { include(name: "?*.jar") } - fileset(dir: "${ideaPlugins}/yaml/lib") { - include(name: "yaml.jar") - } - fileset(dir: "${ideaPlugins}/coverage/lib") { - include(name: "coverage.jar") - include(name: "coverage-agent.jar") - } - fileset(dir: "${ideaPlugins}/JavaScriptDebugger/lib") { - include(name: "JavaScriptDebugger.jar") - } - fileset(dir: "${ideaPlugins}/webDeployment/lib") { - include(name: "webDeployment.jar") - include(name: "commons-vfs*.jar") - } - fileset(dir: "${ideaPlugins}/uml/lib") { - include(name: "*.jar") - } - fileset(dir: "${ideaPlugins}/DatabaseSupport/lib") { - include(name: "*.jar") - } - fileset(dir: "${ideaPlugins}/remote-run/lib") { - include(name: "*.jar") - } fileset(dir: "${ideaPlugins}/terminal/lib") { include(name: "*.jar") } - pathelement(location: restJarName) - pathelement(location: localizationJarName) } ant.path(id: "sourcepath") { @@ -274,19 +90,10 @@ target(name: "compile", description: "Compile module python") { include(name: "resources") include(name: "src") include(name: "pluginSrc") - include(name: "community/pydevSrc") - include(name: "community/openapi/src") - include(name: "community/psi-api/src") - include(name: "community/src") - include(name: "pluginResources") + include(name: "pydevSrc") + include(name: "openapi/src") + include(name: "psi-api/src") } - connectorPlugins.each { - pathelement(location: "${pluginHome}/${it}/src") - } - contribPlugins.each { - pathelement(location: "${contribHome}/${it}/src") - } - pathelement(location: "${pluginHome}/../ultimate/ultimate-verifier/src") } //The task requires the following libraries from IntelliJ IDEA distribution: //javac2.jar; jdom.jar; asm.jar; asm-commons.jar @@ -317,46 +124,26 @@ target(name: "compile", description: "Compile module python") { patternset(refid: "resources.pt") type(type: "file") } - fileset(dir: "${pluginResourcesDir}") { - patternset(refid: "resources.pt") - type(type: "file") - } fileset(dir: "${pluginHome}/src") { patternset(refid: "resources.pt") type(type: "file") } - fileset(dir: "${pluginHome}/community/psi-api/resources") { + fileset(dir: "${pluginHome}/psi-api/resources") { patternset(refid: "resources.pt") type(type: "file") } - fileset(dir: "${pluginHome}/community/src") { + fileset(dir: "${pluginHome}/resources") { patternset(refid: "resources.pt") type(type: "file") } - fileset(dir: "${pluginHome}/community/resources") { - patternset(refid: "resources.pt") - type(type: "file") - } - connectorPlugins.each { - fileset(dir: "${pluginHome}/${it}/resources") { - patternset(refid: "resources.pt") - type(type: "file") - } - } - contribPlugins.each { - fileset(dir: "${contribHome}/${it}/resources") { - patternset(refid: "resources.pt") - type(type: "file") - } - } - fileset(dir: "${pluginHome}/../community/colorSchemes/src") + fileset(dir: "${pluginHome}/../../community/colorSchemes/src") } //copy plugin.xml ant.mkdir(dir: "${classesDir}/META-INF") ant.copy(todir: "${classesDir}/META-INF") { - fileset(file: "${pluginHome}/pluginSrc/META-INF/plugin.xml") - fileset(file: "${pluginHome}/build/python-plugin-dependencies.xml") + fileset(file: "${pluginHome}/pluginSrc/META-INF/*.xml") + fileset(file: "${pluginHome}/pluginResources/META-INF/*.xml") } ant.replaceregexp(file: "${classesDir}/META-INF/plugin.xml", @@ -367,7 +154,7 @@ target(name: "compile", description: "Compile module python") { target(name: "jar", description: "Generate jar file") { depends("compile") ant.mkdir(dir: "${output}") - ant.jar(destfile: "${output}/python.jar", basedir: "${classesDir}") { + ant.jar(destfile: "${output}/python-community.jar", basedir: "${classesDir}") { manifest() { attribute(name: "Revision", value: "${pluginRevision}") // @@ -382,11 +169,11 @@ target(name: "zip", description: "Generate zip plugin file") { // copy plugin jar ant.mkdir(dir: "${plugindir}/lib") - ant.move(file: "${output}/python.jar", todir: "${plugindir}/lib") + ant.move(file: "${output}/python-community.jar", todir: "${plugindir}/lib") ant.mkdir(dir: "${plugindir}/helpers") ant.copy(todir: "${plugindir}/helpers") { - fileset(dir: "${pluginHome}/community/helpers") { + fileset(dir: "${pluginHome}/helpers") { include(name: "**/*") } } @@ -395,19 +182,12 @@ target(name: "zip", description: "Generate zip plugin file") { ant.copy(file: "${pluginHelp}/pytonpluginhelp.jar", tofile: "${plugindir}/help/pythonpluginhelp.jar") ant.copy(file: "${pluginHelp}/pytonpluginhelp_mac.jar", tofile: "${plugindir}/help/pythonpluginhelp_mac.jar") - ant.move(file: "${debugEgg}", todir: "${plugindir}") - ant.move(file: "${debugEggPy3K}", todir: "${plugindir}") - ant.zip(basedir: "${zipdir}", destfile: "${output}/${zipname}") } target(name: "build") { depends("unzip") depends("compile") - egg = buildDebuggerEgg(outDir, pluginHome, "PythonPlugin-${buildNumber}") - setProperty("debugEgg", "$egg") - egg = buildDebuggerEggPy3K(outDir, pluginHome, "PythonPlugin-${buildNumber}") - setProperty("debugEggPy3K", "$egg") } target(name: "dist", description: "main target") { diff --git a/python/ide/python-ide-community.iml b/python/ide/python-ide-community.iml index 0ec9c8325478..9cfa2aa868d5 100644 --- a/python/ide/python-ide-community.iml +++ b/python/ide/python-ide-community.iml @@ -5,9 +5,6 @@ - - - diff --git a/python/layout.xml b/python/layout.xml index 2b35430d16b3..6510cf902497 100644 --- a/python/layout.xml +++ b/python/layout.xml @@ -20,6 +20,7 @@ + @@ -28,10 +29,10 @@ - - + + - \ No newline at end of file + diff --git a/python/pluginResources/META-INF/plugin.xml b/python/pluginResources/META-INF/plugin.xml new file mode 100644 index 000000000000..ab57b46eb7c9 --- /dev/null +++ b/python/pluginResources/META-INF/plugin.xml @@ -0,0 +1,16 @@ + + + + PythonCore + Python Community Edition + + Smart editing for Python scripts + 3.0 + com.intellij.modules.java + + + JetBrains, Keith Lea + + + diff --git a/python/pluginSrc/META-INF/plugin.xml b/python/pluginSrc/META-INF/plugin.xml index 9b613f34176d..1a3ada2d8ffe 100644 --- a/python/pluginSrc/META-INF/plugin.xml +++ b/python/pluginSrc/META-INF/plugin.xml @@ -1,12 +1,12 @@ - + Pythonid Python Smart editing for Python scripts - 2.11.2 + 3.0 com.intellij.modules.ultimate com.intellij.modules.java Coverage @@ -17,6 +17,7 @@ + + + + + + + + + + + + + + + + + + + + + + + com.jetbrains.python.facet.PythonSdkTableListener + + + + + + com.jetbrains.python.facet.PythonFacetListener + + + + + + + + + + \ No newline at end of file diff --git a/python/pluginSrc/com/jetbrains/python/PythonFileTypeFactory.java b/python/pluginSrc/com/jetbrains/python/PythonFileTypeFactory.java deleted file mode 100644 index 0075ce121406..000000000000 --- a/python/pluginSrc/com/jetbrains/python/PythonFileTypeFactory.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.jetbrains.python; - -import com.intellij.ide.highlighter.XmlFileType; -import com.intellij.openapi.fileTypes.FileTypeConsumer; -import com.intellij.openapi.fileTypes.FileTypeFactory; -import com.intellij.ultimate.PluginVerifier; -import com.intellij.ultimate.UltimateVerifier; -import com.jetbrains.pyqt.QtUIFileType; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -/** - * Plugin version of file type factory - uses UltimateVerifier. - * - * @author yole - */ -public class PythonFileTypeFactory extends FileTypeFactory { - public PythonFileTypeFactory(UltimateVerifier verifier) { - PluginVerifier.verifyUltimatePlugin(verifier); - } - - public void createFileTypes(@NonNls @NotNull final FileTypeConsumer consumer) { - consumer.consume(PythonFileType.INSTANCE, "py;pyw;"); - consumer.consume(QtUIFileType.INSTANCE, "ui"); - consumer.consume(XmlFileType.INSTANCE, "qrc"); - } -} diff --git a/python/python-community.iml b/python/python-community.iml index a3b4304fdda2..06515d2fa936 100644 --- a/python/python-community.iml +++ b/python/python-community.iml @@ -16,11 +16,12 @@ - + + diff --git a/python/python-ide.iml b/python/python-ide.iml index 08f4987ff1c8..b1c3c129ab68 100644 --- a/python/python-ide.iml +++ b/python/python-ide.iml @@ -5,6 +5,9 @@ + + + diff --git a/python/resources/PyCharmCore13.png b/python/resources/PyCharmCore13.png new file mode 100644 index 000000000000..de135e7f6a90 Binary files /dev/null and b/python/resources/PyCharmCore13.png differ diff --git a/python/resources/idea/PyCharmCoreApplicationInfo.xml b/python/resources/idea/PyCharmCoreApplicationInfo.xml index 03a666646adf..851372bfedd9 100644 --- a/python/resources/idea/PyCharmCoreApplicationInfo.xml +++ b/python/resources/idea/PyCharmCoreApplicationInfo.xml @@ -4,7 +4,7 @@ - + diff --git a/python/src/META-INF/PyCharmCorePlugin.xml b/python/src/META-INF/PyCharmCorePlugin.xml index a94573141fb5..a250bdc539d7 100644 --- a/python/src/META-INF/PyCharmCorePlugin.xml +++ b/python/src/META-INF/PyCharmCorePlugin.xml @@ -1,4 +1,4 @@ - + diff --git a/python/src/META-INF/python-plugin-core.xml b/python/src/META-INF/python-core.xml similarity index 99% rename from python/src/META-INF/python-plugin-core.xml rename to python/src/META-INF/python-core.xml index 42f8bb100ebf..241b3df18185 100644 --- a/python/src/META-INF/python-plugin-core.xml +++ b/python/src/META-INF/python-core.xml @@ -668,6 +668,10 @@ text="Generate Python Spellchecker Dictionaries" internal="true"> + + + + diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml index fffc3af78434..8b684343d9b5 100644 --- a/python/src/META-INF/python-plugin-common.xml +++ b/python/src/META-INF/python-plugin-common.xml @@ -1,7 +1,7 @@ - + @@ -226,6 +226,8 @@ + + @@ -458,18 +460,7 @@ - - - com.jetbrains.django.lang.template.DjangoTemplatePsiManager - - - - - - - - diff --git a/python/src/com/jetbrains/python/PythonDialectsTokenSetProvider.java b/python/src/com/jetbrains/python/PythonDialectsTokenSetProvider.java index 34bb3263dc36..63245a572980 100644 --- a/python/src/com/jetbrains/python/PythonDialectsTokenSetProvider.java +++ b/python/src/com/jetbrains/python/PythonDialectsTokenSetProvider.java @@ -9,7 +9,7 @@ import com.intellij.psi.tree.TokenSet; * @author vlan */ public class PythonDialectsTokenSetProvider { - public static final PythonDialectsTokenSetProvider INSTANCE = new PythonDialectsTokenSetProvider(); + public static PythonDialectsTokenSetProvider INSTANCE = new PythonDialectsTokenSetProvider(); private final TokenSet myStatementTokens; private final TokenSet myExpressionTokens; @@ -104,4 +104,8 @@ public class PythonDialectsTokenSetProvider { public TokenSet getReferenceExpressionTokens() { return myReferenceExpressionTokens; } + + public static void reset() { + INSTANCE = new PythonDialectsTokenSetProvider(); + } } diff --git a/python/ide/src/com/jetbrains/python/PythonFileTypeFactory.java b/python/src/com/jetbrains/python/PythonFileTypeFactory.java similarity index 89% rename from python/ide/src/com/jetbrains/python/PythonFileTypeFactory.java rename to python/src/com/jetbrains/python/PythonFileTypeFactory.java index 25a2ecc42ad4..937a006ded6e 100644 --- a/python/ide/src/com/jetbrains/python/PythonFileTypeFactory.java +++ b/python/src/com/jetbrains/python/PythonFileTypeFactory.java @@ -8,8 +8,6 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; /** - * IDE version of file type factory - does not use UltimateVerifier. - * * @author yole */ public class PythonFileTypeFactory extends FileTypeFactory { diff --git a/python/src/com/jetbrains/python/PythonModuleTypeBase.java b/python/src/com/jetbrains/python/PythonModuleTypeBase.java index e7ebc4923613..5bfbcdc8bc9e 100644 --- a/python/src/com/jetbrains/python/PythonModuleTypeBase.java +++ b/python/src/com/jetbrains/python/PythonModuleTypeBase.java @@ -1,6 +1,8 @@ package com.jetbrains.python; +import com.intellij.facet.FacetType; import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.ModuleType; import com.intellij.openapi.module.ModuleTypeManager; import icons.PythonIcons; @@ -30,7 +32,14 @@ public abstract class PythonModuleTypeBase extends Modu @NotNull public String getDescription() { - return "Python modules are used for developing Python applications. Supported technologies include Django, Google App Engine, Mako, Jinja2 and others."; + String basicDescription = "Python modules are used for developing Python applications."; + FacetType[] facetTypes = Extensions.getExtensions(FacetType.EP_NAME); + for (FacetType type : facetTypes) { + if (type.getId().toString().equalsIgnoreCase("django")) { + return basicDescription + " Supported technologies include Django, Google App Engine, Mako, Jinja2 and others."; + } + } + return basicDescription; } public Icon getBigIcon() { diff --git a/python/src/com/jetbrains/python/codeInsight/userSkeletons/PyUserSkeletonsUtil.java b/python/src/com/jetbrains/python/codeInsight/userSkeletons/PyUserSkeletonsUtil.java index 00864f3239e3..4a59ac3f2598 100644 --- a/python/src/com/jetbrains/python/codeInsight/userSkeletons/PyUserSkeletonsUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/userSkeletons/PyUserSkeletonsUtil.java @@ -44,7 +44,7 @@ public class PyUserSkeletonsUtil { final List result = new ArrayList(); result.add(PathManager.getConfigPath() + File.separator + USER_SKELETONS_DIR); result.add(ApplicationManager.getApplication().isInternal() - ? StringUtil.join(new String[]{PathManager.getHomePath(), "python", "helpers", USER_SKELETONS_DIR}, File.separator) + ? StringUtil.join(new String[]{PathManager.getHomePath(), "python", "community", "helpers", USER_SKELETONS_DIR}, File.separator) : PythonHelpersLocator.getHelperPath(USER_SKELETONS_DIR)); return result; } @@ -53,7 +53,7 @@ public class PyUserSkeletonsUtil { public static VirtualFile getUserSkeletonsDirectory() { if (ourUserSkeletonsDirectory == null) { for (String path : getPossibleUserSkeletonsPaths()) { - ourUserSkeletonsDirectory = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); + ourUserSkeletonsDirectory = LocalFileSystem.getInstance().findFileByPath(path); if (ourUserSkeletonsDirectory != null) { break; } diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index ff563cd79988..8416a3627f91 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -176,6 +176,21 @@ public class PyCallExpressionHelper { else if (PyNames.STATICMETHOD.equals(wrapper_name)) wrappedModifier = PyFunction.Modifier.STATICMETHOD; } } + final List qualifiers = resolveResult != null ? resolveResult.getQualifiers() : Collections.emptyList(); + final TypeEvalContext context = resolveContext.getTypeEvalContext(); + if (resolved instanceof PyFunction) { + final PyFunction function = (PyFunction)resolved; + final Property property = function.getProperty(); + if (property != null && isQualifiedByInstance(function, qualifiers, context)) { + final PyType type = function.getReturnType(context, null); + if (type instanceof PyFunctionType) { + resolved = ((PyFunctionType)type).getCallable(); + } + else { + resolved = null; + } + } + } if (resolved instanceof Callable) { PyFunction.Modifier modifier = resolved instanceof PyFunction ? ((PyFunction)resolved).getModifier() @@ -183,12 +198,10 @@ public class PyCallExpressionHelper { if (modifier == null && wrappedModifier != null) { modifier = wrappedModifier; } - List qualifiers = resolveResult != null ? resolveResult.getQualifiers() : Collections.emptyList(); - boolean isByInstance = isConstructorCall || - isQualifiedByInstance((Callable)resolved, qualifiers, resolveContext.getTypeEvalContext()) - || resolved instanceof PyBoundFunction; + boolean isByInstance = isConstructorCall || isQualifiedByInstance((Callable)resolved, qualifiers, context) + || resolved instanceof PyBoundFunction; PyExpression lastQualifier = qualifiers != null && qualifiers.isEmpty() ? null : qualifiers.get(qualifiers.size()-1); - boolean isByClass = lastQualifier == null ? false : isQualifiedByClass((Callable)resolved, lastQualifier, resolveContext.getTypeEvalContext()); + boolean isByClass = lastQualifier == null ? false : isQualifiedByClass((Callable)resolved, lastQualifier, context); final Callable callable = (Callable)resolved; implicitOffset += getImplicitArgumentCount(callable, modifier, isConstructorCall, isByInstance, isByClass); @@ -408,6 +421,12 @@ public class PyCallExpressionHelper { if (t != null && !(t instanceof PyNoneType)) { return t; } + if (cls != null && t == null) { + final PyFunction newMethod = cls.findMethodByName(PyNames.NEW, true); + if (newMethod != null && !PyBuiltinCache.getInstance(call).hasInBuiltins(newMethod)) { + return PyUnionType.createWeakType(new PyClassTypeImpl(cls, false)); + } + } } if (cls != null) { return new PyClassTypeImpl(cls, false); diff --git a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java index f3b2043003ea..22678d6bc80c 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyNamedParameterImpl.java @@ -165,7 +165,26 @@ public class PyNamedParameterImpl extends PyPresentableElementImpl) +c.f(1, 2, 3) diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/CustomNewReturnInAnotherModule/a.py b/python/testData/inspections/PyUnresolvedReferencesInspection/CustomNewReturnInAnotherModule/a.py new file mode 100644 index 000000000000..5e6d4a745397 --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/CustomNewReturnInAnotherModule/a.py @@ -0,0 +1,4 @@ +from b import C + +c = C() +c.foo() diff --git a/python/testData/inspections/PyUnresolvedReferencesInspection/CustomNewReturnInAnotherModule/b.py b/python/testData/inspections/PyUnresolvedReferencesInspection/CustomNewReturnInAnotherModule/b.py new file mode 100644 index 000000000000..16af06a7831e --- /dev/null +++ b/python/testData/inspections/PyUnresolvedReferencesInspection/CustomNewReturnInAnotherModule/b.py @@ -0,0 +1,8 @@ +class C(object): + def __new__(cls): + return D() + + +class D(object): + def foo(self): + pass diff --git a/python/testSrc/com/jetbrains/python/quickFixes/AddFieldQuickFixTest.java b/python/testSrc/com/jetbrains/python/AddFieldQuickFixTest.java similarity index 92% rename from python/testSrc/com/jetbrains/python/quickFixes/AddFieldQuickFixTest.java rename to python/testSrc/com/jetbrains/python/AddFieldQuickFixTest.java index a337e38e10d5..8c48d7f6a44a 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/AddFieldQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/AddFieldQuickFixTest.java @@ -1,6 +1,5 @@ -package com.jetbrains.python.quickFixes; +package com.jetbrains.python; -import com.jetbrains.python.PyBundle; import com.jetbrains.python.inspections.PyUnresolvedReferencesInspection; /** diff --git a/python/testSrc/com/jetbrains/python/quickFixes/AddMethodQuickFixTest.java b/python/testSrc/com/jetbrains/python/AddMethodQuickFixTest.java similarity index 93% rename from python/testSrc/com/jetbrains/python/quickFixes/AddMethodQuickFixTest.java rename to python/testSrc/com/jetbrains/python/AddMethodQuickFixTest.java index 01d97615b242..b411feb3ecbc 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/AddMethodQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/AddMethodQuickFixTest.java @@ -1,6 +1,5 @@ -package com.jetbrains.python.quickFixes; +package com.jetbrains.python; -import com.jetbrains.python.PyBundle; import com.jetbrains.python.inspections.PyClassHasNoInitInspection; import com.jetbrains.python.inspections.PyUnresolvedReferencesInspection; diff --git a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java index fabbdfc8c772..9df7f57bd5a9 100644 --- a/python/testSrc/com/jetbrains/python/Py3ResolveTest.java +++ b/python/testSrc/com/jetbrains/python/Py3ResolveTest.java @@ -4,6 +4,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.testFramework.LightProjectDescriptor; import com.jetbrains.python.fixtures.PyResolveTestCase; +import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyFunction; import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; @@ -14,13 +15,13 @@ import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; public class Py3ResolveTest extends PyResolveTestCase { @Override protected LightProjectDescriptor getProjectDescriptor() { - return ourPy3Descriptor; + return PyTestCase.ourPy3Descriptor; } @Override protected PsiElement doResolve() { myFixture.configureByFile("resolve/" + getTestName(false) + ".py"); - final PsiReference ref = findReferenceByMarker(myFixture.getFile()); + final PsiReference ref = PyResolveTestCase.findReferenceByMarker(myFixture.getFile()); return ref.resolve(); } diff --git a/python/testSrc/com/jetbrains/python/PyAssignmentMappingTest.java b/python/testSrc/com/jetbrains/python/PyAssignmentMappingTest.java index e4fd31e4bb51..8cc69b766250 100644 --- a/python/testSrc/com/jetbrains/python/PyAssignmentMappingTest.java +++ b/python/testSrc/com/jetbrains/python/PyAssignmentMappingTest.java @@ -7,6 +7,7 @@ import com.jetbrains.python.psi.PyAssignmentStatement; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PySubscriptionExpression; import com.jetbrains.python.psi.PyTargetExpression; +import junit.framework.Assert; import java.util.List; import java.util.Map; @@ -26,134 +27,134 @@ public class PyAssignmentMappingTest extends LightMarkedTestCase { public void testSimple() throws Exception { Map marks = loadTest(); - assertEquals(2, marks.size()); + Assert.assertEquals(2, marks.size()); PsiElement src = marks.get("").getParent(); // const -> expr; PsiElement dst = marks.get("").getParent(); // ident -> target expr - assertTrue(dst instanceof PyTargetExpression); + Assert.assertTrue(dst instanceof PyTargetExpression); PyAssignmentStatement stmt = (PyAssignmentStatement)dst.getParent(); List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(1, mapping.size()); + Assert.assertEquals(1, mapping.size()); Pair pair = mapping.get(0); - assertEquals(dst, pair.getFirst()); - assertEquals(src, pair.getSecond()); + Assert.assertEquals(dst, pair.getFirst()); + Assert.assertEquals(src, pair.getSecond()); } public void testSubscribedSource() throws Exception { Map marks = loadTest(); - assertEquals(2, marks.size()); + Assert.assertEquals(2, marks.size()); PsiElement src = marks.get("").getParent().getParent(); // const -> ref foo -> subscr expr; PsiElement dst = marks.get("").getParent(); // ident -> target expr - assertTrue(dst instanceof PyTargetExpression); + Assert.assertTrue(dst instanceof PyTargetExpression); PyAssignmentStatement stmt = (PyAssignmentStatement)dst.getParent(); List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(1, mapping.size()); + Assert.assertEquals(1, mapping.size()); Pair pair = mapping.get(0); - assertEquals(dst, pair.getFirst()); - assertEquals(src, pair.getSecond()); + Assert.assertEquals(dst, pair.getFirst()); + Assert.assertEquals(src, pair.getSecond()); } public void testSubscribedTarget() throws Exception { Map marks = loadTest(); - assertEquals(2, marks.size()); + Assert.assertEquals(2, marks.size()); PsiElement src = marks.get("").getParent(); // const -> expr; PsiElement dst = marks.get("").getParent().getParent(); // ident -> target expr - assertTrue(dst instanceof PySubscriptionExpression); + Assert.assertTrue(dst instanceof PySubscriptionExpression); PyAssignmentStatement stmt = (PyAssignmentStatement)src.getParent(); List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(1, mapping.size()); + Assert.assertEquals(1, mapping.size()); Pair pair = mapping.get(0); - assertEquals(dst, pair.getFirst()); - assertEquals(src, pair.getSecond()); + Assert.assertEquals(dst, pair.getFirst()); + Assert.assertEquals(src, pair.getSecond()); } public void testMultiple() throws Exception { Map marks = loadTest(); final int TARGET_NUM = 3; - assertEquals(TARGET_NUM+1, marks.size()); + Assert.assertEquals(TARGET_NUM + 1, marks.size()); PsiElement src = marks.get("").getParent(); // const -> expr; PsiElement[] dsts = new PsiElement[TARGET_NUM]; for (int i=0; i").getParent(); // ident -> target expr - assertTrue(dst instanceof PyTargetExpression); + Assert.assertTrue(dst instanceof PyTargetExpression); dsts[i] = dst; } PyAssignmentStatement stmt = (PyAssignmentStatement)src.getParent(); List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(TARGET_NUM, mapping.size()); + Assert.assertEquals(TARGET_NUM, mapping.size()); for (int i=0; i pair = mapping.get(i); - assertEquals(dsts[i], pair.getFirst()); - assertEquals(src, pair.getSecond()); + Assert.assertEquals(dsts[i], pair.getFirst()); + Assert.assertEquals(src, pair.getSecond()); } } public void testTupleMapped() throws Exception { Map marks = loadTest(); final int PAIR_NUM = 2; - assertEquals(PAIR_NUM*2, marks.size()); + Assert.assertEquals(PAIR_NUM * 2, marks.size()); PsiElement[] srcs = new PsiElement[PAIR_NUM]; PsiElement[] dsts = new PsiElement[PAIR_NUM]; for (int i=0; i").getParent(); // ident -> target expr - assertTrue(dst instanceof PyTargetExpression); + Assert.assertTrue(dst instanceof PyTargetExpression); dsts[i] = dst; PsiElement src = marks.get("").getParent(); // ident -> target expr - assertTrue(src instanceof PyExpression); + Assert.assertTrue(src instanceof PyExpression); srcs[i] = src; } PyAssignmentStatement stmt = (PyAssignmentStatement)srcs[0].getParent().getParent(); // tuple expr -> assignment List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(PAIR_NUM, mapping.size()); + Assert.assertEquals(PAIR_NUM, mapping.size()); for (int i=0; i pair = mapping.get(i); - assertEquals(dsts[i], pair.getFirst()); - assertEquals(srcs[i], pair.getSecond()); + Assert.assertEquals(dsts[i], pair.getFirst()); + Assert.assertEquals(srcs[i], pair.getSecond()); } } public void testParenthesizedTuple() throws Exception { //PY-2648 Map marks = loadTest(); final int PAIR_NUM = 2; - assertEquals(PAIR_NUM*2, marks.size()); + Assert.assertEquals(PAIR_NUM * 2, marks.size()); PsiElement[] srcs = new PsiElement[PAIR_NUM]; PsiElement[] dsts = new PsiElement[PAIR_NUM]; for (int i=0; i").getParent(); // ident -> target expr - assertTrue(dst instanceof PyTargetExpression); + Assert.assertTrue(dst instanceof PyTargetExpression); dsts[i] = dst; PsiElement src = marks.get("").getParent(); // ident -> target expr - assertTrue(src instanceof PyExpression); + Assert.assertTrue(src instanceof PyExpression); srcs[i] = src; } PyAssignmentStatement stmt = (PyAssignmentStatement)srcs[0].getParent().getParent().getParent(); // tuple expr -> assignment List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(PAIR_NUM, mapping.size()); + Assert.assertEquals(PAIR_NUM, mapping.size()); for (int i=0; i pair = mapping.get(i); - assertEquals(dsts[i], pair.getFirst()); - assertEquals(srcs[i], pair.getSecond()); + Assert.assertEquals(dsts[i], pair.getFirst()); + Assert.assertEquals(srcs[i], pair.getSecond()); } } public void testTuplePack() throws Exception { Map marks = loadTest(); final int SRC_NUM = 2; - assertEquals(SRC_NUM+1, marks.size()); + Assert.assertEquals(SRC_NUM + 1, marks.size()); PsiElement[] srcs = new PsiElement[SRC_NUM]; for (int i=0; i").getParent(); // ident -> target expr - assertTrue(src instanceof PyExpression); + Assert.assertTrue(src instanceof PyExpression); srcs[i] = src; } PsiElement dst = marks.get("").getParent(); // ident -> target expr PyAssignmentStatement stmt = (PyAssignmentStatement)dst.getParent(); List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(1, mapping.size()); + Assert.assertEquals(1, mapping.size()); Pair pair = mapping.get(0); - assertEquals(dst, pair.getFirst()); + Assert.assertEquals(dst, pair.getFirst()); for (PsiElement src : srcs) { - assertEquals(src.getParent(), pair.getSecond()); // numeric expr -> tuple + Assert.assertEquals(src.getParent(), pair.getSecond()); // numeric expr -> tuple } } @@ -161,28 +162,28 @@ public class PyAssignmentMappingTest extends LightMarkedTestCase { public void testTupleUnpack() throws Exception { Map marks = loadTest(); final int DST_NUM = 2; - assertEquals(DST_NUM+3, marks.size()); + Assert.assertEquals(DST_NUM + 3, marks.size()); PsiElement[] dsts = new PsiElement[DST_NUM]; for (int i=0; i").getParent(); // ident -> target expr - assertTrue(dst instanceof PyTargetExpression); + Assert.assertTrue(dst instanceof PyTargetExpression); dsts[i] = dst; } PsiElement[] srcs = new PsiElement[DST_NUM]; for (int i=0; i").getParent().getParent().getParent(); // ident -> target expr - assertTrue(src instanceof PyExpression); + Assert.assertTrue(src instanceof PyExpression); srcs[i] = src; } PsiElement src = marks.get("").getParent(); // ident -> target expr PyAssignmentStatement stmt = (PyAssignmentStatement)src.getParent().getParent(); List> mapping = stmt.getTargetsToValuesMapping(); - assertEquals(DST_NUM, mapping.size()); + Assert.assertEquals(DST_NUM, mapping.size()); for (int i=0; i pair = mapping.get(i); - assertEquals(dsts[i], pair.getFirst()); - assertEquals(srcs[i].getText(), pair.getSecond().getText()); + Assert.assertEquals(dsts[i], pair.getFirst()); + Assert.assertEquals(srcs[i].getText(), pair.getSecond().getText()); } } } diff --git a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java index f608c9bca23e..0fc8c06d04bc 100644 --- a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java +++ b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java @@ -8,10 +8,12 @@ import com.intellij.openapi.vfs.VirtualFile; import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache; import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; import com.jetbrains.python.fixtures.LightMarkedTestCase; +import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyFile; import com.jetbrains.python.psi.PyFunction; +import junit.framework.Assert; import java.io.IOException; @@ -236,10 +238,10 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase { for (Instruction instruction : instructions) { buffer.append(instruction).append("\n"); } - final VirtualFile vFile = getVirtualFileByName(fullPath); + final VirtualFile vFile = PyTestCase.getVirtualFileByName(fullPath); try { final String fileText = StringUtil.convertLineSeparators(VfsUtil.loadText(vFile), "\n"); - assertEquals(fileText.trim(), buffer.toString().trim()); + Assert.assertEquals(fileText.trim(), buffer.toString().trim()); } catch (IOException e) { throw new RuntimeException(e); diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyMakeFunctionFromMethodQuickFixTest.java b/python/testSrc/com/jetbrains/python/PyMakeFunctionFromMethodQuickFixTest.java similarity index 96% rename from python/testSrc/com/jetbrains/python/quickFixes/PyMakeFunctionFromMethodQuickFixTest.java rename to python/testSrc/com/jetbrains/python/PyMakeFunctionFromMethodQuickFixTest.java index 7fe875860262..e56453958e46 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyMakeFunctionFromMethodQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyMakeFunctionFromMethodQuickFixTest.java @@ -1,6 +1,5 @@ -package com.jetbrains.python.quickFixes; +package com.jetbrains.python; -import com.jetbrains.python.PyBundle; import com.jetbrains.python.inspections.PyMethodMayBeStaticInspection; /** diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyMakeMethodStaticQuickFixTest.java b/python/testSrc/com/jetbrains/python/PyMakeMethodStaticQuickFixTest.java similarity index 94% rename from python/testSrc/com/jetbrains/python/quickFixes/PyMakeMethodStaticQuickFixTest.java rename to python/testSrc/com/jetbrains/python/PyMakeMethodStaticQuickFixTest.java index dc34bb60cce1..f232eb9d31ef 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyMakeMethodStaticQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyMakeMethodStaticQuickFixTest.java @@ -1,6 +1,5 @@ -package com.jetbrains.python.quickFixes; +package com.jetbrains.python; -import com.jetbrains.python.PyBundle; import com.jetbrains.python.inspections.PyMethodMayBeStaticInspection; /** diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyMoveAttributeToInitQuickFixTest.java b/python/testSrc/com/jetbrains/python/PyMoveAttributeToInitQuickFixTest.java similarity index 94% rename from python/testSrc/com/jetbrains/python/quickFixes/PyMoveAttributeToInitQuickFixTest.java rename to python/testSrc/com/jetbrains/python/PyMoveAttributeToInitQuickFixTest.java index 1032dfa1ac12..f8e1017fd569 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyMoveAttributeToInitQuickFixTest.java +++ b/python/testSrc/com/jetbrains/python/PyMoveAttributeToInitQuickFixTest.java @@ -1,7 +1,6 @@ -package com.jetbrains.python.quickFixes; +package com.jetbrains.python; import com.intellij.testFramework.TestDataPath; -import com.jetbrains.python.PyBundle; import com.jetbrains.python.inspections.PyAttributeOutsideInitInspection; /** diff --git a/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java b/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java index 0bf4fc53e778..7c538ce0479f 100644 --- a/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyMultiFileResolveTest.java @@ -1,20 +1,14 @@ package com.jetbrains.python; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.psi.*; -import com.intellij.psi.impl.PsiManagerImpl; -import com.jetbrains.cython.psi.CythonFunction; -import com.jetbrains.cython.psi.CythonVariable; -import com.jetbrains.python.fixtures.PyResolveTestCase; +import com.jetbrains.python.fixtures.PyMultiFileResolveTestCase; +import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.*; /** * @author yole */ -public class PyMultiFileResolveTest extends PyResolveTestCase { - protected String myTestFileName; +public class PyMultiFileResolveTest extends PyMultiFileResolveTestCase { private static void checkInitPyDir(PsiElement elt, String dirname) { assertTrue(elt instanceof PyFile); @@ -266,96 +260,6 @@ public class PyMultiFileResolveTest extends PyResolveTestCase { myTestFileName = null; } } - - public void testCythonFromModuleCImport() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - public void testCythonFromModuleCImportAs() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - public void testCythonFromModuleCImportStar() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - public void testCythonFromPackageCImportAttribute() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - public void testCythonFromPackageCImportModule() { - assertResolvesTo(PyFile.class, "m1.pxd"); - } - - public void testCythonFromPackageCImportPackage() { - assertResolvesTo(PyFile.class, "__init__.pxd"); - } - - public void testCythonCImportAttribute() { - assertResolvesTo(PyFile.class, "m1.pxd"); - } - - public void testCythonCImportPackage() { - assertResolvesTo(PyFile.class, "__init__.pxd"); - } - - public void testCythonCImportModule() { - assertResolvesTo(PyFile.class, "m1.pxd"); - } - - public void testCythonImplicitCImport() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - public void testCythonInclude() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - // PY-4843 - public void testCythonFromSubmoduleAbsoluteCImport() { - prepareTestDirectory(); - final VirtualFile file = myFixture.findFileInTempDir("p1/m2.pyx"); - assertNotNull("Could not find test file", file); - final PsiFile psiFile = myFixture.getPsiManager().findFile(file); - PsiElement element = doResolve(psiFile); - assertInstanceOf(element, CythonVariable.class); - assertEquals("foo", ((PsiNamedElement)element).getName()); - } - - // PY-4844 - public void testCythonFromModuleCImportExternStar() { - assertResolvesTo(CythonVariable.class, "foo"); - } - - public void testCythonCdefClassForwardInclude() { - final PyTargetExpression target = assertResolvesTo(PyTargetExpression.class, "bar"); - final PyExpression value = target.findAssignedValue(); - assertNotNull(value); - final PsiReference ref = value.getReference(); - assertNotNull(ref); - final PsiElement field = ref.resolve(); - assertNotNull(field); - assertInstanceOf(field, CythonVariable.class); - assertEquals("foo", ((PsiNamedElement)field).getName()); - } - - public void testCythonImportFromPython() { - assertResolvesTo(CythonFunction.class, "foo"); - } - - // PY-4946 - public void testCythonCdefClassAttributeInDefinition() { - final PyTargetExpression target = assertResolvesTo(PyTargetExpression.class, "foo"); - final PyExpression value = target.findAssignedValue(); - assertNotNull(value); - final PsiReference ref = value.getReference(); - assertNotNull(ref); - final PsiElement field = ref.resolve(); - assertNotNull(field); - assertInstanceOf(field, CythonVariable.class); - assertEquals("x", ((PsiNamedElement)field).getName()); - } - // PY-2813 public void testFromNamespacePackageImport() { assertResolvesTo(PyFunction.class, "foo"); @@ -441,70 +345,12 @@ public class PyMultiFileResolveTest extends PyResolveTestCase { public void testFromPackageModuleImportElementNamedAsModule() { assertResolvesTo(PyFunction.class, "foo"); final PsiManager psiManager = myFixture.getPsiManager(); - assertNotParsed((PyFile)psiManager.findFile(myFixture.findFileInTempDir("p1/__init__.py"))); - assertNotParsed((PyFile)psiManager.findFile(myFixture.findFileInTempDir("p1/foo.py"))); + PyTestCase.assertNotParsed((PyFile)psiManager.findFile(myFixture.findFileInTempDir("p1/__init__.py"))); + PyTestCase.assertNotParsed((PyFile)psiManager.findFile(myFixture.findFileInTempDir("p1/foo.py"))); } // PY-10819 public void testFromPackageModuleImportStarElementNamedAsModule() { assertResolvesTo(PyFunction.class, "foo"); } - - private void prepareTestDirectory() { - final String testName = getTestName(true); - myFixture.copyDirectoryToProject(testName, ""); - PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments(); - } - - private PsiFile prepareFile() { - prepareTestDirectory(); - VirtualFile sourceFile = null; - for (String ext : new String[]{".py", ".pyx"}) { - final String fileName = myTestFileName != null ? myTestFileName : getTestName(false) + ext; - sourceFile = myFixture.findFileInTempDir(fileName); - if (sourceFile != null) { - break; - } - } - assertNotNull("Could not find test file", sourceFile); - return myFixture.getPsiManager().findFile(sourceFile); - } - - @Override - protected String getTestDataPath() { - return PythonTestUtil.getTestDataPath() + "/resolve/multiFile/"; - } - - protected PsiElement doResolve(PsiFile psiFile) { - final PsiPolyVariantReference ref = findReferenceByMarker(psiFile); - final PsiManagerImpl psiManager = (PsiManagerImpl)myFixture.getPsiManager(); - psiManager.setAssertOnFileLoadingFilter(new VirtualFileFilter() { - @Override - public boolean accept(VirtualFile file) { - FileType fileType = file.getFileType(); - return fileType == PythonFileType.INSTANCE; - } - }); - try { - final ResolveResult[] resolveResults = ref.multiResolve(false); - if (resolveResults.length == 0) { - return null; - } - return resolveResults[0].isValidResult() ? resolveResults[0].getElement() : null; - } - finally { - psiManager.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE); - } - } - - @Override - protected PsiElement doResolve() { - return doResolve(prepareFile()); - } - - private ResolveResult[] doMultiResolve() { - PsiFile psiFile = prepareFile(); - final PsiPolyVariantReference ref = findReferenceByMarker(psiFile); - return ref.multiResolve(false); - } } diff --git a/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java b/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java index f6278282537d..657a66b81460 100644 --- a/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java +++ b/python/testSrc/com/jetbrains/python/PyParameterInfoTest.java @@ -15,6 +15,7 @@ import com.intellij.util.containers.HashSet; import com.jetbrains.python.fixtures.LightMarkedTestCase; import com.jetbrains.python.psi.CallArgumentsMapping; import com.jetbrains.python.psi.PyArgumentList; +import junit.framework.Assert; import org.jetbrains.annotations.NotNull; import java.awt.*; @@ -35,7 +36,7 @@ public class PyParameterInfoTest extends LightMarkedTestCase { protected Map loadTest(int expected_marks) { Map marks = loadTest(); - assertEquals("Test data sanity", marks.size(), expected_marks); + Assert.assertEquals("Test data sanity", marks.size(), expected_marks); return marks; } @@ -402,7 +403,7 @@ public class PyParameterInfoTest extends LightMarkedTestCase { final PyArgumentList parameterOwner = handler.findElementForParameterInfo(collector); collector.setParameterOwner(parameterOwner); // finds arglist, sets items to show if (collector.getParameterOwner() != null) { - assertEquals("Collected one analysis result", 1, collector.myItems.length); + Assert.assertEquals("Collected one analysis result", 1, collector.myItems.length); handler.updateParameterInfo((PyArgumentList)collector.getParameterOwner(), collector); // moves offset to correct parameter handler.updateUI((CallArgumentsMapping)collector.getItemsToShow()[0], collector); // sets hint text and flags } @@ -472,7 +473,7 @@ public class PyParameterInfoTest extends LightMarkedTestCase { @Override public void setParameterOwner(PsiElement o) { - assertTrue("Found element is a python arglist", o == null || o instanceof PyArgumentList); + Assert.assertTrue("Found element is a python arglist", o == null || o instanceof PyArgumentList); myParamOwner = (PyArgumentList)o; } @@ -557,7 +558,7 @@ public class PyParameterInfoTest extends LightMarkedTestCase { * @param disabled expected disabled substrings of hint */ public void check(String text, String[] highlighted, String[] disabled) { - assertEquals("Signature", text, StringUtil.join(myTexts, "")); + Assert.assertEquals("Signature", text, StringUtil.join(myTexts, "")); StringBuilder wrongs = new StringBuilder(); // see if highlighted matches Set highlightSet = new HashSet(); @@ -586,7 +587,7 @@ public class PyParameterInfoTest extends LightMarkedTestCase { } } // - if (wrongs.length() > 0) fail(wrongs.toString()); + if (wrongs.length() > 0) Assert.fail(wrongs.toString()); } public void check(String text, String[] highlighted) { @@ -594,7 +595,7 @@ public class PyParameterInfoTest extends LightMarkedTestCase { } public void assertNotFound() { - assertNull(myParamOwner); + Assert.assertNull(myParamOwner); } } } diff --git a/python/testSrc/com/jetbrains/python/PyQuickDocTest.java b/python/testSrc/com/jetbrains/python/PyQuickDocTest.java index 9747a59c770f..6cdb263414a7 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickDocTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickDocTest.java @@ -7,8 +7,10 @@ import com.intellij.psi.PsiElement; import com.intellij.testFramework.TestDataFile; import com.jetbrains.python.documentation.PythonDocumentationProvider; import com.jetbrains.python.fixtures.LightMarkedTestCase; +import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; +import junit.framework.Assert; import java.io.IOException; import java.util.Map; @@ -27,14 +29,14 @@ public class PyQuickDocTest extends LightMarkedTestCase { } private void checkByHTML(String text) { - assertNotNull(text); + Assert.assertNotNull(text); checkByHTML(text, "/quickdoc/" + getTestName(false) + ".html"); } private void checkByHTML(String text, @TestDataFile String filePath) { final String fullPath = getTestDataPath() + filePath; - final VirtualFile vFile = getVirtualFileByName(fullPath); - assertNotNull("file " + fullPath + " not found", vFile); + final VirtualFile vFile = PyTestCase.getVirtualFileByName(fullPath); + Assert.assertNotNull("file " + fullPath + " not found", vFile); String loadedText; try { @@ -44,7 +46,7 @@ public class PyQuickDocTest extends LightMarkedTestCase { throw new RuntimeException(e); } String fileText = StringUtil.convertLineSeparators(loadedText, "\n"); - assertEquals(fileText.trim(), text.trim()); + Assert.assertEquals(fileText.trim(), text.trim()); } @Override @@ -54,16 +56,16 @@ public class PyQuickDocTest extends LightMarkedTestCase { private void checkRefDocPair() { Map marks = loadTest(); - assertEquals(2, marks.size()); + Assert.assertEquals(2, marks.size()); final PsiElement original_elt = marks.get(""); PsiElement doc_elt = original_elt.getParent(); // ident -> expr - assertTrue(doc_elt instanceof PyStringLiteralExpression); + Assert.assertTrue(doc_elt instanceof PyStringLiteralExpression); String doc_text = ((PyStringLiteralExpression)doc_elt).getStringValue(); - assertNotNull(doc_text); + Assert.assertNotNull(doc_text); PsiElement ref_elt = marks.get("").getParent(); // ident -> expr final PyDocStringOwner doc_owner = (PyDocStringOwner)((PyReferenceExpression)ref_elt).getReference().resolve(); - assertEquals(doc_elt, doc_owner.getDocStringExpression()); + Assert.assertEquals(doc_elt, doc_owner.getDocStringExpression()); checkByHTML(myProvider.generateDoc(doc_owner, original_elt)); } @@ -127,15 +129,15 @@ public class PyQuickDocTest extends LightMarkedTestCase { public void testInheritedMethod() { Map marks = loadTest(); - assertEquals(2, marks.size()); + Assert.assertEquals(2, marks.size()); PsiElement doc_elt = marks.get("").getParent(); // ident -> expr - assertTrue(doc_elt instanceof PyStringLiteralExpression); + Assert.assertTrue(doc_elt instanceof PyStringLiteralExpression); String doc_text = ((PyStringLiteralExpression)doc_elt).getStringValue(); - assertNotNull(doc_text); + Assert.assertNotNull(doc_text); PsiElement ref_elt = marks.get("").getParent(); // ident -> expr final PyDocStringOwner doc_owner = (PyDocStringOwner)((PyReferenceExpression)ref_elt).getReference().resolve(); - assertNull(doc_owner.getDocStringExpression()); // no direct doc! + Assert.assertNull(doc_owner.getDocStringExpression()); // no direct doc! checkByHTML(myProvider.generateDoc(doc_owner, null)); } diff --git a/python/testSrc/com/jetbrains/python/quickFixes/PyQuickFixTestCase.java b/python/testSrc/com/jetbrains/python/PyQuickFixTestCase.java similarity index 97% rename from python/testSrc/com/jetbrains/python/quickFixes/PyQuickFixTestCase.java rename to python/testSrc/com/jetbrains/python/PyQuickFixTestCase.java index cbc582cc9c2f..9513e25934e9 100644 --- a/python/testSrc/com/jetbrains/python/quickFixes/PyQuickFixTestCase.java +++ b/python/testSrc/com/jetbrains/python/PyQuickFixTestCase.java @@ -1,4 +1,4 @@ -package com.jetbrains.python.quickFixes; +package com.jetbrains.python; import com.intellij.codeInsight.intention.IntentionAction; import com.jetbrains.python.PythonTestUtil; diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index 6ff38765834b..2fe80e17477b 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -5,6 +5,7 @@ import com.intellij.psi.PsiPolyVariantReference; import com.intellij.psi.PsiReference; import com.intellij.psi.ResolveResult; 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.fixtures.PyResolveTestCase; @@ -12,6 +13,7 @@ import com.jetbrains.python.psi.*; import com.jetbrains.python.psi.impl.PyPsiUtils; import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher; import com.jetbrains.python.psi.resolve.ImportedResolveResult; +import junit.framework.Assert; public class PyResolveTest extends PyResolveTestCase { @Override @@ -22,7 +24,7 @@ public class PyResolveTest extends PyResolveTestCase { private PsiReference findReferenceByMarker() { myFixture.configureByFile("resolve/" + getTestName(false) + ".py"); - return findReferenceByMarker(myFixture.getFile()); + return PyResolveTestCase.findReferenceByMarker(myFixture.getFile()); } protected PsiElement resolve() { @@ -33,7 +35,7 @@ public class PyResolveTest extends PyResolveTestCase { private ResolveResult[] multiResolve() { PsiReference ref = findReferenceByMarker(); - assertTrue(ref instanceof PsiPolyVariantReference); + Assert.assertTrue(ref instanceof PsiPolyVariantReference); return ((PsiPolyVariantReference)ref).multiResolve(false); } @@ -43,227 +45,227 @@ public class PyResolveTest extends PyResolveTestCase { public void testFunc() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyFunction); + Assert.assertTrue(targetElement instanceof PyFunction); } public void testToConstructor() { PsiElement target = resolve(); - assertTrue(target instanceof PyFunction); - assertEquals(PyNames.INIT, ((PyFunction)target).getName()); + Assert.assertTrue(target instanceof PyFunction); + Assert.assertEquals(PyNames.INIT, ((PyFunction)target).getName()); } public void testToConstructorInherited() { ResolveResult[] targets = multiResolve(); - assertEquals(2, targets.length); // to class, to init + Assert.assertEquals(2, targets.length); // to class, to init PsiElement elt; // class elt = targets[0].getElement(); - assertTrue(elt instanceof PyClass); - assertEquals("Bar", ((PyClass)elt).getName()); + Assert.assertTrue(elt instanceof PyClass); + Assert.assertEquals("Bar", ((PyClass)elt).getName()); // init elt = targets[1].getElement(); - assertTrue(elt instanceof PyFunction); + Assert.assertTrue(elt instanceof PyFunction); PyFunction fun = (PyFunction)elt; - assertEquals(PyNames.INIT, fun.getName()); + Assert.assertEquals(PyNames.INIT, fun.getName()); PyClass cls = fun.getContainingClass(); - assertNotNull(cls); - assertEquals("Foo", cls.getName()); + Assert.assertNotNull(cls); + Assert.assertEquals("Foo", cls.getName()); } // NOTE: maybe this test does not belong exactly here; still it's the best place currently. public void testComplexCallee() { PsiElement targetElement = resolve(); PyExpression assigned = ((PyAssignmentStatement)targetElement.getContext()).getAssignedValue(); - assertTrue(assigned instanceof PyCallExpression); + Assert.assertTrue(assigned instanceof PyCallExpression); PsiElement callee = ((PyCallExpression)assigned).getCallee(); - assertTrue(callee instanceof PySubscriptionExpression); + Assert.assertTrue(callee instanceof PySubscriptionExpression); } public void testVar() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testDefaultInClass() { PsiElement targetElement = resolve(); - assertNotNull(targetElement); - assertTrue(targetElement instanceof PyTargetExpression); - assertEquals("FOO", ((PyTargetExpression)targetElement).getName()); + Assert.assertNotNull(targetElement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertEquals("FOO", ((PyTargetExpression)targetElement).getName()); } public void testQualifiedFunc() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyFunction); + Assert.assertTrue(targetElement instanceof PyFunction); } public void testQualifiedVar() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testQualifiedTarget() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testQualifiedFalseTarget() { PsiElement targetElement = resolve(); - assertNull(targetElement); + Assert.assertNull(targetElement); } public void testInnerFuncVar() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testTupleInComprh() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testForStatement() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testExceptClause() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testLookAhead() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testLookAheadCapped() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testTryExceptElse() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testGlobal() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testGlobalDefinedLocally() { final PsiElement element = resolve(); - assertInstanceOf(element, PyTargetExpression.class); + UsefulTestCase.assertInstanceOf(element, PyTargetExpression.class); final PsiElement parent = element.getParent(); - assertInstanceOf(parent, PyAssignmentStatement.class); + UsefulTestCase.assertInstanceOf(parent, PyAssignmentStatement.class); } public void testLambda() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyNamedParameter); + Assert.assertTrue(targetElement instanceof PyNamedParameter); } public void testLambdaParameterOutside() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testSuperField() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testFieldInCondition() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testMultipleFields() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testClassPeerMembers() { PsiElement target = resolve(); - assertTrue(target instanceof PyFunction); + Assert.assertTrue(target instanceof PyFunction); } public void testTuple() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testMultiTarget() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testMultiTargetTuple() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertNotNull(PsiTreeUtil.getParentOfType(targetElement, PyAssignmentStatement.class)); // it's deep in a tuple + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertNotNull(PsiTreeUtil.getParentOfType(targetElement, PyAssignmentStatement.class)); // it's deep in a tuple } public void testWithStatement() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyWithItem); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyWithItem); } public void testTupleInExcept() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(PsiTreeUtil.getParentOfType(targetElement, PyExceptPart.class) != null); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(PsiTreeUtil.getParentOfType(targetElement, PyExceptPart.class) != null); } public void testDocStringClass() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyStringLiteralExpression); - assertEquals("Docstring of class Foo", ((PyStringLiteralExpression)targetElement).getStringValue()); + Assert.assertTrue(targetElement instanceof PyStringLiteralExpression); + Assert.assertEquals("Docstring of class Foo", ((PyStringLiteralExpression)targetElement).getStringValue()); } public void testDocStringInstance() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyStringLiteralExpression); - assertEquals("Docstring of class Foo", ((PyStringLiteralExpression)targetElement).getStringValue()); + Assert.assertTrue(targetElement instanceof PyStringLiteralExpression); + Assert.assertEquals("Docstring of class Foo", ((PyStringLiteralExpression)targetElement).getStringValue()); } public void testDocStringFunction() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyStringLiteralExpression); - assertEquals("Docstring of function bar", ((PyStringLiteralExpression)targetElement).getStringValue()); + Assert.assertTrue(targetElement instanceof PyStringLiteralExpression); + Assert.assertEquals("Docstring of function bar", ((PyStringLiteralExpression)targetElement).getStringValue()); } public void testDocStringInvalid() { PsiElement targetElement = resolve(); - assertNull(targetElement); + Assert.assertNull(targetElement); } public void testFieldNotInInit() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement instanceof PyTargetExpression); } public void testClassIsNotMemberOfItself() { PsiElement targetElement = resolve(); - assertNull(targetElement); + Assert.assertNull(targetElement); } public void testSuper() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyFunction); - assertEquals("A", ((PyFunction) targetElement).getContainingClass().getName()); + Assert.assertTrue(targetElement instanceof PyFunction); + Assert.assertEquals("A", ((PyFunction)targetElement).getContainingClass().getName()); } public void testSuperPy3k() { // PY-1330 PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON30); try { final PyFunction pyFunction = assertResolvesTo(PyFunction.class, "foo"); - assertEquals("A", pyFunction.getContainingClass().getName()); + Assert.assertEquals("A", pyFunction.getContainingClass().getName()); } finally { PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null); @@ -272,81 +274,81 @@ public class PyResolveTest extends PyResolveTestCase { public void testStackOverflow() { PsiElement targetElement = resolve(); - assertNull(targetElement); + Assert.assertNull(targetElement); } public void testProperty() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyFunction); - assertEquals("set_full_name", ((PyFunction)targetElement).getName()); + Assert.assertTrue(targetElement instanceof PyFunction); + Assert.assertEquals("set_full_name", ((PyFunction)targetElement).getName()); } public void testLambdaWithParens() { // PY-882 PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyParameter); + Assert.assertTrue(targetElement instanceof PyParameter); } public void testTextBasedResolve() { ResolveResult[] resolveResults = multiResolve(); - assertEquals(1, resolveResults.length); - assertTrue(resolveResults [0].getElement() instanceof PyFunction); + Assert.assertEquals(1, resolveResults.length); + Assert.assertTrue(resolveResults[0].getElement() instanceof PyFunction); } public void testClassPrivateInClass() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testClassPrivateInMethod() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testClassPrivateInMethodNested() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testClassPrivateInherited() { PsiElement targetElement = resolve(); - assertTrue(targetElement instanceof PyTargetExpression); - assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); + Assert.assertTrue(targetElement instanceof PyTargetExpression); + Assert.assertTrue(targetElement.getParent() instanceof PyAssignmentStatement); } public void testClassPrivateOutsideClass() { PsiElement targetElement = resolve(); - assertNull(targetElement); + Assert.assertNull(targetElement); } public void testClassPrivateOutsideInstance() { PsiElement targetElement = resolve(); - assertNull(targetElement); + Assert.assertNull(targetElement); } public void testClassNameEqualsMethodName() { PsiElement targetElement = resolve(); - assertInstanceOf(targetElement, PyFunction.class); + UsefulTestCase.assertInstanceOf(targetElement, PyFunction.class); } public void testUnresolvedImport() { final ResolveResult[] results = multiResolve(); - assertEquals(1, results.length); - assertInstanceOf(results [0], ImportedResolveResult.class); + Assert.assertEquals(1, results.length); + UsefulTestCase.assertInstanceOf(results[0], ImportedResolveResult.class); ImportedResolveResult result = (ImportedResolveResult) results [0]; - assertNull(result.getElement()); + Assert.assertNull(result.getElement()); } public void testIsInstance() { // PY-1133 PsiElement targetElement = resolve(); - assertInstanceOf(targetElement, PyNamedParameter.class); + UsefulTestCase.assertInstanceOf(targetElement, PyNamedParameter.class); } public void testListComprehension() { // PY-1143 PsiElement targetElement = resolve(); - assertInstanceOf(targetElement, PyTargetExpression.class); + UsefulTestCase.assertInstanceOf(targetElement, PyTargetExpression.class); } public void testSuperMetaClass() { @@ -359,18 +361,18 @@ public class PyResolveTest extends PyResolveTestCase { public void testSuperTwoClasses() { // PY-2133 final PyFunction pyFunction = assertResolvesTo(PyFunction.class, "my_call"); - assertEquals("Base2", pyFunction.getContainingClass().getName()); + Assert.assertEquals("Base2", pyFunction.getContainingClass().getName()); } public void testLambdaDefaultParameter() { final PsiElement element = doResolve(); - assertInstanceOf(element, PyTargetExpression.class); - assertTrue(element.getParent() instanceof PySetCompExpression); + UsefulTestCase.assertInstanceOf(element, PyTargetExpression.class); + Assert.assertTrue(element.getParent() instanceof PySetCompExpression); } public void testListAssignment() { final PsiElement element = doResolve(); - assertInstanceOf(element, PyTargetExpression.class); + UsefulTestCase.assertInstanceOf(element, PyTargetExpression.class); } public void testStarUnpacking() { // PY-1459 @@ -383,7 +385,7 @@ public class PyResolveTest extends PyResolveTestCase { public void testBuiltinVsClassMember() { // PY-1654 final PyFunction pyFunction = assertResolvesTo(PyFunction.class, "eval"); - assertEquals("__builtin__.py", pyFunction.getContainingFile().getName()); + Assert.assertEquals("__builtin__.py", pyFunction.getContainingFile().getName()); } public void testLambdaToClass() { // PY-2182 @@ -396,7 +398,7 @@ public class PyResolveTest extends PyResolveTestCase { public void testModuleToBuiltins() { final PsiElement element = doResolve(); - assertNull(element); + Assert.assertNull(element); } public void testWithParentheses() { @@ -413,7 +415,7 @@ public class PyResolveTest extends PyResolveTestCase { public void testNoResolveIntoGenerator() { // PY-3030 PyTargetExpression expr = assertResolvesTo(PyTargetExpression.class, "foo"); - assertEquals("foo = 1", expr.getParent().getText()); + Assert.assertEquals("foo = 1", expr.getParent().getText()); } public void testResolveInGenerator() { @@ -438,9 +440,9 @@ public class PyResolveTest extends PyResolveTestCase { public void testImplicitResolveInstanceAttribute() { ResolveResult[] resolveResults = multiResolve(); - assertEquals(1, resolveResults.length); + Assert.assertEquals(1, resolveResults.length); final PsiElement psiElement = resolveResults[0].getElement(); - assertTrue(psiElement instanceof PyTargetExpression && "xyzzy".equals(((PyTargetExpression)psiElement).getName())); + Assert.assertTrue(psiElement instanceof PyTargetExpression && "xyzzy".equals(((PyTargetExpression)psiElement).getName())); } public void testAttributeAssignedNearby() { @@ -449,15 +451,15 @@ public class PyResolveTest extends PyResolveTestCase { public void testPreviousTarget() { PsiElement resolved = resolve(); - assertInstanceOf(resolved, PyTargetExpression.class); + UsefulTestCase.assertInstanceOf(resolved, PyTargetExpression.class); PyTargetExpression target = (PyTargetExpression)resolved; PyExpression value = target.findAssignedValue(); - assertInstanceOf(value, PyNumericLiteralExpression.class); + UsefulTestCase.assertInstanceOf(value, PyNumericLiteralExpression.class); } public void testMetaclass() { final PyFunction function = assertResolvesTo(PyFunction.class, "getStore"); - assertEquals("PluginMetaclass", function.getContainingClass().getName()); + Assert.assertEquals("PluginMetaclass", function.getContainingClass().getName()); } // PY-6083 @@ -492,9 +494,9 @@ public class PyResolveTest extends PyResolveTestCase { final PsiReference ref = findReferenceByMarker(); final PsiElement source = ref.getElement(); final PsiElement target = ref.resolve(); - assertNotNull(target); - assertTrue(source != target); - assertTrue(PyPsiUtils.isBefore(target, source)); + Assert.assertNotNull(target); + Assert.assertTrue(source != target); + Assert.assertTrue(PyPsiUtils.isBefore(target, source)); } // PY-7541 @@ -502,8 +504,8 @@ public class PyResolveTest extends PyResolveTestCase { final PsiReference ref = findReferenceByMarker(); final PsiElement source = ref.getElement(); final PsiElement target = ref.resolve(); - assertNotNull(target); - assertTrue(source == target); + Assert.assertNotNull(target); + Assert.assertTrue(source == target); } // PY-7970 @@ -516,12 +518,12 @@ public class PyResolveTest extends PyResolveTestCase { final PsiReference ref = findReferenceByMarker(); final PsiElement source = ref.getElement(); final PsiElement resolved = ref.resolve(); - assertInstanceOf(resolved, PyReferenceExpression.class); - assertNotSame(resolved, source); + UsefulTestCase.assertInstanceOf(resolved, PyReferenceExpression.class); + Assert.assertNotSame(resolved, source); final PyReferenceExpression res = (PyReferenceExpression)resolved; - assertNotNull(res); - assertEquals("foo", res.getName()); - assertInstanceOf(res.getParent(), PyAugAssignmentStatement.class); + Assert.assertNotNull(res); + Assert.assertEquals("foo", res.getName()); + UsefulTestCase.assertInstanceOf(res.getParent(), PyAugAssignmentStatement.class); } public void testGeneratorShadowing() { // PY-8725 @@ -531,12 +533,12 @@ public class PyResolveTest extends PyResolveTestCase { // PY-6805 public void testAttributeDefinedInNew() { final PsiElement resolved = resolve(); - assertInstanceOf(resolved, PyTargetExpression.class); + UsefulTestCase.assertInstanceOf(resolved, PyTargetExpression.class); final PyTargetExpression target = (PyTargetExpression)resolved; - assertEquals("foo", target.getName()); + Assert.assertEquals("foo", target.getName()); final ScopeOwner owner = ScopeUtil.getScopeOwner(target); - assertNotNull(owner); - assertInstanceOf(owner, PyFunction.class); - assertEquals("__new__", owner.getName()); + Assert.assertNotNull(owner); + UsefulTestCase.assertInstanceOf(owner, PyFunction.class); + Assert.assertEquals("__new__", owner.getName()); } } diff --git a/python/testSrc/com/jetbrains/python/PyStatementPartsTest.java b/python/testSrc/com/jetbrains/python/PyStatementPartsTest.java index 6c0a325fd7d5..e52b7fa34490 100644 --- a/python/testSrc/com/jetbrains/python/PyStatementPartsTest.java +++ b/python/testSrc/com/jetbrains/python/PyStatementPartsTest.java @@ -3,6 +3,7 @@ package com.jetbrains.python; import com.intellij.psi.PsiElement; import com.jetbrains.python.fixtures.LightMarkedTestCase; import com.jetbrains.python.psi.*; +import junit.framework.Assert; import java.util.Map; @@ -20,141 +21,141 @@ public class PyStatementPartsTest extends LightMarkedTestCase { public void testIf() throws Exception { Map marks = loadTest(); - assertEquals(2, marks.size()); + Assert.assertEquals(2, marks.size()); PsiElement elt = marks.get("").getParent().getParent(); // if_keyword -> if_part -> if_stmt - assertTrue(elt instanceof PyIfStatement); + Assert.assertTrue(elt instanceof PyIfStatement); PyIfStatement if_stmt = (PyIfStatement)elt; PyIfPart if_part = if_stmt.getIfPart(); - assertFalse(if_part.isElif()); + Assert.assertFalse(if_part.isElif()); PyExpression if_cond = if_part.getCondition(); - assertEquals(marks.get("").getParent(), if_cond); + Assert.assertEquals(marks.get("").getParent(), if_cond); } public void testIfElse() throws Exception { Map marks = loadTest(); - assertEquals(4, marks.size()); + Assert.assertEquals(4, marks.size()); PsiElement elt = marks.get("").getParent().getParent(); // if_keyword -> if_part -> if_stmt - assertTrue(elt instanceof PyIfStatement); + Assert.assertTrue(elt instanceof PyIfStatement); PyIfStatement if_stmt = (PyIfStatement)elt; PyIfPart if_part = if_stmt.getIfPart(); - assertFalse(if_part.isElif()); + Assert.assertFalse(if_part.isElif()); PyExpression if_cond = if_part.getCondition(); - assertEquals(marks.get("").getParent(), if_cond); + Assert.assertEquals(marks.get("").getParent(), if_cond); PyStatementList stmt_list = if_part.getStatementList(); - assertNotNull(stmt_list); - assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list + Assert.assertNotNull(stmt_list); + Assert.assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list PyElsePart else_part = if_stmt.getElsePart(); - assertNotNull(else_part); + Assert.assertNotNull(else_part); stmt_list = else_part.getStatementList(); - assertNotNull(stmt_list); - assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list + Assert.assertNotNull(stmt_list); + Assert.assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list } public void testIfElifElse() throws Exception { Map marks = loadTest(); - assertEquals(6, marks.size()); + Assert.assertEquals(6, marks.size()); PsiElement elt = marks.get("").getParent().getParent(); // if_keyword -> if_part -> if_stmt - assertTrue(elt instanceof PyIfStatement); + Assert.assertTrue(elt instanceof PyIfStatement); PyIfStatement if_stmt = (PyIfStatement)elt; PyIfPart if_part = if_stmt.getIfPart(); - assertFalse(if_part.isElif()); + Assert.assertFalse(if_part.isElif()); PyExpression if_cond = if_part.getCondition(); - assertEquals(marks.get("").getParent(), if_cond); + Assert.assertEquals(marks.get("").getParent(), if_cond); PyStatementList stmt_list = if_part.getStatementList(); - assertNotNull(stmt_list); - assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list + Assert.assertNotNull(stmt_list); + Assert.assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list PyElsePart else_part = if_stmt.getElsePart(); - assertNotNull(else_part); + Assert.assertNotNull(else_part); stmt_list = else_part.getStatementList(); - assertNotNull(stmt_list); - assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list + Assert.assertNotNull(stmt_list); + Assert.assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list PyIfPart elif_part = if_stmt.getElifParts()[0]; - assertTrue(elif_part.isElif()); + Assert.assertTrue(elif_part.isElif()); if_cond = elif_part.getCondition(); - assertEquals(marks.get("").getParent(), if_cond); + Assert.assertEquals(marks.get("").getParent(), if_cond); stmt_list = elif_part.getStatementList(); - assertNotNull(stmt_list); - assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list + Assert.assertNotNull(stmt_list); + Assert.assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list } public void testWhile() throws Exception { Map marks = loadTest(); - assertEquals(3, marks.size()); + Assert.assertEquals(3, marks.size()); PsiElement elt = marks.get("").getParent().getParent(); // keyword -> part -> stmt - assertTrue(elt instanceof PyWhileStatement); + Assert.assertTrue(elt instanceof PyWhileStatement); PyWhileStatement while_stmt = (PyWhileStatement)elt; PyWhilePart while_part = while_stmt.getWhilePart(); PyExpression cond = while_part.getCondition(); - assertEquals(marks.get("").getParent(), cond); + Assert.assertEquals(marks.get("").getParent(), cond); elt = marks.get("").getParent(); // keyword -> part - assertTrue(elt instanceof PyElsePart); - assertEquals(while_stmt.getElsePart(), elt); + Assert.assertTrue(elt instanceof PyElsePart); + Assert.assertEquals(while_stmt.getElsePart(), elt); } public void testFor() throws Exception { Map marks = loadTest(); - assertEquals(4, marks.size()); + Assert.assertEquals(4, marks.size()); PsiElement elt = marks.get("").getParent().getParent(); // keyword -> part -> stmt - assertTrue(elt instanceof PyForStatement); + Assert.assertTrue(elt instanceof PyForStatement); PyForStatement stmt = (PyForStatement)elt; PyForPart for_part = stmt.getForPart(); PyExpression target = for_part.getTarget(); - assertEquals(marks.get("").getParent(), target); // ident -> expr + Assert.assertEquals(marks.get("").getParent(), target); // ident -> expr PyExpression source = for_part.getSource(); - assertEquals(marks.get("").getParent(), source); // ident -> expr + Assert.assertEquals(marks.get("").getParent(), source); // ident -> expr elt = marks.get("").getParent(); // keyword -> part - assertTrue(elt instanceof PyElsePart); - assertEquals(stmt.getElsePart(), elt); + Assert.assertTrue(elt instanceof PyElsePart); + Assert.assertEquals(stmt.getElsePart(), elt); } public void testTry() throws Exception { Map marks = loadTest(); - assertEquals(6, marks.size()); + Assert.assertEquals(6, marks.size()); PsiElement elt = marks.get("").getParent().getParent(); // keyword -> part -> stmt - assertTrue(elt instanceof PyTryExceptStatement); + Assert.assertTrue(elt instanceof PyTryExceptStatement); PyTryExceptStatement stmt = (PyTryExceptStatement)elt; PyTryPart try_part = stmt.getTryPart(); PyStatementList stmt_list = try_part.getStatementList(); - assertNotNull(stmt_list); - assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list + Assert.assertNotNull(stmt_list); + Assert.assertEquals(marks.get("").getParent().getParent(), stmt_list); // keyword -> stmt -> stmt_list PyExceptPart exc_part = stmt.getExceptParts()[0]; - assertEquals("ArithmeticError", exc_part.getExceptClass().getText()); - assertEquals(marks.get("").getParent(), exc_part); + Assert.assertEquals("ArithmeticError", exc_part.getExceptClass().getText()); + Assert.assertEquals(marks.get("").getParent(), exc_part); exc_part = (PyExceptPart)marks.get("").getParent(); // keyword -> part - assertEquals(stmt.getExceptParts()[1], exc_part); - assertNull(exc_part.getExceptClass()); + Assert.assertEquals(stmt.getExceptParts()[1], exc_part); + Assert.assertNull(exc_part.getExceptClass()); elt = marks.get("").getParent(); // keyword -> part - assertTrue(elt instanceof PyElsePart); - assertEquals(stmt.getElsePart(), elt); + Assert.assertTrue(elt instanceof PyElsePart); + Assert.assertEquals(stmt.getElsePart(), elt); elt = marks.get("").getParent(); // keyword -> part - assertTrue(elt instanceof PyFinallyPart); - assertEquals(stmt.getFinallyPart(), elt); + Assert.assertTrue(elt instanceof PyFinallyPart); + Assert.assertEquals(stmt.getFinallyPart(), elt); } } diff --git a/python/testSrc/com/jetbrains/python/PyStringLiteralLexerTest.java b/python/testSrc/com/jetbrains/python/PyStringLiteralLexerTest.java index 0faba502cb01..edcbca898d09 100644 --- a/python/testSrc/com/jetbrains/python/PyStringLiteralLexerTest.java +++ b/python/testSrc/com/jetbrains/python/PyStringLiteralLexerTest.java @@ -8,7 +8,7 @@ import com.jetbrains.python.lexer.PyStringLiteralLexer; */ public class PyStringLiteralLexerTest extends PyLexerTestCase { public void testBackslashN() { // PY-1313 - doLexerTest("u\"\\N{LATIN SMALL LETTER B}\"", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), - "Py:SINGLE_QUOTED_UNICODE", "VALID_STRING_ESCAPE_TOKEN", "Py:SINGLE_QUOTED_UNICODE"); + PyLexerTestCase.doLexerTest("u\"\\N{LATIN SMALL LETTER B}\"", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), + "Py:SINGLE_QUOTED_UNICODE", "VALID_STRING_ESCAPE_TOKEN", "Py:SINGLE_QUOTED_UNICODE"); } } diff --git a/python/testSrc/com/jetbrains/python/PyTypeTest.java b/python/testSrc/com/jetbrains/python/PyTypeTest.java index 5d9e84b6b3fc..ba06be6cced3 100644 --- a/python/testSrc/com/jetbrains/python/PyTypeTest.java +++ b/python/testSrc/com/jetbrains/python/PyTypeTest.java @@ -760,6 +760,30 @@ public class PyTypeTest extends PyTestCase { " print(expr)\n"); } + // PY-8953 + public void testSelfInDocString() { + doTest("int", + "class C(object):\n" + + " def foo(self):\n" + + " '''\n" + + " :type self: int\n" + + " '''\n" + + " expr = self\n"); + } + + // PY-9605 + public void testPropertyReturnsCallable() { + doTest("() -> int", + "class C(object):\n" + + " @property\n" + + " def foo(self):\n" + + " return lambda: 0\n" + + "\n" + + + "c = C()\n" + + "expr = c.foo\n"); + } + private static TypeEvalContext getTypeEvalContext(@NotNull PyExpression element) { return TypeEvalContext.userInitiated(element.getContainingFile()).withTracing(); } diff --git a/python/testSrc/com/jetbrains/python/PythonHighlightingLexerTest.java b/python/testSrc/com/jetbrains/python/PythonHighlightingLexerTest.java index a0cfe91588f3..050172dd58dc 100644 --- a/python/testSrc/com/jetbrains/python/PythonHighlightingLexerTest.java +++ b/python/testSrc/com/jetbrains/python/PythonHighlightingLexerTest.java @@ -156,6 +156,6 @@ public class PythonHighlightingLexerTest extends PyLexerTestCase { } private static void doTest(LanguageLevel languageLevel, String text, String... expectedTokens) { - doLexerTest(text, new PythonHighlightingLexer(languageLevel), expectedTokens); + PyLexerTestCase.doLexerTest(text, new PythonHighlightingLexer(languageLevel), expectedTokens); } } diff --git a/python/testSrc/com/jetbrains/python/PythonLexerTest.java b/python/testSrc/com/jetbrains/python/PythonLexerTest.java index e8f85f70e917..693f4b03f469 100644 --- a/python/testSrc/com/jetbrains/python/PythonLexerTest.java +++ b/python/testSrc/com/jetbrains/python/PythonLexerTest.java @@ -301,6 +301,6 @@ public class PythonLexerTest extends PyLexerTestCase { } private static void doTest(String text, String... expectedTokens) { - doLexerTest(text, new PythonIndentingLexer(), expectedTokens); + PyLexerTestCase.doLexerTest(text, new PythonIndentingLexer(), expectedTokens); } } diff --git a/python/testSrc/com/jetbrains/python/PythonParsingTest.java b/python/testSrc/com/jetbrains/python/PythonParsingTest.java index 75da8f3d51c5..6b6f6de68bfd 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -3,7 +3,6 @@ package com.jetbrains.python; import com.intellij.psi.PsiFile; import com.intellij.testFramework.ParsingTestCase; import com.intellij.testFramework.TestDataPath; -import com.jetbrains.cython.CythonTokenSetContributor; import com.jetbrains.python.fixtures.PyTestCase; import com.jetbrains.python.psi.LanguageLevel; @@ -24,7 +23,6 @@ public class PythonParsingTest extends ParsingTestCase { PyTestCase.initPlatformPrefix(); registerExtensionPoint(PythonDialectsTokenSetContributor.EP_NAME, PythonDialectsTokenSetContributor.class); registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new PythonTokenSetContributor()); - registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new CythonTokenSetContributor()); } @Override diff --git a/python/testSrc/com/jetbrains/python/PythonRunConfigurationTest.java b/python/testSrc/com/jetbrains/python/PythonRunConfigurationTest.java index 8a2206fd7ed6..2ae9bb0db04b 100644 --- a/python/testSrc/com/jetbrains/python/PythonRunConfigurationTest.java +++ b/python/testSrc/com/jetbrains/python/PythonRunConfigurationTest.java @@ -5,6 +5,7 @@ import com.jetbrains.python.run.PythonConfigurationType; import com.jetbrains.python.run.PythonRunConfiguration; import com.jetbrains.python.testing.PythonTestConfigurationType; import com.jetbrains.python.testing.unittest.PythonUnitTestRunConfiguration; +import junit.framework.Assert; import java.util.List; @@ -19,8 +20,8 @@ public class PythonRunConfigurationTest extends PyCommandLineTestCase { PythonUnitTestRunConfiguration.class); configuration.setScriptName(PY_SCRIPT); final List params = buildRunCommandLine(configuration); - assertTrue(params.get(0).endsWith("utrunner.py")); - assertTrue(params.get(1).equals(PY_SCRIPT)); + Assert.assertTrue(params.get(0).endsWith("utrunner.py")); + Assert.assertTrue(params.get(1).equals(PY_SCRIPT)); } public void testDebugCommandLine() { @@ -28,7 +29,7 @@ public class PythonRunConfigurationTest extends PyCommandLineTestCase { PythonRunConfiguration.class); configuration.setScriptName(PY_SCRIPT); final List params = buildDebugCommandLine(configuration); - final int index = verifyPyDevDParameters(params); - assertEquals(PY_SCRIPT, params.get(index)); + final int index = PyCommandLineTestCase.verifyPyDevDParameters(params); + Assert.assertEquals(PY_SCRIPT, params.get(index)); } } diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java index 40ddfaf84fc3..1636a64389ac 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyLexerTestCase.java @@ -2,8 +2,8 @@ package com.jetbrains.python.fixtures; import com.intellij.lexer.Lexer; import com.intellij.testFramework.PlatformLiteFixture; -import com.jetbrains.cython.CythonTokenSetContributor; import com.jetbrains.python.PythonDialectsTokenSetContributor; +import com.jetbrains.python.PythonDialectsTokenSetProvider; import com.jetbrains.python.PythonTokenSetContributor; /** @@ -16,7 +16,7 @@ public abstract class PyLexerTestCase extends PlatformLiteFixture { PyTestCase.initPlatformPrefix(); registerExtensionPoint(PythonDialectsTokenSetContributor.EP_NAME, PythonDialectsTokenSetContributor.class); registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new PythonTokenSetContributor()); - registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new CythonTokenSetContributor()); + PythonDialectsTokenSetProvider.reset(); } public static void doLexerTest(String text, Lexer lexer, String... expectedTokens) { diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyMultiFileResolveTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyMultiFileResolveTestCase.java new file mode 100644 index 000000000000..763ad9084819 --- /dev/null +++ b/python/testSrc/com/jetbrains/python/fixtures/PyMultiFileResolveTestCase.java @@ -0,0 +1,76 @@ +package com.jetbrains.python.fixtures; + +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileFilter; +import com.intellij.psi.*; +import com.intellij.psi.impl.PsiManagerImpl; +import com.jetbrains.python.PythonFileType; +import com.jetbrains.python.PythonTestUtil; +import junit.framework.Assert; + +/** + * @author yole + */ +public abstract class PyMultiFileResolveTestCase extends PyResolveTestCase { + protected String myTestFileName; + + @Override + protected String getTestDataPath() { + return PythonTestUtil.getTestDataPath() + "/resolve/multiFile/"; + } + + protected PsiElement doResolve(PsiFile psiFile) { + final PsiPolyVariantReference ref = PyResolveTestCase.findReferenceByMarker(psiFile); + final PsiManagerImpl psiManager = (PsiManagerImpl)myFixture.getPsiManager(); + psiManager.setAssertOnFileLoadingFilter(new VirtualFileFilter() { + @Override + public boolean accept(VirtualFile file) { + FileType fileType = file.getFileType(); + return fileType == PythonFileType.INSTANCE; + } + }); + try { + final ResolveResult[] resolveResults = ref.multiResolve(false); + if (resolveResults.length == 0) { + return null; + } + return resolveResults[0].isValidResult() ? resolveResults[0].getElement() : null; + } + finally { + psiManager.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE); + } + } + + + protected void prepareTestDirectory() { + final String testName = getTestName(true); + myFixture.copyDirectoryToProject(testName, ""); + PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments(); + } + + private PsiFile prepareFile() { + prepareTestDirectory(); + VirtualFile sourceFile = null; + for (String ext : new String[]{".py", ".pyx"}) { + final String fileName = myTestFileName != null ? myTestFileName : getTestName(false) + ext; + sourceFile = myFixture.findFileInTempDir(fileName); + if (sourceFile != null) { + break; + } + } + Assert.assertNotNull("Could not find test file", sourceFile); + return myFixture.getPsiManager().findFile(sourceFile); + } + + @Override + protected PsiElement doResolve() { + return doResolve(prepareFile()); + } + + protected ResolveResult[] doMultiResolve() { + PsiFile psiFile = prepareFile(); + final PsiPolyVariantReference ref = PyResolveTestCase.findReferenceByMarker(psiFile); + return ref.multiResolve(false); + } +} diff --git a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java index 3d70ffcd78ef..40db6a2ca128 100644 --- a/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java +++ b/python/testSrc/com/jetbrains/python/fixtures/PyTestCase.java @@ -22,7 +22,6 @@ import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; import com.intellij.testFramework.fixtures.TestFixtureBuilder; import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; -import com.intellij.util.PlatformUtils; import com.jetbrains.python.PythonMockSdk; import com.jetbrains.python.PythonTestUtil; import com.jetbrains.python.psi.LanguageLevel; @@ -147,6 +146,10 @@ public abstract class PyTestCase extends UsefulTestCase { } public static void initPlatformPrefix() { - PlatformTestCase.initPlatformPrefix(UsefulTestCase.IDEA_MARKER_CLASS, PlatformUtils.PYCHARM_PREFIX); + PlatformTestCase.autodetectPlatformPrefix(); + } + + public static String getHelpersPath() { + return new File(PathManager.getHomePath(), "python/community/helpers").getPath(); } } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java index b9e9cb53b3d3..e906073074e5 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyArgumentListInspectionTest.java @@ -138,4 +138,9 @@ public class PyArgumentListInspectionTest extends PyTestCase { public void testDecoratedChangedParameters() { doTest(); } + + // PY-9605 + public void testPropertyReturnsCallable() { + doTest(); + } } diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java index 363d4c0c7242..771c4426fe84 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnresolvedReferencesInspectionTest.java @@ -298,6 +298,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase { doMultiFileTest("a.py"); } + // PY-10893 + public void testCustomNewReturnInAnotherModule() { + doMultiFileTest("a.py"); + } + private void doTest() { myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py"); myFixture.enableInspections(PyUnresolvedReferencesInspection.class); diff --git a/python/testSrc/com/jetbrains/python/testRunner/PyDocTestRunnerTest.java b/python/testSrc/com/jetbrains/python/testRunner/PyDocTestRunnerTest.java index 15a73a646e88..3571ad8192b5 100644 --- a/python/testSrc/com/jetbrains/python/testRunner/PyDocTestRunnerTest.java +++ b/python/testSrc/com/jetbrains/python/testRunner/PyDocTestRunnerTest.java @@ -2,7 +2,6 @@ package com.jetbrains.python.testRunner; import com.intellij.execution.ExecutionException; import com.intellij.execution.process.ProcessOutput; -import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.util.ArrayUtil; @@ -67,12 +66,12 @@ public class PyDocTestRunnerTest extends LightPlatformTestCase { } private static String[] runUTRunner(String workDir, String... args) throws ExecutionException { - File helpersDir = new File(PathManager.getHomePath(), "python/helpers"); - File utRunner = new File(helpersDir, "pycharm/docrunner.py"); + String helpersPath = PyTestCase.getHelpersPath(); + File utRunner = new File(helpersPath, "pycharm/docrunner.py"); List allArgs = new ArrayList(); allArgs.add(utRunner.getPath()); Collections.addAll(allArgs, args); - final ProcessOutput output = JythonUnitTestUtil.runJython(workDir, helpersDir.getPath(), ArrayUtil.toStringArray(allArgs)); + final ProcessOutput output = JythonUnitTestUtil.runJython(workDir, helpersPath, ArrayUtil.toStringArray(allArgs)); assertEquals(output.getStderr(), 0, splitLines(output.getStderr()).length); return splitLines(output.getStdout()); } diff --git a/python/testSrc/com/jetbrains/python/testRunner/PyTestRunnerTest.java b/python/testSrc/com/jetbrains/python/testRunner/PyTestRunnerTest.java index 7024879a2951..cbbcd4e409ab 100644 --- a/python/testSrc/com/jetbrains/python/testRunner/PyTestRunnerTest.java +++ b/python/testSrc/com/jetbrains/python/testRunner/PyTestRunnerTest.java @@ -72,7 +72,7 @@ public class PyTestRunnerTest extends LightPlatformTestCase { } private static String[] runUTRunner(String workDir, String... args) throws ExecutionException { - File helpersDir = new File(PathManager.getHomePath(), "python/helpers"); + File helpersDir = new File(PyTestCase.getHelpersPath()); File utRunner = new File(helpersDir, "pycharm/utrunner.py"); List allArgs = new ArrayList(); allArgs.add(utRunner.getPath()); diff --git a/python/testSrc/python-community-tests.iml b/python/testSrc/python-community-tests.iml index 38fa516e812e..6614fb726be8 100644 --- a/python/testSrc/python-community-tests.iml +++ b/python/testSrc/python-community-tests.iml @@ -10,6 +10,10 @@ + + + +