package com.jetbrains.python;

import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.search.ProjectScope;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.testFramework.PsiTestUtil;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.search.PyClassInheritorsSearch;
import com.jetbrains.python.psi.stubs.PyClassNameIndex;

import java.util.Collection;

/**
 * @author yole
 */
public class PyInheritorsSearchTest extends CodeInsightTestCase {
  public void testSimple() throws Exception {
    setupProject();
    final PyClass pyClass = findClass("A");
    Collection<PyClass> inheritors = PyClassInheritorsSearch.search(pyClass, false).findAll();
    assertEquals(2, inheritors.size());
  }

  public void testDeep() throws Exception {
    setupProject();
    final PyClass pyClass = findClass("A");
    Collection<PyClass> inheritors = PyClassInheritorsSearch.search(pyClass, true).findAll();
    assertEquals(2, inheritors.size());
  }

  public void testDotted() throws Exception {
    setupProject();
    final PyClass pyClass = findClass("A");
    Collection<PyClass> inheritors = PyClassInheritorsSearch.search(pyClass, true).findAll();
    assertEquals(1, inheritors.size());
  }

  private void setupProject() throws Exception {
    String testName = getTestName(true);
    String root = PythonTestUtil.getTestDataPath() + "/inheritors/" + testName;
    VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);
    PsiTestUtil.addSourceContentToRoots(myModule, rootDir);
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  }

  private PyClass findClass(final String name) {
    final Collection<PyClass> classes = StubIndex.getInstance().get(PyClassNameIndex.KEY, name, myProject,
                                                                    ProjectScope.getProjectScope(myProject));
    assertEquals(1, classes.size());
    return classes.iterator().next();
  }
}

@@ -48,84 +48,31 @@
 lij.
-codeInsight.CodeInsightTestCase;%0Aimport com.intellij.openapi.vfs.VirtualFile
+openapi.project.Project
 ;%0Aim
@@ -214,42 +214,56 @@
 com.
-intellij.testFramework.PsiTestUtil
+jetbrains.python.fixtures.PyLightFixtureTestCase
 ;%0Aim
@@ -524,19 +524,22 @@
 nds 
-CodeInsight
+PyLightFixture
 Test
@@ -1389,258 +1389,53 @@
     
-String root = PythonTestUtil.getTestDataPath() + %22/inheritors/%22 + testName;%0A    VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);%0A    PsiTestUtil.addSourceContentToRoots(myModule, rootDir
+myFixture.copyDirectoryToProject(testName, %22%22
 );%0A 
@@ -1470,23 +1470,36 @@
 tance(my
+Fixture.get
 Project
+()
 ).commit
@@ -1568,16 +1568,68 @@
 name) %7B%0A
+    final Project project = myFixture.getProject();%0A
     fina
@@ -1716,19 +1716,17 @@
 , name, 
-myP
+p
 roject,%0A
@@ -1826,11 +1826,9 @@
 ope(
-myP
+p
 roje
@@ -1911,11 +1911,129 @@
 t();%0A  %7D
+%0A%0A  @Override%0A  protected String getTestDataPath() %7B%0A    return PythonTestUtil.getTestDataPath() + %22/inheritors/%22;%0A  %7D
 %0A%7D%0A

convert test to PyLightFixtureTestCase