use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyExtractSuperclassPresenterTest method testInvalidSuperClassNameLeadsToError.
/**
* Checks that presenter displays error if user enters invalid name for new class
*/
public void testInvalidSuperClassNameLeadsToError() {
final String className = "Child";
final PyClass aClass = getClassByName(className);
final List<PyMemberInfo<PyElement>> classMemberInfos = new PyMemberInfoStorage(aClass).getClassMemberInfos(aClass);
assert !classMemberInfos.isEmpty() : "No member infos for " + className;
final PyMemberInfo<PyElement> pyMemberInfo = classMemberInfos.get(0);
EasyMock.expect(myView.getSelectedMemberInfos()).andReturn(Collections.singletonList(pyMemberInfo)).anyTimes();
EasyMock.expect(myView.getSuperClassName()).andReturn("INVALID CLASS NAME").anyTimes();
final Capture<String> errorMessageCapture = configureViewToCaptureError();
final PyExtractSuperclassPresenterImpl sut = configureByClass(className);
myMocksControl.replay();
sut.launch();
sut.okClicked();
Assert.assertTrue("No error displayed for invalid class name", errorMessageCapture.hasCaptured());
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyExtractSuperclassTest method doSimpleTest.
private void doSimpleTest(final String className, final String superclassName, final String expectedError, final boolean sameFile, boolean asAbstract, final String... membersName) throws Exception {
try {
String baseName = "/refactoring/extractsuperclass/" + getTestName(true);
myFixture.configureByFile(baseName + ".before.py");
final PyClass clazz = findClass(className);
final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
for (String memberName : membersName) {
final PyElement member = findMember(className, memberName);
final PyMemberInfo<PyElement> memberInfo = MembersManager.findMember(clazz, member);
memberInfo.setToAbstract(asAbstract);
members.add(memberInfo);
}
new WriteCommandAction.Simple(myFixture.getProject()) {
@Override
protected void run() throws Throwable {
//noinspection ConstantConditions
final String url = sameFile ? myFixture.getFile().getVirtualFile().getUrl() : myFixture.getFile().getVirtualFile().getParent().getUrl();
PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, url);
}
}.execute();
myFixture.checkResultByFile(baseName + ".after.py");
} catch (Exception e) {
if (expectedError == null)
throw e;
assertEquals(expectedError, e.getMessage());
}
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyExtractSuperclassTest method testMultifileAppend.
public void testMultifileAppend() {
// this is half-copy-paste of testMultifileNew. generalization won't make either easier to follow.
String baseName = "/refactoring/extractsuperclass/multifile/";
myFixture.configureByFiles(baseName + "source.py", baseName + "a/__init__.py", baseName + "a/b/__init__.py", baseName + "a/b/foo.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 {
//TODO: Test via presenter
//noinspection ConstantConditions
final String path = base_dir.getPath() + "/a/b";
PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path + "/foo.py");
}
}.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());
assertNotNull(vfile.findChild(PyNames.INIT_DOT_PY));
vfile = vfile.findChild("foo.py");
assertNotNull(vfile);
PsiFile psi_file = psi_mgr.findFile(vfile);
String result = psi_file.getText().trim();
File expected_file = new File(getTestDataPath() + baseName, "target.append.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 PyPullUpTest method doPullUp.
private void doPullUp(final String className, final String superClassName, final boolean toAbstract, final String... memberNames) {
final PyClass clazz = findClass(className);
final PyClass superClass = findClass(superClassName);
final Collection<PyMemberInfo<PyElement>> membersToMove = new ArrayList<>(memberNames.length);
for (final String memberName : memberNames) {
final PyElement member = findMember(className, memberName);
final PyMemberInfo<PyElement> memberInfo = MembersManager.findMember(clazz, member);
memberInfo.setToAbstract(toAbstract);
membersToMove.add(memberInfo);
}
moveViaProcessor(clazz.getProject(), new PyPullUpProcessor(clazz, superClass, membersToMove));
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyPushDownTest method doProcessorTest.
private void doProcessorTest(final String className, final String expectedError, final String... memberNames) throws Exception {
try {
String baseName = "/refactoring/pushdown/" + getTestName(true);
myFixture.configureByFile(baseName + ".before.py");
final PyClass clazz = findClass(className);
final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
for (String memberName : memberNames) {
final PyElement member = findMember(className, memberName);
members.add(MembersManager.findMember(clazz, member));
}
final PyPushDownProcessor processor = new PyPushDownProcessor(myFixture.getProject(), members, clazz);
moveViaProcessor(myFixture.getProject(), processor);
myFixture.checkResultByFile(baseName + ".after.py");
} catch (Exception e) {
if (expectedError == null)
throw e;
assertTrue(e.getMessage(), e.getMessage().contains(expectedError));
}
}
Aggregations