Re: Testing interactive code using raw_input

2014-03-11 Thread Steven D'Aprano
On Mon, 10 Mar 2014 17:57:19 +0100, Peter Otten wrote: > Steven D'Aprano wrote: >> what are my options for *automatically* supplying input to raw_input? > > https://pypi.python.org/pypi/mock > > In Python 3 this is part of the standard library: Nice! Thanks to everyone who responded. --

Re: Testing interactive code using raw_input

2014-03-10 Thread Ben Finney
Steven D'Aprano writes: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? Are you testing the behaviour of the ‘input’ function? If not, then it is an external dependency; and, since you're not interested in testing its behaviour, you c

Re: Testing interactive code using raw_input

2014-03-10 Thread Ethan Furman
On 03/10/2014 08:59 AM, Steven D'Aprano wrote: With an automated test, I can provide the arguments, and check the result, but what are my options for *automatically* supplying input to raw_input? pexpect? -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: Testing interactive code using raw_input

2014-03-10 Thread Peter Otten
Steven D'Aprano wrote: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? > > A simple technique would be to factor out the interactive part, e.g. like > this: > > # Before > def spam(): > answer = raw_input(prompt) > return eggs(a

Re: Testing interactive code using raw_input

2014-03-10 Thread Oscar Benjamin
On 10 March 2014 15:59, Steven D'Aprano wrote: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? > > A simple technique would be to factor out the interactive part, e.g. like > this: > > # Before > def spam(): > answer = raw_input(promp

Testing interactive code using raw_input

2014-03-10 Thread Steven D'Aprano
Does anyone have any good hints for testing interactive code that uses raw_input, or input in Python 3? A simple technique would be to factor out the interactive part, e.g. like this: # Before def spam(): answer = raw_input(prompt) return eggs(answer) + cheese(answer) + toast(answer) #