use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyExtractSuperclassTest method testMultifileNew.
public void testMultifileNew() {
String baseName = "/refactoring/extractsuperclass/multifile/";
myFixture.configureByFile(baseName + "source.py");
final String className = "Foo";
final String superclassName = "Suppa";
final PyClass clazz = findClass(className);
final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
final PyElement member = findMember(className, ".foo");
members.add(MembersManager.findMember(clazz, member));
final VirtualFile base_dir = myFixture.getFile().getVirtualFile().getParent();
new WriteCommandAction.Simple(myFixture.getProject()) {
@Override
protected void run() throws Throwable {
//noinspection ConstantConditions
final String path = base_dir.getPath() + "/a/b";
PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path);
}
}.execute();
final PsiManager psi_mgr = PsiManager.getInstance(myFixture.getProject());
VirtualFile vfile = base_dir.findChild("a");
assertTrue(vfile.isDirectory());
vfile = vfile.findChild(PyNames.INIT_DOT_PY);
assertNotNull(vfile);
vfile = base_dir.findChild("a").findChild("b");
assertTrue(vfile.isDirectory());
vfile = vfile.findChild(PyNames.INIT_DOT_PY);
assertNotNull(vfile);
PsiFile psi_file = psi_mgr.findFile(vfile);
String result = psi_file.getText().trim();
File expected_file = new File(getTestDataPath() + baseName, "target.new.py");
String expected = psi_mgr.findFile(LocalFileSystem.getInstance().findFileByIoFile(expected_file)).getText().trim();
assertEquals(expected, result);
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyPullUpInfoModelTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
myFixture.configureByFile("/refactoring/pullup/pyPullUpInfoModel.py");
final PyClass childClass = getClassByName("ChildWithDependencies");
final PyClass parentClass = getClassByName("SomeParent");
mySut = new PyPullUpInfoModel(childClass, new MocksControl(MocksControl.MockType.NICE).createMock(PyPullUpView.class));
mySut.setSuperClass(parentClass);
myMemberInfos = new PyMemberInfoStorage(childClass).getClassMemberInfos(childClass);
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyPullUpPresenterTest method configureByClass.
/**
* Creates presenter (sut) by class
*
* @param name name of class
* @return presenter
*/
private PyPullUpPresenterImpl configureByClass(@NotNull final String name) {
final PyClass childClass = getClassByName(name);
final PyMemberInfoStorage storage = new PyMemberInfoStorage(childClass);
return new PyPullUpPresenterImpl(myView, storage, childClass);
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyPullUpPresenterTest method testConflicts.
/**
* Ensures that presenter displays conflicts if destination class already has that members
*/
public void testConflicts() throws Exception {
final PyPullUpPresenterImpl sut = configureByClass("ChildWithConflicts");
configureParent();
final Collection<PyMemberInfo<PyElement>> infos = getMemberInfos(sut);
final Capture<MultiMap<PyClass, PyMemberInfo<?>>> conflictCapture = new Capture<>();
EasyMock.expect(myView.showConflictsDialog(EasyMock.capture(conflictCapture), EasyMock.<Collection<PyMemberInfo<?>>>anyObject())).andReturn(false).anyTimes();
EasyMock.expect(myView.getSelectedMemberInfos()).andReturn(infos).anyTimes();
final PyClass parent = getClassByName("ParentWithConflicts");
EasyMock.expect(myView.getSelectedParent()).andReturn(parent).anyTimes();
myMocksControl.replay();
sut.okClicked();
final MultiMap<PyClass, PyMemberInfo<?>> conflictMap = conflictCapture.getValue();
Assert.assertTrue("No conflicts found, while it should", conflictMap.containsKey(parent));
final Collection<String> conflictedMemberNames = Collections2.transform(conflictMap.get(parent), NameTransformer.INSTANCE);
Assert.assertThat("Failed to find right conflicts", conflictedMemberNames, Matchers.containsInAnyOrder("extends Bar", "CLASS_FIELD", "self.instance_field", "my_func(self)", "__init__(self)"));
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class Py3UnresolvedReferencesInspectionTest method testMetaclassStub.
public void testMetaclassStub() {
doMultiFileTest("a.py");
final Project project = myFixture.getProject();
Collection<PyClass> classes = PyClassNameIndex.find("M", project, GlobalSearchScope.allScope(project));
for (PyClass cls : classes) {
final PsiFile file = cls.getContainingFile();
if (file instanceof PyFile) {
assertNotParsed((PyFile) file);
}
}
}
Aggregations