[Tutor] Testing a method in a class with nosetests (Alex Baker)

Alex Baker dime26 at yahoo.com
Mon Apr 22 03:09:08 CEST 2013


Dang, forgot to send in plain text! Sorry... 

Here is the GitHub link http://github.com/robotsmack/ex48


________________________________
 From: "tutor-request at python.org" <tutor-request at python.org>
To: tutor at python.org 
Sent: Sunday, April 21, 2013 6:51 PM
Subject: Tutor Digest, Vol 110, Issue 87
 

Send Tutor mailing list submissions to
    tutor at python.org

To subscribe or unsubscribe via the World Wide Web, visit
    http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
    tutor-request at python.org

You can reach the person managing the list at
    tutor-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

   1. Py 3 package maturity - good links (Jim Mooney)
   2. Re: Py 3 package maturity - good links (Dave Angel)
   3. Testing a method in a class with nosetests (Alex Baker)


----------------------------------------------------------------------

Message: 1
Date: Sun, 21 Apr 2013 09:24:06 -0700
From: Jim Mooney <cybervigilante at gmail.com>
To: tutor at python.org
Subject: [Tutor] Py 3 package maturity - good links
Message-ID:
    <CALRAYNX_1XmVJ85Lmcz4Y-748S6uDJtbHhuHBdy6TC-9uwTBvA at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

> On the other hand, from the perspective of "When will the *majority* of
> publicly-available libraries and packages support Python 3, then the answer
> is "Right now". The Python 3 Wall of Shame turned mostly green some time
> ago,
> and is now known as the Python 3 Wall of Superpowers:
>
> https://python3wos.appspot.com/
>
> Based on the number of downloads, almost three quarters of the Top 50
> Python
> packages support Python 3:
>
> http://py3ksupport.appspot.com/
>

Thanks. Very useful links to save that would have taken time for me to find
on my own.

As for "syllabus," probably a dream for a dynamic language ;')  I was
thinking of the time my brother, a Lit grad, gave me a syllabus of
literature to read - still working on it forty years later.

Jim
*
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130421/f1a36fa0/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 21 Apr 2013 16:05:42 -0400
From: Dave Angel <davea at davea.name>
To: tutor at python.org
Subject: Re: [Tutor] Py 3 package maturity - good links
Message-ID: <51744696.2090903 at davea.name>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 04/21/2013 12:24 PM, Jim Mooney wrote:
>> On the other hand, from the perspective of "When will the *majority* of
>> publicly-available libraries and packages support Python 3, then the answer
>> is "Right now". The Python 3 Wall of Shame turned mostly green some time
>> ago,
>> and is now known as the Python 3 Wall of Superpowers:
>>
>> https://python3wos.appspot.com/
>>
>> Based on the number of downloads, almost three quarters of the Top 50
>> Python
>> packages support Python 3:
>>
>> http://py3ksupport.appspot.com/
>>
>
> Thanks. Very useful links to save that would have taken time for me to find
> on my own.
>
> As for "syllabus," probably a dream for a dynamic language ;')  I was
> thinking of the time my brother, a Lit grad, gave me a syllabus of
> literature to read - still working on it forty years later.
>
>
>
http://pymotw.com/2/
     This could be one way to learn about new (to you) Python modules in 
a systematic way.

On the other hand, if you're looking for a syllabus of studying 
languages (plural), consider
    1) a dynamic language
    2) a compile one
    3) an assembler
    4) other    (lisp, Forth, ML, Prolog, ...)

Each category is enough different that you have to learn all new habits. 
  But knowing each one is valuable when using the other three types.




-- 
DaveA


------------------------------

Message: 3
Date: Sun, 21 Apr 2013 17:49:09 -0700 (PDT)
From: Alex Baker <dime26 at yahoo.com>
To: "tutor at python.org" <tutor at python.org>
Subject: [Tutor] Testing a method in a class with nosetests
Message-ID:
    <1366591749.43705.YahooMailNeo at web120205.mail.ne1.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"

Hello,
I've been lurking tutor for the last couple months and have quite enjoyed it!

I'm having a problem testing a method using nosetests. The assignment (Learn Python the Hard Way) asks that I write tests for a package using assert_equal and assert_raises. I've?conquered the assert_equals but I'm having issues with assert_raises. I can't figure out how am I supposed to test a method in a class with an __init__. I understand the assert_raises works assert_raises("ERROR", callable, parameters), and the parameters get sent to nosetests, but because of the __init__ I have no parameters to send.


# main module code
class ParserError(Exception):
? ? pass

class Parser(object):

? ? def __init__(self, word_list):
? ? ? ? self.word_list = word_list

