Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'calls.': 0.07; 'subject:test': 0.07; '0),': 0.09; '[0,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '(ie,': 0.16; '-1))': 0.16; '1),': 0.16; 'iterator': 0.16; 'keyerror': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'repetition': 0.16; 'subject:strategy': 0.16; 'wrote:': 0.17; 'script.': 0.17; 'creates': 0.18; 'are.': 0.22; "i'd": 0.22; "i've": 0.23; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'accuracy': 0.27; 'thoughts': 0.27; 'developing': 0.28; 'header:X-Complaints-To:1': 0.28; 'rest': 0.28; "people's": 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'function': 0.30; 'point': 0.31; 'url:python': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'could': 0.32; 'avoiding': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'something': 0.35; 'received:org': 0.36; 'created': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'test': 0.36; 'subject:: ': 0.38; 'mark': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'first': 0.61; 'between': 0.63; 'more': 0.63; 'strategy': 0.64; 'introduce': 0.80 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: unit test strategy Date: Sun, 16 Sep 2012 13:28:17 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-184-155.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: X-Antivirus: avast! (VPS 120916-0, 16/09/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347798515 news.xs4all.nl 6961 [2001:888:2000:d::a6]:45571 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29305 On 15/09/2012 03:59, Aaron Brady wrote: > Hello, > > I've developing a test script. There's a lot of repetition. I want to introduce a strategy for approaching it, but I don't want the program to be discredited because of the test script. Therefore, I'd like to know what people's reactions to and thoughts about it are. > > The first strategy I used created an iterator and advanced it between each step: > self.op_chain(range(5), ('add', 5)) > self.op_chain(range(5), ('add', -2), ('add', -1)) > self.op_chain(range(5), ('discard', -1), ('add', 5)) > self.op_chain_ok(range(5), ('update', [0, 1])) > Etc. > > I'm considering something more complicated. 'iN' creates iterator N, 'nN' advances iterator N, an exception calls 'assertRaises', and the rest are function calls. > dsi= dict.__setitem__ > ddi= dict.__delitem__ > dsd= dict.setdefault > KE= KeyError > IE= IterationError > self.chain(range(10), 'i0', (dsi, 0, 1), 'n0', (dsi, 10, 1), (IE, 'n0')) > self.chain(range(10), 'i0', 'n0', (dsd, 0, 0), 'n0', (dsd, 10, 1), (IE, 'n0')) > self.chain(range(10), 'i0', (KE, ddi, 10), 'n0', (ddi, 9), (IE, 'n0')) > > Do you think the 2nd version is legible? Could it interfere with the accuracy of the test? > http://docs.python.org/library/unittest.html#organizing-test-code seems to be a good starting point for avoiding repetition and introducing a strategy. -- Cheers. Mark Lawrence.