Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unicode support to the doctesting framework #14153

Closed
jdemeyer opened this issue Feb 20, 2013 · 92 comments
Closed

Add Unicode support to the doctesting framework #14153

jdemeyer opened this issue Feb 20, 2013 · 92 comments

Comments

@jdemeyer
Copy link

Support

  1. Doctest (i.e. sage:) lines containing non-ASCII characters.
  2. Doctest results containing non-ASCII characters.
  3. Print statements in doctests outputting unicode.
  4. Source files with a PEP 0263 encoding declaration.

see also #18370

CC: @nexttime @embray @jdemeyer @hivert

Component: doctest framework

Keywords: unicode

Author: Frédéric Chapoton

Branch/Commit: ed1e3b5

Reviewer: Erik Bray, Volker Braun, David Roe

Issue created by migration from https://trac.sagemath.org/ticket/14153

@jdemeyer

This comment has been minimized.

@nexttime
Copy link
Mannequin

nexttime mannequin commented Mar 19, 2013

comment:2

Attachment: doctest_unicode.patch.gz

@kiwifb
Copy link
Member

kiwifb commented Mar 19, 2013

comment:3

I just tried this patch on the suspicion it could help with the test weirdness I reported in 5.9.beta0 on sage-release

sage -t --long devel/sage-main/sage/misc/interpreter.py
**********************************************************************
File "devel/sage-main/sage/misc/interpreter.py", line 150, in 
sage.misc.interpreter.sage_prompt
Failed example:
    shell.run_cell('sage_prompt()')
Expected:
    u'sage'
Got:
    u'sage'
**********************************************************************
File "devel/sage-main/sage/misc/interpreter.py", line 187, in 
sage.misc.interpreter.SageInteractiveShell.system_raw
Failed example:
    shell.system_raw('R --version')
Expected:
    R version ...
Got:
    WARNING: ignoring environment value of R_HOME
    R version 2.15.2 (2012-10-26) -- "Trick or Treat"
    Copyright (C) 2012 The R Foundation for Statistical Computing
    ISBN 3-900051-07-0
    Platform: x86_64-unknown-linux-gnu (64-bit)
    <BLANKLINE>
    R is free software and comes with ABSOLUTELY NO WARRANTY.
    You are welcome to redistribute it under the terms of the
    GNU General Public License versions 2 or 3.
    For more information about these matters see
    http://www.gnu.org/licenses/.
    <BLANKLINE>
**********************************************************************
File "devel/sage-main/sage/misc/interpreter.py", line 566, in 
sage.misc.interpreter.interface_shell_embed
Failed example:
    shell.run_cell('List( [1..10], IsPrime )')
Expected:
    [ false, true, true, false, true, false, true, false, false, false ]
Got:
    [ false, true, true, false, true, false, true, false, false, false ]
**********************************************************************
3 items had failures:
   1 of  15 in sage.misc.interpreter.SageInteractiveShell.system_raw
   1 of   4 in sage.misc.interpreter.interface_shell_embed
   1 of   4 in sage.misc.interpreter.sage_prompt
    [107 tests, 3 failures, 2.4 s]

The R error was fixed by unsetting R_HOME before running the test. Then I applied the patch and here is the result

sage -t --long devel/sage-main/sage/misc/interpreter.py
**********************************************************************
File "devel/sage-main/sage/misc/interpreter.py", line 150, in sage.misc.interpreter.sage_prompt
Failed example:
    shell.run_cell('sage_prompt()')
Expected:
    u'sage'
Got:
    u'sage'
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-1-e17c2c2153ac> in <module>()
    ----> 1 sage_prompt()
    
    /home/work/fbissey/sandbox/sage-5.9.beta0/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
        240             self.update_user_ns(result)
        241             self.log_output(format_dict)
    --> 242             self.finish_displayhook()
        243 
        244     def flush(self):
    <BLANKLINE>
    /home/work/fbissey/sandbox/sage-5.9.beta0/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in finish_displayhook(self)
        224         """Finish up all displayhook activities."""
        225         io.stdout.write(self.shell.separate_out2)
    --> 226         io.stdout.flush()
        227 
        228     def __call__(self, result=None):
    <BLANKLINE>
    AttributeError: IOStream instance has no attribute 'flush'
**********************************************************************
File "devel/sage-main/sage/misc/interpreter.py", line 566, in sage.misc.interpreter.interface_shell_embed
Failed example:
    shell.run_cell('List( [1..10], IsPrime )')
Expected:
    [ false, true, true, false, true, false, true, false, false, false ]
