Re: [Tutor] Unit testing: Just the API or internal use only methods, too?

2019-07-16 Thread Mats Wichmann
On 7/16/19 4:41 PM, boB Stepp wrote: > Peter Otten, while responding to one of my questions in the past, > mentioned something in passing that apparently has been mulling around > in the back of my head. I don't recall his exact words, but he > essentially said that I should be testing the public

Re: [Tutor] Unit testing: Just the API or internal use only methods, too?

2019-07-16 Thread Alan Gauld via Tutor
On 16/07/2019 23:41, boB Stepp wrote: > essentially said that I should be testing the public interface to my > classes, but not the methods only used internally by the class and not > meant to be publicly accessible. I suspect he meant that you should publish the tests for the API but not neces

[Tutor] Unit testing: Just the API or internal use only methods, too?

2019-07-16 Thread boB Stepp
Peter Otten, while responding to one of my questions in the past, mentioned something in passing that apparently has been mulling around in the back of my head. I don't recall his exact words, but he essentially said that I should be testing the public interface to my classes, but not the methods

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 02:03:13PM +, James Chapman wrote: > On the note of what doesn't need a test... > The question of coverage always comes up when unit testing is > mentioned and I read an interesting blog article once about it. It > basically said: Assume you have 85% coverage on a progr

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Thanks Steven! You've raised a few valid points, mostly that the run_forever method should be broken up. I like the principle of a method doing just one thing and for whatever reason I didn't apply that thinking to this method as it's the master loop (even though it does nothing). So for starters

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 11:31:49AM +, James Chapman wrote: > Hello tutors > > I've constructed an example which shows a problem I'm having testing a real > world program and would like to run it past you. [...] > class Infinite_Loop_Tutor_Question(object): > def run_forever(self): >

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Hmm... Here is an example of how I'm currently trying to test it: test_tutor_question.py - # -*- coding: utf-8 -*- import unittest import mock from tutor_question import Infinite_Loop_Tutor_Question class Test_Infinite_Loop_Tutor_Question(unittest.TestCase): def

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread eryksun
On Fri, Jan 31, 2014 at 6:31 AM, James Chapman wrote: > try: > while self.attribute: > time.sleep(1) > except KeyboardInterrupt: > ... > > My unit test could then set the attribute. However I'd still have the > problem of how I get from the unit test line that fires up the method t

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread Steven D'Aprano
On Fri, Jan 31, 2014 at 01:10:03PM +0100, spir wrote: > I don't know whether one can interrupt while sleeping py> from time import sleep py> sleep(60*60*24*365) # 1 year Traceback (most recent call last): File "", line 1, in KeyboardInterrupt Yes you can. -- Steven ___

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread spir
On 01/31/2014 12:31 PM, James Chapman wrote: try: while self.attribute: time.sleep(1) except KeyboardInterrupt: Maybe I'm missing apoint or reasoning wrongly, but I'd rather do: while self.attribute: try: time.sleep(1) except KeyboardInterrupt: ... or something lik

[Tutor] Unit testing infinite loops

