Re: manually build a unittest/doctest object.

2015-12-08 Thread Peter Otten
Vincent Davis wrote: > On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__pete...@web.de> wrote: > >> >>> import doctest >> >>> example = doctest.Example( >> ... "print('hello world')\n", >> ... want="hello world\n") >> >>> test = doctest.DocTest([example], {}, None, None, None, None) >> >>>

Re: manually build a unittest/doctest object.

2015-12-08 Thread Vincent Davis
On Tue, Dec 8, 2015 at 7:30 AM, Laura Creighton wrote: > >-- > >https://mail.python.org/mailman/listinfo/python-list > > Check out this: > https://pypi.python.org/pypi/pytest-ipynb > ​Thanks Laura, I think I read the descript as saying I could run untittests on source code from a jupyter noteboo

Re: manually build a unittest/doctest object.

2015-12-08 Thread Vincent Davis
On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__pete...@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(v

Re: manually build a unittest/doctest object.

2015-12-08 Thread Laura Creighton
In a message of Tue, 08 Dec 2015 07:04:39 -0700, Vincent Davis writes: >On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__pete...@web.de> wrote: > >> But why would you want to do that? > > >Thanks Peter, I want to do that because I want to test jupyter notebooks. >​The notebook is in JSON and I can ge

Re: manually build a unittest/doctest object.

2015-12-08 Thread Chris Angelico
On Wed, Dec 9, 2015 at 1:04 AM, Vincent Davis wrote: > I also tried something like: > assert exec("""print('hello word')""") == 'hello word' I'm pretty sure exec() always returns None. If you want this to work, you would need to capture sys.stdout into a string: import io import contextlib outpu

Re: manually build a unittest/doctest object.

2015-12-08 Thread Vincent Davis
On Tue, Dec 8, 2015 at 2:06 AM, Peter Otten <__pete...@web.de> wrote: > But why would you want to do that? Thanks Peter, I want to do that because I want to test jupyter notebooks. ​The notebook is in JSON and I can get the source and result out but it was unclear to me how to stick this into a

Re: manually build a unittest/doctest object.

2015-12-08 Thread Peter Otten
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(

Re: manually build a unittest/doctest object.

2015-12-07 Thread Steven D'Aprano
On Tuesday 08 December 2015 14:30, 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 Not easily. Effectively, you would have to re-invent

manually build a unittest/doctest object.

2015-12-07 Thread Vincent Davis
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", wan