? ? def parse_object(self):
? ? ? ? skip(self.word_list, 'stop')
? ? ? ? next = peek(self.word_list)

? ? ? ? if next == 'noun':
? ? ? ? ? ? return match(self.word_list, 'noun')
? ? ? ? if next == 'direction':
? ? ? ? ? ? return match(self.word_list, 'direction')
? ? ? ? else:
? ? ? ? ? ? raise ParserError("Expected a noun or direction next.")

# test code
from nose.tools import *
from ex48 import parser
from ex48 import lexicon

def _test_words(input): ? ?
? ? words = lexicon.scan(input)
? ? test = parser.Parser(words)
? ? return test

def test_parse_object(): ? ?
? ? assert_equal(_test_words("the bear").parse_object(),?
? ? ? ? ? ? ? ? ('noun', 'bear'))
? ? assert_equal(_test_words("the the ?princess").parse_object(),
? ? ? ? ? ? ? ? ('noun', 'princess'))
? ? assert_equal(_test_words("the nortH").parse_object(),?
? ? ? ? ? ? ? ? ('direction', 'north'))
? ? assert_raises("ParserError", _test_words("will fail"))

# nosetests output
ERROR: tests.parser_tests.test_parse_object
----------------------------------------------------------------------
Traceback (most recent call last):
? File "/Library/Python/2.7/site-packages/nose/case.py", line 197, in runTest
? ? self.test(*self.arg)
? File "/Users/robotsmack/hack/python_projects/ex48/tests/parser_tests.py", line 17, in test_parse_object
? ? assert_raises("ParserError", _test_words("will fail"))
? File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 456, in assertRaises
? File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 113, in __exit__
TypeError: issubclass() arg 2 must be a class or tuple of classes

Obviously a bunch a code was snipped, but I don't think its relevant to my question. But just in case, I'm currently fumbling my way through putting up the whole package on GitHub.

Thanks in advance!
_Alex


________________________________
From: "tutor-request at python.org" <tutor-request at python.org>
To: tutor at python.org 
Sent: Sunday, April 21, 2013 4:00 AM
Subject: Tutor Digest, Vol 110, Issue 86


Send Tutor mailing list submissions to
??? tutor at python.org

To subscribe or unsubscribe via the World Wide Web, visit
??? http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
??? tutor-request at python.org

You can reach the person managing the list at
??? tutor-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

