Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108788 > unrolled thread

Re: Resources/pointers for writing maintable, testable Python

Started byAndrew Farrell <armorsmith42@gmail.com>
First post2016-05-18 17:23 -0400
Last post2016-05-19 18:45 -0400
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Resources/pointers for writing maintable, testable Python Andrew Farrell <armorsmith42@gmail.com> - 2016-05-18 17:23 -0400
    Re: Resources/pointers for writing maintable, testable Python Mike Driscoll <kyosohma@gmail.com> - 2016-05-19 08:33 -0700
      Re: Resources/pointers for writing maintable, testable Python Jacob Scott <jacob.scott@gmail.com> - 2016-05-19 09:10 -0700
      Re: Resources/pointers for writing maintable, testable Python Terry Reedy <tjreedy@udel.edu> - 2016-05-19 12:23 -0400
        Re: Resources/pointers for writing maintable, testable Python Mike Driscoll <kyosohma@gmail.com> - 2016-05-19 13:10 -0700
          Re: Resources/pointers for writing maintable, testable Python Terry Reedy <tjreedy@udel.edu> - 2016-05-19 18:45 -0400

#108788 — Re: Resources/pointers for writing maintable, testable Python

FromAndrew Farrell <armorsmith42@gmail.com>
Date2016-05-18 17:23 -0400
SubjectRe: Resources/pointers for writing maintable, testable Python
Message-ID<mailman.22.1463608092.27390.python-list@python.org>
Hi Jacob,

You are probably looking for the book Test-Driven Development with Python
<http://chimera.labs.oreilly.com/books/1234000000754/index.html>.
You'll also want to look at py.test <http://pytest.org/latest/>

Cheers!
Andrew Farrell

On Wed, May 18, 2016 at 5:01 PM, Jacob Scott <jacob.scott@gmail.com> wrote:

> Many years ago, when I was primarily writing Java, I found Misko
> Hevery's Guide:
> Writing Testable Code
> <http://misko.hevery.com/attachments/Guide-Writing%20Testable%20Code.pdf>
> to
> be incredibly helpful in guiding the design and structure of my codebase,
> and as reference for checking if my code was smelly.
>
> Today, I'm happily writing primarily Python (unfortunately, 2.7 -- but I'm
> not sure it makes that much of a difference), but I haven't found anything
> that speaks to me in the same way. Some of the best resources I've found,
> but which don't quite cover all of what I'm looking for, include
>
>    - PEP-8 and PEP-20
>    - The Hitchhiker's Guide to Python
>    <http://docs.python-guide.org/en/latest/>
>    - Effective Python <http://www.effectivepython.com/>
>
> I'd appreciate any pointers to resources I might have missed, general
> thoughts on the topic, etc.
>
> Thanks,
>
> Jacob
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [next] | [standalone]


#108827

FromMike Driscoll <kyosohma@gmail.com>
Date2016-05-19 08:33 -0700
Message-ID<ffa86da4-f7f1-4a02-9fba-0bd6ca68e074@googlegroups.com>
In reply to#108788
On Wednesday, May 18, 2016 at 4:48:28 PM UTC-5, Andrew Farrell wrote:
> Hi Jacob,
> 
> You are probably looking for the book Test-Driven Development with Python
> <http://chimera.labs.oreilly.com/books/1234000000754/index.html>.
> You'll also want to look at py.test <http://pytest.org/latest/>
> 
> Cheers!
> Andrew Farrell

I was under the impression that this book is primarily aimed at Python/Django web testing. I saw "Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing" is getting good reviews too though. 

Mike

[toc] | [prev] | [next] | [standalone]


#108828

FromJacob Scott <jacob.scott@gmail.com>
Date2016-05-19 09:10 -0700
Message-ID<mailman.34.1463674225.27390.python-list@python.org>
In reply to#108827
Indeed, I skimmed the TOC for Test-Driven Development with Python and it
does look to be rather Django-centric (which makes it a bit less helpful to
me). I will take a look at "Testing Python: Applying Unit Testing, TDD, BDD
and Acceptance Testing"!

Thanks,

Jacob

On Thu, May 19, 2016 at 8:33 AM, Mike Driscoll <kyosohma@gmail.com> wrote:

> On Wednesday, May 18, 2016 at 4:48:28 PM UTC-5, Andrew Farrell wrote:
> > Hi Jacob,
> >
> > You are probably looking for the book Test-Driven Development with Python
> > <http://chimera.labs.oreilly.com/books/1234000000754/index.html>.
> > You'll also want to look at py.test <http://pytest.org/latest/>
> >
> > Cheers!
> > Andrew Farrell
>
> I was under the impression that this book is primarily aimed at
> Python/Django web testing. I saw "Testing Python: Applying Unit Testing,
> TDD, BDD and Acceptance Testing" is getting good reviews too though.
>
> Mike
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#108829

