Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100140
| 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 10:06:32 +0100 |
| Organization | None |
| Lines | 32 |
| Message-ID | <mailman.53.1449565611.12405.python-list@python.org> (permalink) |
| References | <CALyJZZXeRaFxxdDK6aNSZC4xyqn082kZCGtgYBQxnBqKU-_WEg@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de n+690MKUKPXb0UsRcK3kRQ5lToWye3WLIdFGffFaZdUA== |
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'that?': 0.05; 'doctest': 0.07; 'none)': 0.07; 'subject:build': 0.07; 'unittest': 0.07; 'attempted': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '{},': 0.09; 'python': 0.10; 'intermediate': 0.15; '"hello': 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; 'string': 0.17; 'working.': 0.18; '>>>': 0.20; 'code,': 0.23; 'seems': 0.23; 'import': 0.24; 'header:User- Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'subject:/': 0.30; 'skip:d 20': 0.34; 'step': 0.36; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'why': 0.39; 'test': 0.39; 'build': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'world': 0.64 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd9067.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 <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100140 |
Show key headers only | View raw
Vincent Davis wrote:
> If I have a string that is python code, for example
> mycode = "print('hello world')"
> myresult = "hello world"
> How can a "manually" build a unittest (doctest) and test I get myresult
>
> I have attempted to build a doctest but that is not working.
> e = doctest.Example(source="print('hello world')/n", want="hello world\n")
> t = doctest.DocTestRunner()
> t.run(e)
There seems to be one intermediate step missing:
example --> doctest --> runner
>>> 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)
But why would you want to do that?
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: manually build a unittest/doctest object. Peter Otten <__peter__@web.de> - 2015-12-08 10:06 +0100
csiph-web