Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30678
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <oscar.j.benjamin@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'classes.': 0.07; 'unittest': 0.07; 'python': 0.09; 'defined,': 0.09; 'received :mail-vc0-f174.google.com': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'cls': 0.16; 'hierarchy': 0.16; 'subject:class': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.17; 'tests': 0.18; 'module': 0.19; 'regardless': 0.21; 'cc:2**0': 0.23; 'class.': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'run': 0.28; "d'aprano": 0.29; 'received:209.85.220.174': 0.29; 'steven': 0.29; 'class': 0.29; 'classes': 0.30; 'skip:s 30': 0.33; 'exhibit': 0.33; 'skip:d 20': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'received:209.85.220': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'but': 0.36; 'wanted': 0.36; 'test': 0.36; 'october': 0.37; 'skip:t 40': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'oscar': 0.84; 'yours': 0.88 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=afM833plyUA3uoyKUw9ppGgUnOXMExAdH4ZajUrmoFU=; b=rk3T2zbEH3ZoI6W9Ty1AUwcd6XLAUuVjkiqnAgk5d6bdhd3WfrEL5Q5wT1g/ha51qO wmAorgwbSywCCba5jvB9Kw2JwkLJSBv1a6DXNFRJvj3j3D1juOvq5dtMJKiF5hLz41Qj LqvPiVRGIvmX1sK7IXnjwPtgpGXwCOwNozsm/yarhzPhZ6ehRIPCz489IhxkOxSnBMzq 89KVTdcNgXnnXdnLAJbqsNI55KhX+Qcej7wkijynpvs8pmz1JGqzKDUurVC0jYboDfQy O/NiTVd4AzZRelEvKd7ckZxHMxRFLn/fkQ88wIx+sZrFI2TdAs8ACBw06j/HCM1uqGoH DSew== |
| MIME-Version | 1.0 |
| In-Reply-To | <506b92f3$0$29982$c3e8da3$5496439d@news.astraweb.com> |
| References | <v53rj9-5kd.ln1@satorlaser.homedns.org> <mailman.1725.1349186875.27098.python-list@python.org> <irirj9-sme.ln1@satorlaser.homedns.org> <mailman.1748.1349217065.27098.python-list@python.org> <506b92f3$0$29982$c3e8da3$5496439d@news.astraweb.com> |
| Date | Wed, 3 Oct 2012 10:33:55 +0100 |
| Subject | Re: unit testing class hierarchies |
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| To | "Steven D'Aprano" <steve+comp.lang.python@pearwood.info> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1758.1349256837.27098.python-list@python.org> (permalink) |
| Lines | 38 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1349256837 news.xs4all.nl 6923 [2001:888:2000:d::a6]:42173 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:30678 |
Show key headers only | View raw
On 3 October 2012 02:20, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > > But surely, regardless of where that functionality is defined, you still > need to test that both D1 and D2 exhibit the correct behaviour? Otherwise > D2 (say) may break that functionality and your tests won't notice. > > Given a class hierarchy like this: > > class AbstractBaseClass: > spam = "spam" > > class D1(AbstractBaseClass): pass > class D2(D1): pass > > > I write tests like this: > > class TestD1CommonBehaviour(unittest.TestCase): > cls = D1 > def testSpam(self): > self.assertTrue(self.cls.spam == "spam") > def testHam(self): > self.assertFalse(hasattr(self.cls, 'ham')) > > class TestD2CommonBehaviour(TestD1CommonBehaviour): > cls = D2 That's an excellent idea. I wanted a convenient way to run the same tests on two classes in order to test both a pure python and a cython-accelerator module implementation of the same class. I find it difficult to work out how to do such simple things with unittest because of its Java-like insistence on organising all tests into classes. I can't immediately remember what solution I came up with but yours is definitely better. Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
unit testing class hierarchies Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-02 14:27 +0200
Re: unit testing class hierarchies Demian Brecht <demianbrecht@gmail.com> - 2012-10-02 07:05 -0700
Re: unit testing class hierarchies Thomas Bach <thbach@students.uni-mainz.de> - 2012-10-02 16:06 +0200
Re: unit testing class hierarchies Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-02 17:24 +0200
Re: unit testing class hierarchies Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-02 18:54 +0200
Re: unit testing class hierarchies Peter Otten <__peter__@web.de> - 2012-10-02 19:38 +0200
Re: unit testing class hierarchies Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-02 19:41 +0100
Re: unit testing class hierarchies Ben Finney <ben+python@benfinney.id.au> - 2012-10-03 08:30 +1000
Re: unit testing class hierarchies Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-03 01:20 +0000
Re: unit testing class hierarchies Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-03 10:33 +0100
Re: unit testing class hierarchies Terry Reedy <tjreedy@udel.edu> - 2012-10-03 16:14 -0400
Re: unit testing class hierarchies Peter Otten <__peter__@web.de> - 2012-10-02 16:32 +0200
Re: unit testing class hierarchies Fayaz Yusuf Khan <fayaz@dexetra.com> - 2012-10-02 20:35 +0530
Re: unit testing class hierarchies Peter Otten <__peter__@web.de> - 2012-10-02 19:40 +0200
Re: unit testing class hierarchies Roy Smith <roy@panix.com> - 2012-10-02 19:46 -0400
csiph-web