Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Vincent Davis Newsgroups: comp.lang.python Subject: Re: manually build a unittest/doctest object. Date: Tue, 8 Dec 2015 07:31:19 -0700 Lines: 52 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de Myv1j/Juvjtvv2pCJk/fAwjr3xSg9ZooCzn5tZlkOumg== 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; 'none,': 0.05; 'skip:" 60': 0.05; 'doctest': 0.07; 'none)': 0.07; 'subject:build': 0.07; 'cc:addr:python-list': 0.09; 'statements': 0.09; '{},': 0.09; 'example:': 0.10; 'received:209.85.218': 0.10; 'exception': 0.13; '>>>': 0.15; '1),': 0.16; '2:06': 0.16; 'received:209.85.218.51': 0.16; 'received:io': 0.16; 'received :mail-oi0-f51.google.com': 0.16; 'received:psf.io': 0.16; 'skip:d 60': 0.16; 'subject:unittest': 0.16; 'syntaxerror:': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; 'am,': 0.23; 'dec': 0.23; 'import': 0.24; '(most': 0.24; 'header:In- Reply-To:1': 0.24; 'example': 0.26; 'message-id:@mail.gmail.com': 0.27; '8bit%:3': 0.27; '8bit%:2': 0.29; 'skip:& 70': 0.29; 'subject:/': 0.30; 'statement': 0.32; 'traceback': 0.33; 'tue,': 0.34; 'file': 0.34; 'skip:d 20': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'received:209.85': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'received:209': 0.38; 'test': 0.39; 'skip:n 10': 0.62; 'world': 0.64; 'skip:\xc2 10': 0.67; 'skip:* 70': 0.70; 'otten': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vincentdavis.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=enEk6JpOyaPoZQ2iLvWw/2xcR6Ufo688kP0qS6Qu65c=; b=2uCUFhfjQF0/tx+wvw1yN94RE4SMyf2gCNYBU6vi962ycp6q4dMpe+AE9ROlOslvYm 5hSbKRfJMNtHBCnEbHEUs1zM2SA0k/iyodwguvmjaqCPmwOK7QaPYHWH1NUlGbSw7ybn /iyHfybuj8oOnq33fSzYQmplPo1WVvBc4UmUw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=enEk6JpOyaPoZQ2iLvWw/2xcR6Ufo688kP0qS6Qu65c=; b=P4wQT2BWapOsMkjTbOhoHOrQs/6W7cmIzBqLhbTbbgXwnhsL7AvEa0vV7YQ97N4Z+N T8CTHN+MuSed5nxoy6lX6D9yWn7AY4YgfpowGwfcEHlzrGBRoamXnsYcWzvOc1EuyTcC LdC4CUsbkKAT/DG3Z0v65HvNEvgAmOWKhxtK0VyeUo2CnCGjpu4ZHwoVE+nOSB2hbNnm ecHZLO0AvLH+caMtIRTraxq1dKrYopiJkyGjrMiqkkT2YbZkL6KRgXlY4W4WYeALkSIY prC7wXorkErh3+yTI/CV4b0Pj4Ns6mfrPSSUdY7E0jNZD1PSOtYJ2sFS4T0pbB3Ab9zv x4NQ== X-Gm-Message-State: ALoCoQnq2Tb2sOaILh3nu5bor6ScPAnzugE8qW4VYdACpQoc/InNINladaSXgFCbl2qUF2LQxnun1EmG5E1oky5T4OfJyFLomT1YSHXQvxkk8WsSb8MDECY= X-Received: by 10.202.208.68 with SMTP id h65mr2214854oig.111.1449585098806; Tue, 08 Dec 2015 06:31:38 -0800 (PST) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ 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:100160 On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__peter__@web.de> wrote: > >>> import doctest > >>> example =3D doctest.Example( > ... "print('hello world')\n", > ... want=3D"hello world\n") > >>> test =3D doctest.DocTest([example], {}, None, None, None, None) > >>> runner =3D doctest.DocTestRunner(verbose=3DTrue) > >>> runner.run(test) > Trying: > print('hello world') > Expecting: > hello world > ok > TestResults(failed=3D0, attempted=3D1) > =E2=80=8Band now how to do a multi line statement=E2=80=8B. >>> import doctest >>> example =3D doctest.Example("print('hello')\nprint('world')",want=3D"hello\nworld") >>> test =3D doctest.DocTest([example], {}, None, None, None, None) >>> runner =3D doctest.DocTestRunner(verbose=3DTrue) >>> runner.run(test) Trying: print('hello') print('world') Expecting: hello world ********************************************************************** Line 1, in None Failed example: print('hello') print('world') Exception raised: Traceback (most recent call last): File "/Users/vincentdavis/anaconda/envs/py35/lib/python3.5/doctest.py= ", line 1320, in __run compileflags, 1), test.globs) File "", line 1 print('hello') ^ SyntaxError: multiple statements found while compiling a single stateme= nt Vincent Davis