gleb-sevruk / pycrunch-engine

NCrunch inspired tool for continuous testing Python
https://pycrunch.com
Other
57 stars 8 forks source link

Unable to use pycrunch to find relevant lines of code. #74

Closed psampathkumar closed 12 months ago

psampathkumar commented 2 years ago

Pycrunch seems to work for me in small projects, in the same conda enviroment, but I am unable to use my existing tests along with pycrunch to find relevant lines of code.

These stacktraces might be helpful. Is there a way to run it in verbose mode or something to check what goes wrong ?

java.lang.NullPointerException
    at com.gleb.pycrunch.NavigateToTest.Go(NavigateToTest.java:36)
    at com.gleb.pycrunch.PycrunchToolWindow$1.mouseClicked(PycrunchToolWindow.java:104)
    at java.desktop/java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:278)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6657)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3345)
    at com.intellij.ui.treeStructure.Tree.processMouseEvent(Tree.java:394)
    at java.desktop/java.awt.Component.processEvent(Component.java:6419)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5029)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4861)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4556)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2793)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4861)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
    at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:820)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:743)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:119)
    at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

and

    java.lang.Throwable: Already disposed: MessageBus(owner=Project(name=RNN, containerState=DISPOSE_COMPLETED, componentStore=/home/pranav/work-stuff/RNN) (disposed), disposeState= 2)
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:182)
    at com.intellij.util.messages.impl.MessageBusImpl.checkNotDisposed(MessageBusImpl.java:334)
    at com.intellij.util.messages.impl.MessageBusImpl.access$000(MessageBusImpl.java:34)
    at com.intellij.util.messages.impl.MessageBusImpl$MessagePublisher.invoke(MessageBusImpl.java:164)
    at com.sun.proxy.$Proxy134.engineDidDisconnect(Unknown Source)
    at com.gleb.pycrunch.PycrunchConnector.lambda$engineWillDisconnect$13(PycrunchConnector.java:274)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
    at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
    at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
    at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
    at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
psampathkumar commented 2 years ago

I think the engine is working fine, I am able to see the relevant lines of code in the webUI, the problem is somewhere in Pycharm

gleb-sevruk commented 2 years ago
public class NavigateToTest {
    public void Go(PycrunchTestMetadata testByFqn, PycrunchConnector _connector) {

        VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(testByFqn.filename);
//        PsiDocumentManagerImpl.getInstance(_connector._project).getPsiFile(fileByPath)
        PsiDocumentManager documentManager = PsiDocumentManager.getInstance(_connector._project);
        Document document = FileDocumentManager.getInstance().getDocument(fileByPath);
        PyFile psiFile = (PyFile) documentManager.getPsiFile(document);
        String fqn = testByFqn.name;
        int text_offset = 0;
        boolean contains = fqn.contains("::");
        if (contains) {
            String[] split = fqn.split("::");
            PyClass topLevelClass = psiFile.findTopLevelClass(split[0]);
            if (topLevelClass != null) {
                PyFunction test_method2 = topLevelClass.findMethodByName(split[1], false, null);
                if (test_method2 != null) {
                    text_offset = test_method2.getTextOffset();
                }
            }
        } else {
            PsiElement psiElement = psiFile.findExportedName(fqn);
/*line 36 */            text_offset = psiElement.getTextOffset();
        }
        OpenFileDescriptor openFileDescriptor;
        if (text_offset > 0) {
            openFileDescriptor = new OpenFileDescriptor(_connector._project, fileByPath, text_offset);
        }
        else {
            openFileDescriptor = new OpenFileDescriptor(_connector._project, fileByPath, 0, -1, true);
        }

        openFileDescriptor.navigate(true);
    }
}

Here is the source file for pycharm plugin.

It looks like either Conda env is not supported entirely or you didn't select environment after opening the project. (By some reason Pycharm indexes doesn't work as expected)

psampathkumar commented 2 years ago

I am not sure if it is a problem with conda. I am able to get the expected behaviour in the same enviroment, (infact even testing with some smaller functions in my project).

gleb-sevruk commented 12 months ago

Please reopen if still actual and add more details, steps to reproduce