gfcapalbo / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

twitter_test.py fails due to Python AttributeError for python 2.4 #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following issue seems to be related to python 2.4 but will be seen
again in python 2.7 and 3.0 per "For 2.6, the message attribute is being
deprecated in favor of the args attribute."
[http://docs.python.org/whatsnew/2.6.html and
http://www.python.org/dev/peps/pep-0352/#retracted-ideas]

What steps will reproduce the problem?
1. Checkout from the trunk
2. python setup.py build and install
3. python twitter_test.py

What is the expected output? What do you see instead?

Expected Output:

aarjav@yc$ python twitter_test.py
.....................................
----------------------------------------------------------------------
Ran 37 tests in 0.061s

OK

Error seen:

aarjav@yc:$ python twitter_test.py
................E....................
======================================================================
ERROR: Test that twitter responses containing an error message are wrapped.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "twitter_test.py", line 331, in testTwitterError
    self.assertEqual('test error', error.message)
AttributeError: TwitterError instance has no attribute 'message'

----------------------------------------------------------------------
Ran 37 tests in 0.060s

FAILED (errors=1)

What version of the product are you using? On what operating system?
Python 2.4.4

Please provide any additional information below.

Original issue reported on code.google.com by aar...@gmail.com on 26 Mar 2009 at 12:57

GoogleCodeExporter commented 9 years ago
The code version is r139

Original comment by aar...@gmail.com on 26 Mar 2009 at 12:59

GoogleCodeExporter commented 9 years ago
Suggested fix:

aarjav@yc:~/python-twitter$ svn diff twitter_test.py
Index: twitter_test.py
===================================================================
--- twitter_test.py (revision 139)
+++ twitter_test.py (working copy)
@@ -328,7 +328,8 @@
       statuses = self._api.GetPublicTimeline()
     except twitter.TwitterError, error:
       # If the error message matches, the test passes
-      self.assertEqual('test error', error.message)
+      print error.args
+      self.assertEqual('test error', error.args[0])
     else:
       self.fail('TwitterError expected')

Original comment by aar...@gmail.com on 26 Mar 2009 at 2:07

GoogleCodeExporter commented 9 years ago

Original comment by dclinton on 26 Mar 2009 at 2:55

GoogleCodeExporter commented 9 years ago
Thanks for the bug report.

Rather than fixing it by changing the test, I changed TwitterError to always 
expose
.message (i.e., self.args[0]).  Please take a look at r140 and see if this 
addresses
the issue you found.

I'm also very curious as to why this broke in your version of python2.4, but 
not others.

Original comment by dclinton on 26 Mar 2009 at 3:15

GoogleCodeExporter commented 9 years ago
It addresses the issue. Good question about my python version. Here's all the 
info I
can think of about it. Let me know if there's anything else I can find out..

aarjav@yc:~/python-twitter$ python -V
Python 2.4.4
aarjav@yc:~/ubiqom/python-twitter$ uname -a
Linux yc 2.6.18.8-linode16 #1 SMP Mon Jan 12 09:50:18 EST 2009 i686 GNU/Linux
aarjav@yc:~/python-twitter$ python twitter_test.py 
................E....................
======================================================================
ERROR: Test that twitter responses containing an error message are wrapped.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "twitter_test.py", line 331, in testTwitterError
    self.assertEqual('test error', error.message)
AttributeError: TwitterError instance has no attribute 'message'

----------------------------------------------------------------------
Ran 37 tests in 0.064s

FAILED (errors=1)
aarjav@yc:~/python-twitter$ python
Python 2.4.4 (#2, Oct 22 2008, 19:52:44) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
aarjav@yc:~/python-twitter$ svn update .
U    twitter.py
Updated to revision 140.
aarjav@yc:~/python-twitter$ python twitter_test.py 
.....................................
----------------------------------------------------------------------
Ran 37 tests in 0.062s

OK
aarjav@yc:~/python-twitter$ 

Original comment by aar...@gmail.com on 26 Mar 2009 at 3:39

GoogleCodeExporter commented 9 years ago
I'm glad it fixed your issue, though I'll admit to still not understanding what 
was
happening here.  Let's leave this as "Fixed" and keep an eye out to see if it 
impacts
anyone else.

Thanks again for the detailed report and followup.

Original comment by dclinton on 26 Mar 2009 at 3:44

GoogleCodeExporter commented 9 years ago
Two things in Python docs hint at why.

1) On the Exception doc page for multiple python version  (2.5.1 and 2.4.4), it 
says:

Warning: Messages to exceptions are not part of the Python API. Their contents 
may
change from one version of Python to the next without warning and should not be
relied on by code which will run under multiple versions of the interpreter. 

2) From 2.4.4 to 2.6.1, the following statement is added

The built-in exceptions listed below can be generated by the interpreter or 
built-in
functions. Except where mentioned, they have an “associated value” 
indicating the
detailed cause of the error. This may be a string or a tuple containing several 
items
of information (e.g., an error code and a string explaining the code). The 
associated
value is the second argument to the raise statement. If the exception class is
derived from the standard root class BaseException, the associated value is 
present
as the exception instance’s args attribute

http://www.python.org/doc/2.4.4/ref/exceptions.html vs
http://www.python.org/doc/2.6/library/exceptions.html

Original comment by aar...@gmail.com on 26 Mar 2009 at 3:58

GoogleCodeExporter commented 9 years ago
Finally (last comment I promise, but had to get to the bottom of this)

aarjav@yc:~/ubiqom/python-twitter$ python
Python 2.4.4 (#2, Oct 22 2008, 19:52:44) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dir(Exception)
['__doc__', '__getitem__', '__init__', '__module__', '__str__']
>>> 

ajju@mire:~$ python2.5
Python 2.5 (release25-maint, Jul 20 2008, 20:47:25) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> dir(Exception)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__getitem__', '__getslice__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__str__', 'args', 
'message']
>>> 

Original comment by aar...@gmail.com on 26 Mar 2009 at 4:01