Got:
    [ false, true, true, false, true, false, true, false, false, false ]
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-1-a772973ec1ce> in <module>()
    ----> 1 sage.misc.all.logstr("""[ false, true, true, false, true, false, true, false, false, false ]""")
    
    /home/work/fbissey/sandbox/sage-5.9.beta0/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
        240             self.update_user_ns(result)
        241             self.log_output(format_dict)
    --> 242             self.finish_displayhook()
        243 
        244     def flush(self):
    <BLANKLINE>
    /home/work/fbissey/sandbox/sage-5.9.beta0/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in finish_displayhook(self)
        224         """Finish up all displayhook activities."""
        225         io.stdout.write(self.shell.separate_out2)
    --> 226         io.stdout.flush()
        227 
        228     def __call__(self, result=None):
    <BLANKLINE>
    AttributeError: IOStream instance has no attribute 'flush'
**********************************************************************
2 items had failures:
   1 of   4 in sage.misc.interpreter.interface_shell_embed
   1 of   4 in sage.misc.interpreter.sage_prompt
    [107 tests, 2 failures, 3.0 s]

@roed314 roed314 assigned roed314 and unassigned sagetrac-mvngu Mar 28, 2013
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@nexttime nexttime mannequin modified the milestones: sage-6.4, sage-7.4 Aug 12, 2016
@fchapoton
Copy link
Contributor

Branch: public/14153

@fchapoton
Copy link
Contributor

comment:11

just made a branch from the old patch, not tried to test it


New commits:

cffdb90trac 14153 unicode in documentation

@fchapoton
Copy link
Contributor

Commit: cffdb90

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 18, 2017

Changed commit from cffdb90 to 1712c87

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 18, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

abd83e5Merge branch 'public/14153' in 7.5.1
1712c87trac 14153 fixing doc default call

@fchapoton
Copy link
Contributor

comment:13

I have repaired a detail, but this is not working, in several distinct ways.

This seems to be broken on lines having unicode characters in comments such as:

sage: 0 + 0    # c'est trop bête

Some doctests come from the notebook, I made a pull request.

A failing doctest in src/sage/misc/rest_index_of_methods.py
is related to the presence of "Lov\xc3\xa1sz theta"

@fchapoton
Copy link
Contributor

comment:14

seems that something like that is hurting us (in forker):

sage: md=hashlib.md5()
sage: md.update(u'été')
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-9-6a9959b36b47> in <module>()
----> 1 md.update(u'été')

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)

solution: encode ?

sage: md.update(u'été'.encode('utf8'))

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 21, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

1c0dd43trac 14153 trying to fix the gap doc doctests

@fchapoton
Copy link
Contributor

comment:62

not sure at all that this is a good solution..

@embray
Copy link
Contributor

embray commented Jul 21, 2017

comment:63

Interesting. It's not clear to me where TermEncoding is used in the process of displaying some help docs. But if you were able to reproduce by setting that then it must be involved somewhere, somehow...

@fchapoton
Copy link
Contributor

comment:64

see the section 5.3-2 GAPDoc2Text in the link ​https://www.gap-system.org/Manuals/pkg/GAPDoc-1.5.1/doc/chap5.html

I think this explain what GAP does when its doc is required as a text.

@embray
Copy link
Contributor

embray commented Jul 21, 2017

comment:65

Great, that should explain it then.

Hmm--maybe rather than forcing TermEncoding to a specific value we should read TermEncoding and use that to determine how to decode text from GAP.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 21, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

0faa943trac 14153 detect gap encoding

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 21, 2017

Changed commit from 1c0dd43 to 0faa943

@fchapoton
Copy link
Contributor

comment:67

indeed, here is a try..

@fchapoton
Copy link
Contributor

comment:69

bot seems to be stable-green, please review

@fchapoton
Copy link
Contributor

comment:70

ping ? Jeroen ? Erik ?

@vbraun
Copy link
Member

vbraun commented Aug 5, 2017

comment:71

Can you replace the unconditional except: with something more sensible? Probably just name = str(name) instead of the entire try/except + assertion. Rest lgtm

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2017

Branch pushed to git repo; I updated commit sha1. New commits:

b6077c0Merge branch 'u/chapoton/14153v2' in 8.1.b1
ed1e3b5trac 14153 more precise except clause

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2017

Changed commit from 0faa943 to ed1e3b5

@fchapoton
Copy link
Contributor

comment:73

Thanks Volker for having a look.

I have made a more precise except. I guess one could also have removed the try-except.

@fchapoton
Copy link
Contributor

comment:74

bot is morally green

@roed314
Copy link
Contributor

roed314 commented Aug 6, 2017

Changed reviewer from Erik Bray to Erik Bray, Volker Bruan, David Roe

@roed314
Copy link
Contributor

roed314 commented Aug 6, 2017

comment:75

Looks good. Sorry that this review took so long!

@vbraun
Copy link
Member

vbraun commented Aug 9, 2017

Changed reviewer from Erik Bray, Volker Bruan, David Roe to Erik Bray, Volker Braun, David Roe

@roed314
Copy link
Contributor

roed314 commented Aug 11, 2017

comment:77

Sorry for the typo Volker!

@vbraun
Copy link
Member

vbraun commented Aug 11, 2017

Changed branch from u/chapoton/14153v2 to ed1e3b5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants