The following forum message was posted by  at 
http://sourceforge.net/projects/pydev/forums/forum/293649/topic/4431233:

I have looking for the best way to integrate nosetests with PyDev.
I have been able to make it work as a Builder, but that doesn't put Markers
on your code where it failed.
So, I am looking at PyDev Scripting with Jython.
I started with a script that I found on StackOverflow, but it didn't work --
so I added some debug code to print out the types of objects and their 
attributes
-- but they don't seem to have any attributes!
( the dir function returns nothing?, and type(x) often returns:
org.python.core.PyJavaInstance )
Maybe I just don't "get" how Jython works?
Maybe I need to know how PyDev works, and how Eclipse works?
How can I figure out how to make this work if I can't debug it, and I can't
see the type or attributes of the objects?
Does anyone else already have a Jython script similar to this, that would run
tests and add Markers to the code?

Here's what I have so far, which started as a copy from a StackOverflow answer,
with my attempts at introspection thrown in:
[code]
print '----- nicks_pydev_plugins / pyedit_nose ---------'

assert cmd is not None
assert editor is not None

def show(x):
    print '----------'
    print 'SHOW:',type(x)
    for a in dir(x):
        print a, getattr(x,a)
    print '----------'

if cmd == 'onSave':

    from java.lang import Runtime
    from java.io import BufferedReader
    from java.io import InputStreamReader

    from org.eclipse.core.resources import ResourcesPlugin
    from org.eclipse.core.resources import IMarker
    from org.eclipse.core.resources import IResource

    runtime = Runtime.getRuntime()
    show(runtime)

    proc = Runtime.getRuntime().exec('nosetests
/home/nick/workspace/couchtest')
    show(proc)
    show(proc.inputStream)
    show(cmd)
    
    extra_message
= BufferedReader(InputStreamReader(proc.inputStream)).readLine()
    show(extra_message)
    
    show('String')
    
    if extra_message:
        print extra_message
    
        r = ResourcesPlugin.getWorkspace().getRoot()
        for marker in r.findMarkers(IMarker.PROBLEM, False,
IResource.DEPTH_INFINITE):
            msg = marker.getAttribute(IMarker.MESSAGE)
            if msg:
                if msg.startswith("Some test failed!"):
                    marker.delete()
    
        for rr in r.getProjects():
            marker = rr.createMarker(IMarker.PROBLEM)
            marker.setAttribute(IMarker.MESSAGE, "Some test failed! " +
extra_message)
            marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH)
            marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR)

[/code]

...and here is the output:
[code]----- nicks_pydev_plugins / pyedit_nose ---------
----------
SHOW: org.python.core.PyJavaInstance
----------
----------
SHOW: org.python.core.PyJavaInstance
----------
----------
SHOW: org.python.core.PyJavaInstance
----------
----------
SHOW: org.python.core.PyString
----------
----------
SHOW: org.python.core.PyNone
----------
----------
SHOW: org.python.core.PyString
----------[/code]




------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Pydev-users mailing list
Pydev-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pydev-users

Reply via email to