Re: [Tutor] how to unittest cli input

2015-10-15 Thread Alex Kleider
On 2015-10-14 11:29, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p} return d.get ## This is an example of a 'closure' is it not? Y

Re: [Tutor] how to unittest cli input

2015-10-15 Thread Peter Otten
Alex Kleider wrote: > On 2015-10-14 12:27, Peter Otten wrote: >> Alex Kleider wrote: >> >>> On 2015-10-13 14:44, Alex Kleider wrote: On 2015-10-13 12:11, Danny Yoo wrote: > ## > def make_ask(f, l, p): > d = {'Enter your first name: ' : f, >

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Alex Kleider
On 2015-10-14 12:27, Peter Otten wrote: Alex Kleider wrote: On 2015-10-13 14:44, Alex Kleider wrote: On 2015-10-13 12:11, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile p

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Peter Otten
Alex Kleider wrote: > On 2015-10-13 14:44, Alex Kleider wrote: >> On 2015-10-13 12:11, Danny Yoo wrote: >> >> >>> ## >>> def make_ask(f, l, p): >>> d = {'Enter your first name: ' : f, >>>'Enter your last name: ' : l, >>>'Your mobile phone #: ' : p}

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Alex Kleider
On 2015-10-14 11:29, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p} return d.get ## This is an example of a 'closure' is it not? Y

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Danny Yoo
>>> ## >>> def make_ask(f, l, p): >>> d = {'Enter your first name: ' : f, >>>'Enter your last name: ' : l, >>>'Your mobile phone #: ' : p} >>> return d.get >>> ## > > > This is an example of a 'closure' is it not? Yes, though

Re: [Tutor] how to unittest cli input

2015-10-14 Thread Alex Kleider
On 2015-10-13 14:44, Alex Kleider wrote: On 2015-10-13 12:11, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p} return d.get ## This i

Re: [Tutor] how to unittest cli input

2015-10-13 Thread Danny Yoo
On Tue, Oct 13, 2015 at 2:44 PM, Alex Kleider wrote: > On 2015-10-13 12:11, Danny Yoo wrote: > > >> ## >> def make_ask(f, l, p): >> d = {'Enter your first name: ' : f, >>'Enter your last name: ' : l, >>'Your mobile phone #: ' : p} >> return d.get

Re: [Tutor] how to unittest cli input

2015-10-13 Thread Alex Kleider
On 2015-10-13 12:11, Danny Yoo wrote: ## def make_ask(f, l, p): d = {'Enter your first name: ' : f, 'Enter your last name: ' : l, 'Your mobile phone #: ' : p} return d.get ## This last line got my attention ("a dict has no

Re: [Tutor] how to unittest cli input

2015-10-13 Thread Danny Yoo
On Sat, Oct 10, 2015 at 5:41 PM, Alex Kleider wrote: > """ > I'm trying to follow a test driven development paradigm (using > unittest) but can't figure out how to test functions that collect > info from the command line such as the following. > """ > # collect.py > def collect_data(): > ret =

Re: [Tutor] how to unittest cli input

2015-10-12 Thread Steven D'Aprano
On Mon, Oct 12, 2015 at 10:37:51AM -0700, Alex Kleider wrote: > Any comments about when/if to use 'if src != None:' vs 'if src is not > None:'? > (or 'if src == None:' vs 'if src is None:') Short answer: always compare to None using `is` or `is not`. Long answer: If you want to check for src b

Re: [Tutor] how to unittest cli input

2015-10-12 Thread Ben Finney
Alex Kleider writes: > Any comments about when/if to use 'if src != None:' vs 'if src is not > None:'? Express your intention in the code. If you want to express “is this value the ‘None’ singleton?”, compare identity with ‘is’/‘is not’. (This is what you almost always mean when comparing to ‘N

Re: [Tutor] how to unittest cli input

2015-10-12 Thread Alex Kleider
On 2015-10-11 14:52, Cameron Simpson wrote: Minor remark: I would write "if src is not None:". In principle the empty string is also "falsey" like None, making your plain "if src:" slightly unreliable. Be precise! 'precise' is good! Any comments about when/if to use 'if src != None:' vs 'if s

Re: [Tutor] how to unittest cli input

2015-10-11 Thread Cameron Simpson
On 11Oct2015 09:29, Alex Kleider wrote: On 2015-10-10 18:10, Cameron Simpson wrote: However, you'r eusing input(), which unconditionally uses stdin and stdout. In that circumstance I'd consider this: [... temporarily replace stdin and stdout with test data ...] Yes indeed, and thank you f

Re: [Tutor] how to unittest cli input

2015-10-11 Thread Peter Otten
Alex Kleider wrote: > It'll take more studying on my part before I'll be able to implement > Ben's suggestion. I find Ben's example instructive, but when you're just starting you might prefer a simpler approach: import unittest from unittest import mock import collect class TestCollectData(u

Re: [Tutor] how to unittest cli input

2015-10-11 Thread Alex Kleider
On 2015-10-10 18:10, Cameron Simpson wrote: On 10Oct2015 17:41, Alex Kleider wrote: I'm tOn 2015-10-10 18:10, Cameron Simpson wrote: On 10Oct2015 17:41, Alex Kleider wrote: I'm trying to follow a test driven development paradigm (using unittest) but can't figu

Re: [Tutor] how to unittest cli input

2015-10-10 Thread Cameron Simpson
On 10Oct2015 17:41, Alex Kleider wrote: I'm trying to follow a test driven development paradigm (using unittest) but can't figure out how to test functions that collect info from the command line such as the following. Aside: I'd say "the standard input" , not "the command line"; to me the lat

Re: [Tutor] how to unittest cli input

2015-10-10 Thread Ben Finney
Alex Kleider writes: > """ > I'm trying to follow a test driven development paradigm (using > unittest) but can't figure out how to test functions that collect > info from the command line such as the following. > """ > # collect.py > def collect_data(): > ret = {} > ret['first'] = input(

[Tutor] how to unittest cli input

2015-10-10 Thread Alex Kleider
""" I'm trying to follow a test driven development paradigm (using unittest) but can't figure out how to test functions that collect info from the command line such as the following. """ # collect.py def collect_data(): ret = {} ret['first'] = input("Enter your first name: ") ret['last