2014-01-31 Thread James Chapman
Hello tutors I've constructed an example which shows a problem I'm having testing a real world program and would like to run it past you. tutor_question.py -- # -*- coding: utf-8 -*- import sys import threading import time class Time_Printer(threading.Thread)

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-09 Thread Danny Yoo
By the way, there's a nice book by Kent Beck called "Test Driven Development by Example" that might be helpful to look at: http://en.wikipedia.org/wiki/Test-Driven_Development_by_Example ___ Tutor maillist - Tutor@python.org To unsubscribe or chang

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-09 Thread Amit Saha
On Sun, Dec 8, 2013 at 8:22 PM, Rafael Knuth wrote: > Hey there, > > I struggle to understand what unit testing specifically means in > practice and how to actually write unit tests for my code (my gut is > telling me that it's a fairly important concept to understand). > > Over the last few days

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread Alan Gauld
On 08/12/13 10:22, Rafael Knuth wrote: My understanding of unit testing is that I have to embed my code into a test and then I have to define conditions under which my code is supposed to fail and pass. Is that assumption correct? That's correct for any kind of unit testing, not just using the

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread Steven D'Aprano
On Sun, Dec 08, 2013 at 11:22:37AM +0100, Rafael Knuth wrote: > Hey there, > > I struggle to understand what unit testing specifically means in > practice and how to actually write unit tests for my code (my gut is > telling me that it's a fairly important concept to understand). In practice, uni

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread Mark Lawrence
On 08/12/2013 10:22, Rafael Knuth wrote: Hey there, I struggle to understand what unit testing specifically means in practice and how to actually write unit tests for my code (my gut is telling me that it's a fairly important concept to understand). Over the last few days I learned how to write

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread spir
On 12/08/2013 11:22 AM, Rafael Knuth wrote: Hey there, I struggle to understand what unit testing specifically means in practice and how to actually write unit tests for my code (my gut is telling me that it's a fairly important concept to understand). [...] Hello Rafael, This post is quite l

Re: [Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread Amit Saha
On Sun, Dec 8, 2013 at 8:22 PM, Rafael Knuth wrote: > Hey there, > > I struggle to understand what unit testing specifically means in > practice and how to actually write unit tests for my code (my gut is > telling me that it's a fairly important concept to understand). Your gut feeling is right.

[Tutor] Unit testing in Python (3.3.0) for beginners

2013-12-08 Thread Rafael Knuth
Hey there, I struggle to understand what unit testing specifically means in practice and how to actually write unit tests for my code (my gut is telling me that it's a fairly important concept to understand). Over the last few days I learned how to write and work with classes, I learned quite a l

Re: [Tutor] Unit testing individual modules

2013-11-20 Thread ALAN GAULD
;To: Alan Gauld >Sent: Wednesday, 20 November 2013, 17:44 >Subject: Re: [Tutor] Unit testing individual modules > > > >Thank you for your comments. >  >I am trying to import the program file named rball.py, then call/run one of >the modules  >within rball.py  [prin

Re: [Tutor] Unit testing individual modules

2013-11-19 Thread Alan Gauld
On 19/11/13 16:06, Patti Scott wrote: Python 2.4 self-study with Python Programming: An Introduction to Computer Science by Zelle I am trying to import a program that has a conditional execution statement at the end so I can troubleshoot individual modules in the main() program. I'm not quite s

[Tutor] Unit testing individual modules

2013-11-19 Thread Patti Scott
Python 2.4 self-study with Python Programming: An Introduction to Computer Science by Zelle   I am trying to import a program that has a conditional execution statement at the end so I can troubleshoot individual modules in the main() program.   Below is the textbook example program.  When I try t

Re: [Tutor] unit testing - Separate methods or group tests together?

2010-12-17 Thread Steven D'Aprano
Modulok wrote: List, When you create unit tests, do you group tests for a given function together into one unit test method, or do you prefer to have separate test methods for every assert statement? Each test method should test one thing. That doesn't necessarily mean one assert, but one con

[Tutor] unit testing - Separate methods or group tests together?

2010-12-17 Thread Modulok
List, When you create unit tests, do you group tests for a given function together into one unit test method, or do you prefer to have separate test methods for every assert statement? Thanks! -Modulok- ___ Tutor maillist - Tutor@python.org To unsubsc

Re: [Tutor] Unit testing command-line options from argparse or optparse

2010-05-19 Thread Serdar Tumgoren
Ah, okay -- both of those options make sense. I'll try my hand at Jan's first and will report back if I have any problems. Many thanks as always! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.or

Re: [Tutor] Unit testing command-line options from argparse or optparse

2010-05-19 Thread Dave Angel
Serdar Tumgoren wrote: Hello all, Does anyone have advice for writing unit tests against variables set by command-line options? I have a program I'd like to run in either "debug" or "live" mode, with various settings associated with each. Below is some pseudo-code that shows what I'd like to do

Re: [Tutor] Unit testing command-line options from argparse or optparse

2010-05-18 Thread Knacktus
Am 18.05.2010 22:49, schrieb Serdar Tumgoren: Hello all, Does anyone have advice for writing unit tests against variables set by command-line options? I have a program I'd like to run in either "debug" or "live" mode, with various settings associated with each. Below is some pseudo-code tha

[Tutor] Unit testing command-line options from argparse or optparse

2010-05-18 Thread Serdar Tumgoren
Hello all, Does anyone have advice for writing unit tests against variables set by command-line options? I have a program I'd like to run in either "debug" or "live" mode, with various settings associated with each. Below is some pseudo-code that shows what I'd like to do: <> mode = p.parse_args

Re: [Tutor] Unit-testing advice

2010-03-08 Thread C.T. Matsumoto
m...@doctors.net.uk wrote: Dear All, Quick UT question. I am working on a CSV processing script. I want to write some tests. The tests will need to read in, manipulate and write out some CSV files. My instinct is to manually construct some small data files, and consider them as part of the t

[Tutor] Unit-testing advice

2010-03-08 Thread mhw
Dear All, Quick UT question. I am working on a CSV processing script. I want to write some tests. The tests will need to read in, manipulate and write out some CSV files. My instinct is to manually construct some small data files, and consider them as part of the test suite. The other option

Re: [Tutor] Unit testing

2006-06-30 Thread Christopher Arndt
Terry Carroll schrieb: > You can just use a series of Queues, where each Queue represents the work > being passed from one thread to the other. If you want, you can have a look at my threadpool module, which implements exactly this pattern. It is basically nothing more than an elaborate example o

Re: [Tutor] Unit testing

2006-06-29 Thread Tino Dai
Okay, I was bored tonight, so I cooked up an illustration.Thanks for that! Here's an example with five stages.  Stage 1 takes a string and fills aninput queue with a series of letters from the string.  Stages 2-4 do just take a letter off its input queue and move it to its output queue.  Stage5 ta

Re: [Tutor] Unit testing

2006-06-29 Thread Terry Carroll
On Wed, 28 Jun 2006, Terry Carroll wrote: > On Wed, 28 Jun 2006, Tino Dai wrote: > > > Ok, I think I'm going to back up and explain what I'm am heading towards. > > I'm working on an app that fire off a bunch of threads. Each one of these > > threads in connected via queues to another thread in a

Re: [Tutor] Unit testing

2006-06-28 Thread Terry Carroll
On Wed, 28 Jun 2006, Tino Dai wrote: > Ok, I think I'm going to back up and explain what I'm am heading towards. > I'm working on an app that fire off a bunch of threads. Each one of these > threads in connected via queues to another thread in a sequence like a > chain. And how I tell the next sta

Re: [Tutor] Unit testing

2006-06-28 Thread Tino Dai
On 6/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Tino Dai wrote:> How I have it now:>> semaA = threading.semaphore()>> class nameA:>def __init__(self):> >>def run(self): >  >  semaA.release()>> class nameB:>def __init__(

Re: [Tutor] Unit testing

2006-06-28 Thread Tino Dai
Then where you create instances of those classes:sema = threading.semaphore() a = nameA(sema)b = nameB(sema)Maybe you don't even need the semaphore at all: have a look atQueue.Queue, it might do exactly what you need.Ok, I think I'm going to back up and explain what I'm am heading towards. I'm work

Re: [Tutor] Unit testing

2006-06-28 Thread Roel Schroeven
Tino Dai schreef: > How I have it now: > > semaA = threading.semaphore() > > class nameA: >def __init__(self): > > >def run(self): > > semaA.release() > > class nameB: >def __init__(self): > > >def run(self): > semaA.acqui

Re: [Tutor] Unit testing

2006-06-27 Thread Luke Paireepinart
[snip] > class nameB: >def __init__(self, sema): > self.sema = sema > > >def run(self): > self.semaA.acquire() > > I think here Kent meant self.sema.acquire() [snip] ___ Tutor maillist - Tutor@python.org

Re: [Tutor] Unit testing

2006-06-27 Thread Kent Johnson
Tino Dai wrote: > How I have it now: > > semaA = threading.semaphore() > > class nameA: >def __init__(self): > > >def run(self): > > semaA.release() > > class nameB: >def __init__(self): >

Re: [Tutor] Unit testing

2006-06-27 Thread Tino Dai
On 6/27/06, Tino Dai <[EMAIL PROTECTED]> wrote: On 6/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Tino Dai wrote:> And there is one caveat, I> will have to make a bunch of semaphores global instead of local to the> classes. While I know that there is no hard and fast rule about using> global var

Re: [Tutor] Unit testing

2006-06-27 Thread Tino Dai
On 6/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Tino Dai wrote:> And there is one caveat, I> will have to make a bunch of semaphores global instead of local to the> classes. While I know that there is no hard and fast rule about using> global variables, where can I find or can somebody tell me

Re: [Tutor] Unit testing

2006-06-27 Thread Kent Johnson
Tino Dai wrote: > And there is one caveat, I > will have to make a bunch of semaphores global instead of local to the > classes. While I know that there is no hard and fast rule about using > global variables, where can I find or can somebody tell me where I can > find some guidelines about the

Re: [Tutor] Unit testing

2006-06-27 Thread Tino Dai
On 6/27/06, Baiju M <[EMAIL PROTECTED]> wrote: On 6/26/06, Tino Dai <[EMAIL PROTECTED]> wrote:[...]> How would I unit test python GUIsFew weeks back I wrote a small article,may be helpful, so here it is : http://baijum81.livejournal.com/11598.htmlRegards,Baiju MBaiju, This is extremely useful f

Re: [Tutor] Unit testing

2006-06-27 Thread Tino Dai
On 6/27/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > Ok, that leads me to my next question.  Currently, I have a class> that I> want to unit test, but it contains a semaphore from another class.> Now, I> could make the semaphore a global variable, or I bring in the other > class.> One violates "good

Re: [Tutor] Unit testing

2006-06-26 Thread Baiju M
On 6/26/06, Tino Dai <[EMAIL PROTECTED]> wrote: [...] > How would I unit test python GUIs Few weeks back I wrote a small article, may be helpful, so here it is : http://baijum81.livejournal.com/11598.html Regards, Baiju M ___ Tutor maillist - Tutor@py

Re: [Tutor] Unit testing

2006-06-26 Thread Alan Gauld
> Ok, that leads me to my next question. Currently, I have a class > that I > want to unit test, but it contains a semaphore from another class. > Now, I > could make the semaphore a global variable, or I bring in the other > class. > One violates "good" programming principles and the other vio

Re: [Tutor] Unit testing

2006-06-26 Thread Carroll, Barry
Regards, Tino: I agree with Kent on this. As much as possible, a unit test should test what it is supposed to do. > Date: Mon, 26 Jun 2006 15:50:36 -0400 > From: "Tino Dai" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Unit testing > To: "Kent Johnson"

Re: [Tutor] Unit testing

2006-06-26 Thread Tino Dai
I often write unit tests that do this. In my opinion it is simple and straightforward and effective. Some purists will insist that a unit test shouldn't write the file system or touch a database or use any other external resource, but I think that is silly - if the job of a bit of code is to write

Re: [Tutor] Unit testing

2006-06-26 Thread Kent Johnson
Tino Dai wrote: > Hey Everybody, > > First off, I like to thank Kent, Alan, and Danny for their > invaluable help. You guys are amazing! You are welcome! >I do have some questions about unit testing. > >I have a part of the code that writes to the filesystem. Is the > o

Re: [Tutor] Unit testing

2006-06-26 Thread Jorge Godoy
"Tino Dai" <[EMAIL PROTECTED]> writes: > How do I simulate my queues and other sources of data. In Java, there > is a program called JMock that you can use to simulate that. Is there > anything like that in Python or do I roll my own and create the appropriate > queues with some data in the

[Tutor] Unit testing

2006-06-26 Thread Tino Dai
Hey Everybody,  First off, I like to thank Kent, Alan, and Danny for their invaluable help. You guys are amazing!   I do have some questions about unit testing. I have read through the diving into python section about unit testing as well as the documentation from the python docs. While tha

Re: [Tutor] unit testing raw_input()

2006-04-18 Thread Alan Gauld
> Suppose I had a function like the following: # def y_n(prompt="Answer yes or no"): while True: answer = raw_input(prompt) if answer in ['y', 'Y', 'yes']: print "You said yes!" break elif answer in ['n', 'N', 'no']: print

Re: [Tutor] unit testing raw_input()

2006-04-18 Thread Danny Yoo
On Tue, 18 Apr 2006, Andre Roberge wrote: > Suppose I had a function like the following: > > def y_n(prompt="Answer yes or no"): >while True: >answer = raw_input(prompt) >if answer in ['y', 'Y', 'yes']: >print "You said yes!" >break >elif answe

Re: [Tutor] unit testing raw_input()

2006-04-18 Thread Michael
On Tuesday 18 April 2006 23:34, Andre Roberge wrote: > Hi all- > > Suppose I had a function like the following: > > [ function that interacts with the outside world ] ... > How could I go about to write an automated test for it? You create a mock for raw_input, put the above code inside a module a

[Tutor] unit testing raw_input()

2006-04-18 Thread Andre Roberge
Hi all- Suppose I had a function like the following: def y_n(prompt="Answer yes or no"): while True: answer = raw_input(prompt) if answer in ['y', 'Y', 'yes']: print "You said yes!" break elif answer in ['n', 'N', 'no']: print "You s