mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tests for extract superclass
formatting for extract superclass
This commit is contained in:
@@ -102,7 +102,7 @@ public class PyClassRefactoringUtil {
|
||||
public static void addMethods(final PyClass superClass, final PyElement[] elements, final boolean up) {
|
||||
if (elements.length == 0) return;
|
||||
final Project project = superClass.getProject();
|
||||
final String text = prepareClassText(superClass, elements, up, false, "Foo");
|
||||
final String text = prepareClassText(superClass, elements, up, false, null);
|
||||
|
||||
if (text == null) return;
|
||||
|
||||
@@ -126,7 +126,11 @@ public class PyClassRefactoringUtil {
|
||||
sibling = sibling == null ? elements[0].getParent().getPrevSibling() : sibling;
|
||||
final String white = sibling.getText();
|
||||
final StringBuilder builder = new StringBuilder("class ");
|
||||
builder.append(preparedClassName).append(":\n");
|
||||
if (preparedClassName != null) {
|
||||
builder.append(preparedClassName).append(":");
|
||||
} else {
|
||||
builder.append("Foo").append(":\n");
|
||||
}
|
||||
boolean hasChanges = false;
|
||||
for (PyElement element : elements) {
|
||||
final String name = element.getName();
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.refactoring.classes.extractSuperclass;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -72,7 +73,7 @@ public class PyExtractSuperclassHelper {
|
||||
}
|
||||
|
||||
private static void placeNewClass(Project project, PyClass newClass, PyClass clazz, String targetFile) {
|
||||
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(targetFile));
|
||||
VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(ApplicationManagerEx.getApplicationEx().isUnitTestMode() ? targetFile : VfsUtil.pathToUrl(targetFile));
|
||||
// file is the same as the source
|
||||
if (file == clazz.getContainingFile().getVirtualFile()) {
|
||||
PyPsiUtils.addBeforeInParent(clazz, newClass, newClass.getNextSibling());
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Suppa:
|
||||
|
||||
def foo(self):
|
||||
print "bar"
|
||||
|
||||
class Foo(Suppa):
|
||||
def bar(self):
|
||||
print "foo"
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo:
|
||||
def bar(self):
|
||||
print "foo"
|
||||
|
||||
def foo(self):
|
||||
print "bar"
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.jetbrains.python.refactoring.classes;
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.jetbrains.python.PythonTestUtil;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyElement;
|
||||
import com.jetbrains.python.refactoring.classes.extractSuperclass.PyExtractSuperclassHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dennis.Ushakov
|
||||
*/
|
||||
public class PyExtractSuperclassTest extends PyClassRefactoringTest {
|
||||
public void testSimple() throws Exception {
|
||||
doHelperTest("Foo", "Suppa", null, ".foo");
|
||||
}
|
||||
|
||||
private void doHelperTest(final String className, final String superclassName, final String expectedError, final String... membersName) throws Exception {
|
||||
try {
|
||||
String baseName = getTestName(true);
|
||||
myFixture.configureByFile(baseName + ".before.py");
|
||||
final PyClass clazz = findClass(className);
|
||||
final List<PyMemberInfo> members = new ArrayList<PyMemberInfo>();
|
||||
for (String memberName : membersName) {
|
||||
final PyElement member = findMember(className, memberName);
|
||||
assertNotNull(member);
|
||||
members.add(new PyMemberInfo(member));
|
||||
}
|
||||
|
||||
new WriteCommandAction.Simple(myFixture.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
//noinspection ConstantConditions
|
||||
PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, myFixture.getFile().getVirtualFile().getUrl());
|
||||
}
|
||||
}.execute();
|
||||
myFixture.checkResultByFile(baseName + ".after.py");
|
||||
} catch (Exception e) {
|
||||
if (expectedError == null) throw e;
|
||||
assertEquals(expectedError, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PythonTestUtil.getTestDataPath() + "/refactoring/extractsuperclass/";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user