very weird error when testing a file

5 views
Skip to first unread message

Pablo Angulo

unread,
Apr 8, 2011, 5:17:12 AM4/8/11
to sage-...@googlegroups.com
I've found a very weird error trying to get some files pass the
automated testing: I got the same "Expected" and "Got", but the test
failed. Copy the following text to devel/sage/sage/misc/example.py:

# -*- coding: utf-8 -*

def f(text):
"""

EXAMPLES::

sage: from sage.misc.example import f
sage: s="a=2"
sage: f(s)
'::\n\n sage: a=2'
"""
lines = ['::', '']
prefix=' sage: '
for s in text.splitlines():
lines.append(prefix + s)
return '\n'.join(lines)

And you get a weird error:

File
"/home/moriarty/Software/sage-4.6.1-linux-32bit-ubuntu_10.04_lts-i686-Linux/devel/sage-main/sage/misc/example.py",
line 10:
sage: f(s)
Expected:
'::\n\n sage: a=2'
Got:
'::\n\n sage: a=2'
**********************************************************************

but then make the following simple changes (change prefix from ' sage: '
to ' sag: '):

# -*- coding: utf-8 -*

def f(text):
"""

EXAMPLES::

sage: from sage.misc.example import f
sage: s="a=2"
sage: f(s)
'::\n\n sag: a=2'
"""
lines = ['::', '']
prefix=' sag: '
for s in text.splitlines():
lines.append(prefix + s)
return '\n'.join(lines)

and all tests pass!! They also seem to pass with any prefix that does
not contain the string 'sage:'.
I need to write some tests whose result contain 'sage:': can you help?

Regards

example.py

Nicolas M. Thiery

unread,
Apr 8, 2011, 5:31:01 AM4/8/11
to sage-...@googlegroups.com
Hi Pablo!

Ah, I see now: we got the same issue with #10652, where the doctest
framework was getting confused by this 'sage:'. As a workaround, you
could probably use something like:

sage: f(s) == '::\n\n sa'+'ge: a=2'
True

Cheers,
Nicolas
--
Nicolas M. Thi�ry "Isil" <nth...@users.sf.net>
http://Nicolas.Thiery.name/

Reply all
Reply to author
Forward
0 new messages