FromTerry Reedy <tjreedy@udel.edu>
Date2016-05-19 12:23 -0400
Message-ID<mailman.35.1463675017.27390.python-list@python.org>
In reply to#108827
On 5/19/2016 11:33 AM, Mike Driscoll wrote:
> On Wednesday, May 18, 2016 at 4:48:28 PM UTC-5, Andrew Farrell wrote:
>> Hi Jacob,
>>
>> You are probably looking for the book Test-Driven Development with Python
>> <http://chimera.labs.oreilly.com/books/1234000000754/index.html>.

Electronic version is free online.

> I was under the impression that this book is primarily aimed at Python/Django web testing. I saw

It is.  However, the first four chapters cover the general principles of 
TDD, so one can read them while thinking of web development as just an 
illustrative example.

In my case, I learned better how to test IDLE from a user perspective. 
For tkinter apps, an external program such as Selenium is not needed. 
Tk/tkinter have the simulated event generation and introspection needed 
to simulate a user hitting keys, clicking mouse buttons, and reading the 
screen.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#108840

FromMike Driscoll <kyosohma@gmail.com>
Date2016-05-19 13:10 -0700
Message-ID<909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com>
In reply to#108829
On Thursday, May 19, 2016 at 11:23:53 AM UTC-5, Terry Reedy wrote:
> On 5/19/2016 11:33 AM, Mike Driscoll wrote:
> > On Wednesday, May 18, 2016 at 4:48:28 PM UTC-5, Andrew Farrell wrote:
> >> Hi Jacob,
> >>
> >> You are probably looking for the book Test-Driven Development with Python
> >> <http://chimera.labs.oreilly.com/books/1234000000754/index.html>.
> 
> Electronic version is free online.
> 
> > I was under the impression that this book is primarily aimed at Python/Django web testing. I saw
> 
> It is.  However, the first four chapters cover the general principles of 
> TDD, so one can read them while thinking of web development as just an 
> illustrative example.
> 
> In my case, I learned better how to test IDLE from a user perspective. 
> For tkinter apps, an external program such as Selenium is not needed. 
> Tk/tkinter have the simulated event generation and introspection needed 
> to simulate a user hitting keys, clicking mouse buttons, and reading the 
> screen.
> 
> -- 
> Terry Jan Reedy

I am curious. Where is this documented? Are you referring to calling the invoke() method on each widget?

Mike

[toc] | [prev] | [next] | [standalone]


#108847

FromTerry Reedy <tjreedy@udel.edu>
Date2016-05-19 18:45 -0400
Message-ID<mailman.44.1463697947.27390.python-list@python.org>
In reply to#108840
On 5/19/2016 4:10 PM, Mike Driscoll wrote:
> On Thursday, May 19, 2016 at 11:23:53 AM UTC-5, Terry Reedy wrote:

>> In my case, I learned better how to test IDLE from a user perspective.
>> For tkinter apps, an external program such as Selenium is not needed.
>> Tk/tkinter have the simulated event generation and introspection needed
>> to simulate a user hitting keys, clicking mouse buttons, and reading the
>> screen.

> I am curious. Where is this documented? Are you referring to calling
 > the invoke() method on each widget?

For widget commands, yes.  (And thanks for reminding of the method.)

For events:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html
(An indispensible tkinter reference) says:
'''
w.event_generate(sequence, **kw)

     This method causes an event to trigger without any external 
stimulus. The handling of the event is the same as if it had been 
triggered by an external stimulus. The sequence argument describes the 
event to be triggered. You can set values for selected fields in the 
Event object by providing keyword=value arguments, where the keyword 
specifies the name of a field in the Event object.

     See Section 54, “Events” for a full discussion of events.
'''
This omits some essentials.  tcl.tk/man/tcl8.6/TkCmd/event.htm
has much more, including the need to put focus on Text and Entry.

 From Stackoverflow, I learned that .update() is needed *before* 
.event_generate.  The following works.

import tkinter as tk
root = tk.Tk()
def prt():
     print('Handler called')
button = tk.Button(root, text='Click', command=prt)
button.place(x=20, y=20)
def ev(e):
     print(e.x, e.y)
button.bind('<ButtonPress-1>', ev)
button.update()
button.event_generate('<ButtonPress-1>', x=0, y=0)
button.event_generate('<ButtonRelease-1>')
button.invoke()
entry=tk.Entry(root)
entry.place(x=20, y=50)
entry.focus_force()
entry.update()
entry.event_generate('<Key-a>')

The event is reported, the handler is called, and 'a' is inserted. 
(Inserting text could be done more easily, but some key events such as 
<Key-End> do have text equivalents.)

-- 
Terry Jan Reedy


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web