Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: manually build a unittest/doctest object. Date: Tue, 08 Dec 2015 16:31:39 +0100 Organization: None Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: news.uni-berlin.de cOQIfQpLv/eE47pPqQiJWgwHXjR7nstAXJanHP34wAGw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.03; '"""': 0.05; 'none,': 0.05; 'doctest': 0.07; 'none)': 0.07; 'subject:build': 0.07; '""")': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '{},': 0.09; '2:06': 0.16; 'docstring': 0.16; 'examples:': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:unittest': 0.16; 'wrote:': 0.16; 'tests': 0.18; '>>>': 0.20; '2015': 0.20; 'am,': 0.23; 'dec': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:" 20': 0.26; 'subject:/': 0.30; 'skip:[ 10': 0.31; 'tue,': 0.34; 'skip:d 20': 0.34; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'test': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'skip:w 30': 0.64; 'world': 0.64; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd9c0c.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100168 Vincent Davis wrote: > On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__peter__@web.de> wrote: > >> >>> import doctest >> >>> example = doctest.Example( >> ... "print('hello world')\n", >> ... want="hello world\n") >> >>> test = doctest.DocTest([example], {}, None, None, None, None) >> >>> runner = doctest.DocTestRunner(verbose=True) >> >>> runner.run(test) >> Trying: >> print('hello world') >> Expecting: >> hello world >> ok >> TestResults(failed=0, attempted=1) >> > > ​and now how to do a multi line statement​. doctest doesn't do tests with multiple *statements.* A docstring like """ >>> x = 42 >>> print(x) 42 """ is broken into two examples: >> import doctest >>> p = doctest.DocTestParser() >>> doctest.Example.__repr__ = lambda self: "Example(source={0.source!r}, want={0.want!r})".format(self) >>> p.get_examples(""" ... >>> x = 42 ... >>> print(x) ... 42 ... """) [Example(source='x = 42\n', want=''), Example(source='print(x)\n', want='42\n')]