Picon

nose and jython

Hi guys,

I was wondering if anyone tried to run nose under jython? I must
confess that most probably I've done something wrong as it doesn't
really work for me.

I have both Python 2.5.4 and Jython 2.5.0 installed on my Mac OS
10.5.8. nose was initially installed using easy_install for Python
2.5.4. Then I've just copied the
nosetests script to the jython bin directory and modified the first line from:

#!/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python

to

#!/Users/alex/bin/jython2.5.0/bin/jython

but then I'm seeing the following errors when trying to run nosetests
directly from the Terminal

/Users/alex/bin/jython2.5.0/bin/nosetests: line 3: __requires__:
command not found
/Users/alex/bin/jython2.5.0/bin/nosetests: line 4: import: command not found
from: can't read /var/mail/pkg_resources
/Users/alex/bin/jython2.5.0/bin/nosetests: line 7: syntax error near
unexpected token `newline'
/Users/alex/bin/jython2.5.0/bin/nosetests: line 7: `sys.exit('

2. Second attempt was to run jython nosetests test_module.py, but this
results in errors too:
(Continue reading)

Philip Jenvey | 1 Sep 01:51
Gravatar

Re: nose and jython


On Aug 31, 2009, at 4:23 PM, Alexandru Popescu ☀ wrote:

> Hi guys,
>
> I was wondering if anyone tried to run nose under jython? I must
> confess that most probably I've done something wrong as it doesn't
> really work for me.
>
> I have both Python 2.5.4 and Jython 2.5.0 installed on my Mac OS
> 10.5.8. nose was initially installed using easy_install for Python
> 2.5.4. Then I've just copied the
> nosetests script to the jython bin directory and modified the first  
> line from:
>
> #!/Library/Frameworks/Python.framework/Versions/2.5/Resources/ 
> Python.app/Contents/MacOS/Python
>
> to
>
> #!/Users/alex/bin/jython2.5.0/bin/jython
>
> but then I'm seeing the following errors when trying to run nosetests
> directly from the Terminal
>
> /Users/alex/bin/jython2.5.0/bin/nosetests: line 3: __requires__:
> command not found
> /Users/alex/bin/jython2.5.0/bin/nosetests: line 4: import: command  
> not found
> from: can't read /var/mail/pkg_resources
(Continue reading)

Picon

Re: nose and jython

On Tue, Sep 1, 2009 at 2:51 AM, Philip Jenvey<pjenvey <at> underboss.org> wrote:
>
> On Aug 31, 2009, at 4:23 PM, Alexandru Popescu ☀ wrote:
>
>> Hi guys,
>>
>> I was wondering if anyone tried to run nose under jython? I must
>> confess that most probably I've done something wrong as it doesn't
>> really work for me.
>>
>> I have both Python 2.5.4 and Jython 2.5.0 installed on my Mac OS
>> 10.5.8. nose was initially installed using easy_install for Python
>> 2.5.4. Then I've just copied the
>> nosetests script to the jython bin directory and modified the first line
>> from:
>>
>>
>> #!/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
>>
>> to
>>
>> #!/Users/alex/bin/jython2.5.0/bin/jython
>>
>> but then I'm seeing the following errors when trying to run nosetests
>> directly from the Terminal
>>
>> /Users/alex/bin/jython2.5.0/bin/nosetests: line 3: __requires__:
>> command not found
>> /Users/alex/bin/jython2.5.0/bin/nosetests: line 4: import: command not
>> found
(Continue reading)

Picon

Re: nose and jython

Ok, found a thread where Frank answered this question already.
Following those steps got me started.
I'm reproducing them here just for further reference:

1. download easy_install.py
2. run jython easy_install.py

You are done. Running easy_install will install packages in
<JYTHON_HOME>/Lib/site-packages

./alex

2009/9/1 Alexandru Popescu ☀ <the.mindstorm.mailinglist <at> gmail.com>:
> On Tue, Sep 1, 2009 at 2:51 AM, Philip Jenvey<pjenvey <at> underboss.org> wrote:
>>
>> On Aug 31, 2009, at 4:23 PM, Alexandru Popescu ☀ wrote:
>>
>>> Hi guys,
>>>
>>> I was wondering if anyone tried to run nose under jython? I must
>>> confess that most probably I've done something wrong as it doesn't
>>> really work for me.
>>>
>>> I have both Python 2.5.4 and Jython 2.5.0 installed on my Mac OS
>>> 10.5.8. nose was initially installed using easy_install for Python
>>> 2.5.4. Then I've just copied the
>>> nosetests script to the jython bin directory and modified the first line
>>> from:
>>>
>>>
(Continue reading)

Picon

"AssertionError Only AF_INET sockets": Is this an normal error?

I am wondering if the following trace is a normal/expected one:

Traceback (most recent call last):
  File "/Users/alex/bin/jython2.5.0/Lib/site-packages/nose-0.11.1-py2.5.egg/nose/case.py",
line 183, in runTest
    self.test(*self.arg)
  File "/Users/alex/workspace/python/twit2news/dbserv2/test/python/functional_tests.py",
line 12, in test_post_new_user
    assert_request(request, 201)
  File "/Users/alex/workspace/python/twit2news/dbserv2/test/python/functional_tests.py",
line 17, in assert_request
    res = urllib2.urlopen(request)
  File "/Users/alex/workspace/python/twit2news/dbserv2/test/python/functional_tests.py",
line 17, in assert_request
    res = urllib2.urlopen(request)
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 381, in open
    response = self._open(req, data)
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 398, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 1107, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 1079, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 1079, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
  File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 866, in request
(Continue reading)

Picon

HTTPError for status code 201

Hi again,

It looks like urllib2 is raising a HTTPError for responses with status
201 (created) which seems pretty weird. I have tested the behavior
with both Jython and CPython and it looks like both are behaving the
same way, so I was wondering if you can point me to some documentation
related to this behavior.

many thanks in advance,

./alex

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
Marc Downie | 1 Sep 06:52

Re: "AssertionError Only AF_INET sockets": Is this an normal error?


I came across this very assertion this afternoon. I changed 'localhost' to '127.0.0.1' and got back to my code without thinking long enough to file a bug report. 

Perhaps that will work (as a workaround) in your case?

(I'm not sure when this happened, but it's recent; my "locahost" code in question certainly used to work — I'm on Mac OS X 10.6, 64 bit Java 6).

best,

Marc.

2009/8/31 Alexandru Popescu ☀ <the.mindstorm.mailinglist <at> gmail.com>
I am wondering if the following trace is a normal/expected one:

Traceback (most recent call last):
 File "/Users/alex/bin/jython2.5.0/Lib/site-packages/nose-0.11.1-py2.5.egg/nose/case.py",
line 183, in runTest
   self.test(*self.arg)
 File "/Users/alex/workspace/python/twit2news/dbserv2/test/python/functional_tests.py",
line 12, in test_post_new_user
   assert_request(request, 201)
 File "/Users/alex/workspace/python/twit2news/dbserv2/test/python/functional_tests.py",
line 17, in assert_request
   res = urllib2.urlopen(request)
 File "/Users/alex/workspace/python/twit2news/dbserv2/test/python/functional_tests.py",
line 17, in assert_request
   res = urllib2.urlopen(request)
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 124, in urlopen
   return _opener.open(url, data)
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 381, in open
   response = self._open(req, data)
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 398, in _open
   result = self._call_chain(self.handle_open, protocol, protocol +
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 360, in _call_chain
   result = func(*args)
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 1107, in http_open
   return self.do_open(httplib.HTTPConnection, req)
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 1079, in do_open
   h.request(req.get_method(), req.get_selector(), req.data, headers)
 File "/Users/alex/bin/jython2.5.0/Lib/urllib2.py", line 1079, in do_open
   h.request(req.get_method(), req.get_selector(), req.data, headers)
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 866, in request
   self._send_request(method, url, body, headers)
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 866, in request
   self._send_request(method, url, body, headers)
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 889, in _send_request
   self.endheaders()
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 860, in endheaders
   self._send_output()
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 732, in _send_output
   self.send(msg)
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 699, in send
   self.connect()
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 670, in connect
   self.sock = socket.socket(af, socktype, proto)
 File "/Users/alex/bin/jython2.5.0/Lib/httplib.py", line 670, in connect
   self.sock = socket.socket(af, socktype, proto)
 File "/Users/alex/bin/jython2.5.0/Lib/socket.py", line 1080, in __init__
   _sock = _realsocket(family, type, proto)
 File "/Users/alex/bin/jython2.5.0/Lib/socket.py", line 559, in _realsocket
   assert family == AF_INET, "Only AF_INET sockets are currently
supported on jython"
AssertionError: Only AF_INET sockets are currently supported on jython

Basically my code attempts to request an URI that to localhost:8080
but there is nothing listening to that port.

[code]
def test_post_new_user():
   data = {'json' : ''}
   request= HttpRequest('POST', BASE_URL + '/users/', data=data)
   assert_request(request, 201)

def assert_request(request, status_code):
   print "Request: %s" % request.get_full_url()
   try:
       res = urllib2.urlopen(request)
       res.read()
   except urllib2.HTTPError, httpErr:
       fail('HTTPError occured:' + httpErr)
   else:
     assertEqual(res.code, status_code)
[/code]

(n.b. HttpRequest is just small extension over the urllib2.Request
that allows all request methods).

many thanks again and sorry for bugging you,

./alex

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Alan Kennedy | 1 Sep 10:12
Favicon
Gravatar

Re: "AssertionError Only AF_INET sockets": Is this an normal error?

[Alexandru]
>> I am wondering if the following trace is a normal/expected one:

[..snip..]

>>    assert family == AF_INET, "Only AF_INET sockets are currently
>> supported on jython"
>> AssertionError: Only AF_INET sockets are currently supported on jython

[Marc]
> I came across this very assertion this afternoon. I changed 'localhost' to
> '127.0.0.1' and got back to my code without thinking long enough to file a
> bug report.
> Perhaps that will work (as a workaround) in your case?
> (I'm not sure when this happened, but it's recent; my "locahost" code in
> question certainly used to work — I'm on Mac OS X 10.6, 64 bit Java 6).

That assertion is in there to ensure that people don't pass AF_INET6
as a parameter when opening sockets, since AF_INET6 family sockets is
not currently supported.

Sockets are usually opened like this

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

If you attempt to open an IPV6 socket, with AF_INET6, then you'll get
the assertion error above.

The address you're using is possibly obtained from
socket.getaddrinfo(), using a call something like this

for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  af, socktype, proto, canonname, sa = res

Try examining the results that come back from getaddrinfo for your
host/port combination: I expect that you are being returned an
AF_INET6 address.

The way to retrieve only AF_INET results from getaddrinfo is to pass
AF_INET as the family parameter, e.g.

for res in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM):
  af, socktype, proto, canonname, sa = res

But I note that it is common in python library modules to simply hard
code the value of "0" as the family parameter, meaning that results
from all families are acceptable, i.e. AF_INET and AF_INET6. Therre
are examples of that in ftplib, httplib, poplib, smtplib, and
telnetlib; I'm not sure about urllib/urllib2, and don't have time to
investigate right now.

A simple workaround, as Marc discovered, is to use a raw IPV4 address
instead of the hostname, i.e. "127.0.0.1", which will ensure that you
only get AF_INET results back from getaddrinfo.

I'll look at this some more later.

Alan.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
Picon

Re: "AssertionError Only AF_INET sockets": Is this an normal error?

On Tue, Sep 1, 2009 at 11:12 AM, Alan Kennedy<jython-dev <at> xhaus.com> wrote:
> [Alexandru]
>>> I am wondering if the following trace is a normal/expected one:
>
> [..snip..]
>
>>>    assert family == AF_INET, "Only AF_INET sockets are currently
>>> supported on jython"
>>> AssertionError: Only AF_INET sockets are currently supported on jython
>
> [Marc]
>> I came across this very assertion this afternoon. I changed 'localhost' to
>> '127.0.0.1' and got back to my code without thinking long enough to file a
>> bug report.
>> Perhaps that will work (as a workaround) in your case?
>> (I'm not sure when this happened, but it's recent; my "locahost" code in
>> question certainly used to work — I'm on Mac OS X 10.6, 64 bit Java 6).
>
> That assertion is in there to ensure that people don't pass AF_INET6
> as a parameter when opening sockets, since AF_INET6 family sockets is
> not currently supported.
>
> Sockets are usually opened like this
>
> import socket
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> If you attempt to open an IPV6 socket, with AF_INET6, then you'll get
> the assertion error above.
>
> The address you're using is possibly obtained from
> socket.getaddrinfo(), using a call something like this
>
> for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
>  af, socktype, proto, canonname, sa = res
>
> Try examining the results that come back from getaddrinfo for your
> host/port combination: I expect that you are being returned an
> AF_INET6 address.
>
> The way to retrieve only AF_INET results from getaddrinfo is to pass
> AF_INET as the family parameter, e.g.
>
> for res in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM):
>  af, socktype, proto, canonname, sa = res
>
> But I note that it is common in python library modules to simply hard
> code the value of "0" as the family parameter, meaning that results
> from all families are acceptable, i.e. AF_INET and AF_INET6. Therre
> are examples of that in ftplib, httplib, poplib, smtplib, and
> telnetlib; I'm not sure about urllib/urllib2, and don't have time to
> investigate right now.
>
> A simple workaround, as Marc discovered, is to use a raw IPV4 address
> instead of the hostname, i.e. "127.0.0.1", which will ensure that you
> only get AF_INET results back from getaddrinfo.
>
> I'll look at this some more later.
>
> Alan.
>

Thanks a lot for the extensive explanation (I must confess that I'm
not sure I understand all the details).
Now, I don't actually need a workaround for it, but I wasn't wondering
if this is a limitation, bug, or something else.

./alex

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Picon

Re: HTTPError for status code 201

2009/9/1 Alexandru Popescu ☀ <the.mindstorm.mailinglist <at> gmail.com>:
> Hi again,
>
> It looks like urllib2 is raising a HTTPError for responses with status
> 201 (created) which seems pretty weird. I have tested the behavior
> with both Jython and CPython and it looks like both are behaving the
> same way, so I was wondering if you can point me to some documentation
> related to this behavior.
>
> many thanks in advance,
>
> ./alex
>

I have found the bug reports related to this issue on CPython and it
looks like it was fixed only in 2.6. As far as I read the workaround
is the replace the default urllib2.HTTPErrorProcessor with a correct
one:

[bug code]
        if code not in (200, 206):
            response = self.parent.error(
                'http', request, response, code, msg, hdrs)
[/bug code]

[fix]
if not (200 <= code < 300):
  response = self.parent.error(
       'http', request, response, code, msg, hdrs)
[/fix]

./alex

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

Gmane