mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
Move Python completion test to common Python tests
GitOrigin-RevId: 120f8943fbd93a55d6e2e2d9d9e5e3b36c8c0a4f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9846716abb
commit
593ea26bb1
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,8 @@
|
||||
package com.jetbrains.python.fixture
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
@@ -21,12 +24,16 @@ interface CommonPythonCodeInsightTestFixture {
|
||||
|
||||
val psiManager: PsiManager
|
||||
|
||||
val testRootDisposable: Disposable
|
||||
|
||||
fun setUp() {
|
||||
}
|
||||
|
||||
fun tearDown() {
|
||||
}
|
||||
|
||||
fun setTestDataPath(path: String)
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun runTest(test: ThrowableRunnable<Throwable>) {
|
||||
test.run()
|
||||
@@ -37,11 +44,46 @@ interface CommonPythonCodeInsightTestFixture {
|
||||
|
||||
fun configureByFile(filePath: String): PsiFile?
|
||||
|
||||
fun configureByFiles(vararg filePaths: String): Array<PsiFile>
|
||||
|
||||
fun configureByText(fileType: PythonFileType, text: String): PsiFile?
|
||||
|
||||
fun configureByText(fileName: String, text: String): PsiFile?
|
||||
|
||||
fun configureFromTempProjectFile(filePath: String): PsiFile?
|
||||
|
||||
fun copyFileToProject(sourceFilePath: String): VirtualFile?
|
||||
|
||||
fun copyDirectoryToProject(sourceFilePath: String, targetPath: String): VirtualFile?
|
||||
|
||||
fun findFileInTempDir(filePath: String): VirtualFile?
|
||||
|
||||
fun addFileToProject(relativePath: String, fileText: String): PsiFile?
|
||||
|
||||
fun completeBasic(): Array<LookupElement>?
|
||||
|
||||
fun completeBasicAllCarets(charToTypeAfterCompletion: Char?): List<LookupElement>
|
||||
|
||||
fun complete(completionType: CompletionType): Array<LookupElement>?
|
||||
|
||||
fun complete(type: CompletionType, invocationCount: Int): Array<LookupElement>?
|
||||
|
||||
fun checkResultByFile(expectedFile: String)
|
||||
|
||||
fun getLookupElementStrings(): List<String>?
|
||||
|
||||
fun type(c: Char)
|
||||
|
||||
fun type(s: String)
|
||||
|
||||
fun checkResult(text: String)
|
||||
|
||||
fun finishLookup(completionChar: Char)
|
||||
|
||||
fun addExcludedRoot(rootPath: String)
|
||||
|
||||
fun getLookupElements(): Array<LookupElement>?
|
||||
|
||||
// TODO: this belongs to test case not fixture [utikeev]
|
||||
fun runWithSourceRoots(sourceRoots: List<VirtualFile>, runnable: Runnable)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.jetbrains.python.fixture;
|
||||
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -24,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class CommonPythonTestCase extends TestCase {
|
||||
protected CommonPythonCodeInsightTestFixture myFixture;
|
||||
@@ -156,6 +160,10 @@ public abstract class CommonPythonTestCase extends TestCase {
|
||||
assertEmpty(collection.toString(), collection);
|
||||
}
|
||||
|
||||
public static void assertEmpty(@NotNull Object[] array) {
|
||||
assertOrderedEquals(array);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toString(@NotNull Iterable<?> collection) {
|
||||
if (!collection.iterator().hasNext()) {
|
||||
@@ -257,4 +265,104 @@ public abstract class CommonPythonTestCase extends TestCase {
|
||||
assertNull("Operations should have been performed on stubs but caused file to be parsed: " + file.getVirtualFile().getPath(),
|
||||
((PyFileImpl)file).getTreeElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> void assertSameElements(@NotNull T[] actual, @NotNull T... expected) {
|
||||
assertSameElements(Arrays.asList(actual), expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <T> void assertSameElements(@NotNull Collection<? extends T> actual, @NotNull T... expected) {
|
||||
assertSameElements(actual, Arrays.asList(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order
|
||||
*/
|
||||
public static <T> void assertSameElements(@NotNull Collection<? extends T> actual, @NotNull Collection<? extends T> expected) {
|
||||
assertSameElements("", actual, expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks {@code actual} contains same elements (in {@link #equals(Object)} meaning) as {@code expected} irrespective of their order
|
||||
*/
|
||||
public static <T> void assertSameElements(@NotNull String message, @NotNull Collection<? extends T> actual, @NotNull Collection<? extends T> expected) {
|
||||
if (actual.size() != expected.size() || !new HashSet<>(expected).equals(new HashSet<T>(actual))) {
|
||||
Assert.assertEquals(message, new HashSet<>(expected), new HashSet<T>(actual));
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> void assertContainsElements(@NotNull Collection<? extends T> collection, @NotNull T... expected) {
|
||||
assertContainsElements(collection, Arrays.asList(expected));
|
||||
}
|
||||
|
||||
public static <T> void assertContainsElements(@NotNull Collection<? extends T> collection, @NotNull Collection<? extends T> expected) {
|
||||
ArrayList<T> copy = new ArrayList<>(collection);
|
||||
copy.retainAll(expected);
|
||||
assertSameElements(toString(collection), copy, expected);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> void assertDoesntContain(@NotNull Collection<? extends T> collection, @NotNull T... notExpected) {
|
||||
assertDoesntContain(collection, Arrays.asList(notExpected));
|
||||
}
|
||||
|
||||
public static <T> void assertDoesntContain(@NotNull Collection<? extends T> collection, @NotNull Collection<? extends T> notExpected) {
|
||||
ArrayList<T> expected = new ArrayList<>(collection);
|
||||
expected.removeAll(notExpected);
|
||||
assertSameElements(collection, expected);
|
||||
}
|
||||
|
||||
public static void assertNullOrEmpty(@Nullable Collection<?> collection) {
|
||||
if (collection == null) return;
|
||||
assertEmpty("", collection);
|
||||
}
|
||||
|
||||
public static void assertSize(int expectedSize, @NotNull Object[] array) {
|
||||
if (array.length != expectedSize) {
|
||||
assertEquals(toString(Arrays.asList(array)), expectedSize, array.length);
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertSize(int expectedSize, @NotNull Collection<?> c) {
|
||||
if (c.size() != expectedSize) {
|
||||
assertEquals(toString(c), expectedSize, c.size());
|
||||
}
|
||||
}
|
||||
|
||||
protected void runWithAdditionalClassEntryInSdkRoots(@NotNull VirtualFile directory, @NotNull Runnable runnable) {
|
||||
final Sdk sdk = PythonSdkUtil.findPythonSdk(myFixture.getModule());
|
||||
assertNotNull(sdk);
|
||||
runWithAdditionalRoot(sdk, directory, OrderRootType.CLASSES, (__) -> runnable.run());
|
||||
}
|
||||
|
||||
private static void runWithAdditionalRoot(@NotNull Sdk sdk,
|
||||
@NotNull VirtualFile root,
|
||||
@NotNull OrderRootType rootType,
|
||||
@NotNull Consumer<VirtualFile> rootConsumer) {
|
||||
WriteAction.run(() -> {
|
||||
final SdkModificator modificator = sdk.getSdkModificator();
|
||||
assertNotNull(modificator);
|
||||
modificator.addRoot(root, rootType);
|
||||
modificator.commitChanges();
|
||||
});
|
||||
try {
|
||||
rootConsumer.accept(root);
|
||||
}
|
||||
finally {
|
||||
WriteAction.run(() -> {
|
||||
final SdkModificator modificator = sdk.getSdkModificator();
|
||||
assertNotNull(modificator);
|
||||
modificator.removeRoot(root, rootType);
|
||||
modificator.commitChanges();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,5 +15,7 @@
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-stdlib-jdk8" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" scope="TEST" />
|
||||
<orderEntry type="library" name="Guava" level="project" scope="TEST"/>
|
||||
<orderEntry type="library" name="StreamEx" level="project" scope="TEST"/>
|
||||
</component>
|
||||
</module>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,24 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.fixtures
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import com.intellij.testFramework.TestLoggerFactory
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import com.jetbrains.python.PythonFileType
|
||||
import com.jetbrains.python.PythonTestUtil
|
||||
import com.jetbrains.python.fixture.CommonPythonCodeInsightTestFixture
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import java.io.File
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
|
||||
@@ -33,6 +39,8 @@ class PlatformPythonCodeInsightTestFixture : CommonPythonCodeInsightTestFixture
|
||||
get() = myDelegateFixture.psiManager
|
||||
override val tempDirRoot: VirtualFile
|
||||
get() = requireNotNull(myDelegateFixture.tempDirFixture.getFile("."))
|
||||
override val testRootDisposable: Disposable
|
||||
get() = myDelegateFixture.testRootDisposable
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
@@ -53,6 +61,10 @@ class PlatformPythonCodeInsightTestFixture : CommonPythonCodeInsightTestFixture
|
||||
myDelegateTestCase.addSuppressedException(e)
|
||||
}
|
||||
|
||||
override fun setTestDataPath(path: String) {
|
||||
myDelegateFixture.testDataPath = path
|
||||
}
|
||||
|
||||
override fun configureByFile(filePath: String): PsiFile? = myDelegateFixture.configureByFile(filePath)
|
||||
|
||||
override fun configureByText(fileType: PythonFileType, text: String): PsiFile? = myDelegateFixture.configureByText(fileType, text)
|
||||
@@ -62,8 +74,67 @@ class PlatformPythonCodeInsightTestFixture : CommonPythonCodeInsightTestFixture
|
||||
override fun copyDirectoryToProject(sourceFilePath: String, targetPath: String): VirtualFile? =
|
||||
myDelegateFixture.copyDirectoryToProject(sourceFilePath, targetPath)
|
||||
|
||||
override fun addFileToProject(relativePath: String, fileText: String): PsiFile? = myDelegateFixture.addFileToProject(relativePath,
|
||||
fileText)
|
||||
override fun addFileToProject(relativePath: String, fileText: String): PsiFile? =
|
||||
myDelegateFixture.addFileToProject(relativePath, fileText)
|
||||
|
||||
override fun configureByFiles(vararg filePaths: String): Array<PsiFile> = myDelegateFixture.configureByFiles(*filePaths)
|
||||
|
||||
override fun configureFromTempProjectFile(filePath: String): PsiFile? = myDelegateFixture.configureFromTempProjectFile(filePath)
|
||||
|
||||
override fun copyFileToProject(sourceFilePath: String): VirtualFile? = myDelegateFixture.copyFileToProject(sourceFilePath)
|
||||
|
||||
override fun findFileInTempDir(filePath: String): VirtualFile? = myDelegateFixture.findFileInTempDir(filePath)
|
||||
|
||||
override fun completeBasic(): Array<LookupElement>? = myDelegateFixture.completeBasic()
|
||||
|
||||
override fun completeBasicAllCarets(charToTypeAfterCompletion: Char?): List<LookupElement> =
|
||||
myDelegateFixture.completeBasicAllCarets(charToTypeAfterCompletion)
|
||||
|
||||
override fun complete(completionType: CompletionType): Array<LookupElement>? = myDelegateFixture.complete(completionType)
|
||||
|
||||
override fun complete(type: CompletionType, invocationCount: Int): Array<LookupElement>? =
|
||||
myDelegateFixture.complete(type, invocationCount)
|
||||
|
||||
override fun checkResultByFile(expectedFile: String) {
|
||||
myDelegateFixture.checkResultByFile(expectedFile)
|
||||
}
|
||||
|
||||
override fun getLookupElementStrings(): List<String>? = myDelegateFixture.lookupElementStrings
|
||||
|
||||
override fun type(c: Char) {
|
||||
myDelegateFixture.type(c)
|
||||
}
|
||||
|
||||
override fun type(s: String) {
|
||||
myDelegateFixture.type(s)
|
||||
}
|
||||
|
||||
override fun checkResult(text: String) {
|
||||
myDelegateFixture.checkResult(text)
|
||||
}
|
||||
|
||||
override fun finishLookup(completionChar: Char) {
|
||||
myDelegateFixture.finishLookup(completionChar)
|
||||
}
|
||||
|
||||
override fun addExcludedRoot(rootPath: String) {
|
||||
val dir = myDelegateFixture.findFileInTempDir(rootPath)
|
||||
assertNotNull(dir)
|
||||
PsiTestUtil.addExcludedRoot(module, dir)
|
||||
Disposer.register(myDelegateFixture.projectDisposable, Disposable { PsiTestUtil.removeExcludedRoot(module, dir) })
|
||||
}
|
||||
|
||||
override fun getLookupElements(): Array<LookupElement>? = myDelegateFixture.lookupElements
|
||||
|
||||
override fun runWithSourceRoots(sourceRoots: List<VirtualFile>, runnable: Runnable) {
|
||||
sourceRoots.forEach { root -> PsiTestUtil.addSourceRoot(module, root) }
|
||||
try {
|
||||
runnable.run()
|
||||
}
|
||||
finally {
|
||||
sourceRoots.forEach { root -> PsiTestUtil.removeSourceRoot(module, root) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PyDelegateTestCase : PyTestCase() {
|
||||
|
||||
Reference in New Issue
Block a user