?  1. Time frame for Py 3 Maturity (Jim Mooney)
?  2. Re: Time frame for Py 3 Maturity (Steven D'Aprano)
?  3. Re: 3to2? (Steven D'Aprano)
?  4. Re: Time frame for Py 3 Maturity (Alan Gauld)


----------------------------------------------------------------------

Message: 1
Date: Sat, 20 Apr 2013 19:10:23 -0700
From: Jim Mooney <cybervigilante at gmail.com>
To: tutor at python.org
Subject: [Tutor] Time frame for Py 3 Maturity
Message-ID:
??? <CALRAYNX0C9CSp9TYKB8vxH_VLo9jc1x7FLzgibjq4qQm4TNAuw at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

> This is why we tend to recommend 2.7 for anyone doing serious work in
> Python.
>

Understood. I am in no rush, but what do you think it the time frame when
Py 3 will be mature? A year from now? Two years? At some point I might want
to use it more practically. Or maybe there will be huge inflation, I'll go
broke, and have to use it more practically ;')

Also, is there a good syllabus for the best way to progress in this
language? One can certainly get sidetracked.

-- 
*Jim Mooney

Today is the day that would have been tomorrow if yesterday was today
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130420/e2023111/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 21 Apr 2013 14:02:36 +1000
From: Steven D'Aprano <steve at pearwood.info>
To: tutor at python.org
Subject: Re: [Tutor] Time frame for Py 3 Maturity
Message-ID: <517364DC.3080209 at pearwood.info>
Content-Type: text/plain; charset=UTF-8; format=flowed

On 21/04/13 12:10, Jim Mooney wrote:
>> This is why we tend to recommend 2.7 for anyone doing serious work in
>> Python.
>>
>
> Understood. I am in no rush, but what do you think it the time frame when
> Py 3 will be mature? A year from now? Two years? At some point I might want
> to use it more practically. Or maybe there will be huge inflation, I'll go
> broke, and have to use it more practically ;')

Define "mature".

As a language, Python 3 was fully mature by the time Python 3.1 came out.
(Python 3.0 was, alas, seriously broken, and slow, and is no longer supported.)
Since 3.1, Python has simply become *better*, with more features, better
text handling, the decimal module is now nearly as fast as built-in floats,
a few rough edges have been cleaned up. I expect 3.4 will be better still.

Likewise for the standard library. All of the standard library is fully
compliant with Python 3. Naturally.

As for the external ecosystem of Python libraries and applications, I think
the answer is, "it depends".

There are still people relying on Python 1.5 (!), so from the perspective of
"when will everyone migrate to the latest version?", the answer is "Never",
and even Python 2 is not fully mature.

On the other hand, from the perspective of "When will the *majority* of
publicly-available libraries and packages support Python 3, then the answer
is "Right now". The Python 3 Wall of Shame turned mostly green some time ago,
and is now known as the Python 3 Wall of Superpowers:

https://python3wos.appspot.com/

Based on the number of downloads, almost three quarters of the Top 50 Python
packages support Python 3:

http://py3ksupport.appspot.com/

On the third hand, if *you personally* require one of the packages which has
not been updated, then the answer for you will depend on the specific package
you care about.

When Python 3 was first floated as a backwards-incompatible version, it was
expected that the overall migration would take about ten years. We're now
half-way through that decade, and uptake is going according to plan, possibly
even a little faster than expected. The early adopters have been using 3 for
many years now, the majority of libraries and packages have been updated,
the Linux distros are starting to plan for the day when Python 3 is the default,
and the majority of trolls have given up complaining about Python 3.


> Also, is there a good syllabus for the best way to progress in this
> language? One can certainly get sidetracked.

I don't quite understand that question. Syllabus? As in a list of topics like
this?

"You must learn A, then B, then C, then D, ... and now you are an expert!"


No.




-- 
Steven


------------------------------

Message: 3
Date: Sun, 21 Apr 2013 15:32:44 +1000
From: Steven D'Aprano <steve at pearwood.info>
To: tutor at python.org
Subject: Re: [Tutor] 3to2?
Message-ID: <517379FC.3050905 at pearwood.info>
Content-Type: text/plain; charset=UTF-8; format=flowed

On 21/04/13 04:32, Jim Mooney wrote:
> I was looking at google pengine for python and it only supports 2.7. I've
> installed 3 and would rather not go back (I kept doing Print without the
> parentheses for awhile and it was really annoying ;')
>
> So the question comes up. If there is a 2to3 script, which I got working,
> is there a 3to2 script?. Or does that even makes sense since 3 has features
> 2 does not, although I read somewhere that many have been backported?


Is google broken in your part of the world? *wink*

https://duckduckgo.com/html/?q=python+3to2

https://www.google.com.au/search?q=python+3to2

http://au.search.yahoo.com/search?p=python+3to2

http://www.bing.com/search?q=python+3to2


Some features of Python 3 have already been back-ported, like the with
statement. Some can be optionally enabled, e.g.:

from __future__ import division, print_function

from future_builtins import *


In general, provided you only care about Python 2.7, you can write code
which behaves the same way in both 2 and 3. But as you go further back,
it becomes harder and harder. By the time you're trying to support 2.4
onwards, it becomes very annoying, and I'm speaking from experience.

Although I see that CherryPy actually manages to support everything from
2.3 onwards using a single code base, which truly astonishes me!



-- 
Steven


------------------------------

Message: 4
Date: Sun, 21 Apr 2013 08:46:34 +0100
From: Alan Gauld <alan.gauld at btinternet.com>
To: tutor at python.org
Subject: Re: [Tutor] Time frame for Py 3 Maturity
Message-ID: <kl05gm$58s$1 at ger.gmane.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 21/04/13 03:10, Jim Mooney wrote:

>>? ?  This is why we tend to recommend 2.7 for anyone doing serious work in
>>? ?  Python.
>
> Understood. I am in no rush, but what do you think it the time frame
> when Py 3 will be mature?

As Steven has already pointed out Python 3 itself is mature.
The problem is that many of the key 3rd party libraries have not
been ported yet or the ports are not stable. (Many others have
been so it depends what you need.)

But one of the problems in OpenSource is that the developments
are all done by volunteers. There is no central corporate
program of work to drive the porting process or set its priority
level. It just depends on what each project team sees as its
priority - adding features to the existing code, fixing bugs, or porting 
to Python3 (and thereafter maintaining 2 codebases...).

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



------------------------------

Subject: Digest Footer

_______________________________________________
Tutor maillist? -? Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


------------------------------

End of Tutor Digest, Vol 110, Issue 86
**************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130421/bf6f9009/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


------------------------------

End of Tutor Digest, Vol 110, Issue 87
**************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130421/11fe085d/attachment-0001.html>


More information about the Tutor mailing list