use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyUnwrapperTest method doNegativeTest.
private void doNegativeTest() {
String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
myFixture.configureByFile(before);
UnwrapHandler h = new UnwrapHandler() {
@Override
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
assertEmpty(options);
}
};
h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyUnwrapperTest method doTest.
private void doTest(final int option) {
String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
String after = "refactoring/unwrap/" + getTestName(true) + "_after.py";
myFixture.configureByFile(before);
UnwrapHandler h = new UnwrapHandler() {
@Override
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
assertTrue("No available options to unwrap", !options.isEmpty());
options.get(option).actionPerformed(null);
}
};
h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
myFixture.checkResultByFile(after, true);
}
use of com.intellij.psi.PsiFile 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.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyTestCreatorTest method testCreateTest.
public void testCreateTest() throws Exception {
myFixture.configureByFile("/create_tests/create_tst.py");
final IMocksControl mockControl = createNiceControl();
final CreateTestDialog dialog = mockControl.createMock(CreateTestDialog.class);
expect(dialog.getFileName()).andReturn("tests.py").anyTimes();
expect(dialog.getClassName()).andReturn("Spam").anyTimes();
// Target dir is first module source
final VirtualFile root = ModuleRootManager.getInstance(myFixture.getModule()).getSourceRoots()[0];
expect(dialog.getTargetDir()).andReturn(root.getCanonicalPath()).anyTimes();
expect(dialog.getMethods()).andReturn(Arrays.asList("eggs", "eggs_and_ham")).anyTimes();
mockControl.replay();
WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
final PsiFile file = PyTestCreator.generateTest(myFixture.getProject(), dialog).getContainingFile();
myFixture.configureByText(file.getFileType(), file.getText());
myFixture.checkResultByFile("/create_tests/create_tst.expected.py");
});
}
use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.
the class PyUnwrapperTest method doNegativeTest.
private void doNegativeTest(final String optionName) {
String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
myFixture.configureByFile(before);
UnwrapHandler h = new UnwrapHandler() {
@Override
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
for (AnAction option : options) {
assertFalse("\"" + optionName + "\" is available to unwrap ", option.toString().contains(optionName));
}
}
};
h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
Aggregations