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] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-13 Thread Steven D'Aprano
On Mon, Oct 12, 2015 at 04:12:57PM +, Albert-Jan Roskam wrote: > Hi, > > > In Python 2 one can do silly apple-pear comparisons such as 0> "0".*) > "CPython implementation detail: Objects of different types except > numbers are ordered by their type names; objects of the same types > that d

Re: [Tutor] Guidance on using custom exceptions please

2015-10-13 Thread Cameron Simpson
On 13Oct2015 13:43, David Aldrich wrote: Thanks for all the answers to my question, they were all helpful. I have one more question, which regards style. Suppose my 'send' method is in its own module: TxControl, along with the custom exceptions: TxControl.py: class MessageTimeoutError(Excep

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] Guidance on using custom exceptions please

2015-10-13 Thread Wolfgang Maier
On 13.10.2015 15:43, David Aldrich wrote: > I have one more question, which regards style. Suppose my 'send' method is in its own module: TxControl, along with the custom exceptions: TxControl.py: class MessageTimeoutError(Exception): pass class UndefinedMessageTypeError(Exception): pass def

Re: [Tutor] Guidance on using custom exceptions please

2015-10-13 Thread Danny Yoo
> Then it seems that an importer of that module must include the module name > when referencing the exceptions: > > import TxControl > > try: > send(msg) > except (TxControl.MessageTimeoutError, TxControl.UndefinedMessageTypeError) > as err: > # Exception processing > > Including 'TxContr

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] Guidance on using custom exceptions please

2015-10-13 Thread David Aldrich
> If you don't want to let the original timeout error bubble up you can create > your own little hierarchy of exceptions: > > class ResponseError(Exception): > pass > > class TimeoutError(ResponseError): > pass > > class BadDataError(ResponseError): > pass > > Then the baseclass of

Re: [Tutor] Guidance on using custom exceptions please

2015-10-13 Thread Danny Yoo
On Mon, Oct 12, 2015 at 7:55 AM, David Aldrich wrote: > Hi > > Consider a 'send' method that sends a message to another system via a socket. > This method will wait for a response before returning. There are two > possible error conditions: > > 1) Timeout - i.e. no response received > > 2

Re: [Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-13 Thread Danny Yoo
> In Python 2 one can do silly apple-pear comparisons such as 0> "0".*) > "CPython implementation detail: Objects of different types except numbers are > ordered by their type names; objects of the same types that don’t support > proper comparison are ordered by their address.". In Python3 this

Re: [Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-13 Thread Martin A. Brown
Greetings Albert-Jan, I have a suggestion and a comment in this matter. Yes, a justified fear of making mistakes. That is, a mistake has already occurred and I don't want it to happen again. Suggestion: Choose a single in-memory representation of your data and make all of your input and ou

Re: [Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-13 Thread Albert-Jan Roskam
From: oscar.j.benja...@gmail.com Date: Mon, 12 Oct 2015 20:37:43 + Subject: Re: [Tutor] 0> "0" --> is there a "from __future__ import to make this raise a TypeError? To: sjeik_ap...@hotmail.com; tutor@python.org On Mon, 12 Oct 2015 17:15 Albert-Jan Roskam wrote: Hi, In Python 2 one can

Re: [Tutor] Guidance on using custom exceptions please

2015-10-13 Thread Peter Otten
David Aldrich wrote: > Consider a 'send' method that sends a message to another system via a > socket. This method will wait for a response before returning. There are > two possible error conditions: > > > 1) Timeout - i.e. no response received > > 2) Illegal response received > >