Skip to content

Commit

Permalink
Trac #26304: doctests in src/sage/repl/attach.py and src/sage/repl/lo…
Browse files Browse the repository at this point in the history
…ad.py fail when test.py is present in folder from where doctests are run

First reported at https://groups.google.com/d/msg/sage-
release/eL75kEvaCeA/T6_kmPNCCQAJ.

If an empty `test.py` is present in SAGE_ROOT then
{{{
sage -t --long src/sage/repl/attach.py
**********************************************************************
File "src/sage/repl/attach.py", line 171, in
sage.repl.attach.load_attach_path
Failed example:
    attach('test.py')
Expected:
    Traceback (most recent call last):
    ...
    IOError: did not find file 'test.py' to load or attach
Got:
    <BLANKLINE>
**********************************************************************
File "src/sage/repl/attach.py", line 176, in
sage.repl.attach.load_attach_path
Failed example:
    attach('test.py')
Expected:
    111
Got:
    <BLANKLINE>
**********************************************************************
File "src/sage/repl/attach.py", line 178, in
sage.repl.attach.load_attach_path
Failed example:
    attached_files() == [fullpath]
Expected:
    True
Got:
    False
**********************************************************************
File "src/sage/repl/attach.py", line 183, in
sage.repl.attach.load_attach_path
Failed example:
    load('test.py')
Expected:
    Traceback (most recent call last):
    ...
    IOError: did not find file 'test.py' to load or attach
Got:
    <BLANKLINE>
**********************************************************************
File "src/sage/repl/attach.py", line 436, in sage.repl.attach.detach
Failed example:
    attach('test.py')
Expected:
    111
Got:
    <BLANKLINE>
**********************************************************************
File "src/sage/repl/attach.py", line 438, in sage.repl.attach.detach
Failed example:
    attached_files() == [os.path.normpath(fullpath)]
Expected:
    True
Got:
    False
**********************************************************************
File "src/sage/repl/attach.py", line 443, in sage.repl.attach.detach
Failed example:
    attach('test.py')
Expected:
    111
Got:
    <BLANKLINE>
**********************************************************************
2 items had failures:
   3 of  25 in sage.repl.attach.detach
   4 of  20 in sage.repl.attach.load_attach_path
    [127 tests, 7 failures, 2.61 s]
----------------------------------------------------------------------
sage -t --long src/sage/repl/attach.py  # 7 doctests failed
}}}

and
{{{
sage -t --long src/sage/repl/load.py
**********************************************************************
File "src/sage/repl/load.py", line 180, in sage.repl.load.load
Failed example:
    attach(fname)
Expected:
    111
Got:
    <BLANKLINE>
**********************************************************************
1 item had failures:
   1 of  34 in sage.repl.load.load
    [42 tests, 1 failure, 1.90 s]
----------------------------------------------------------------------
sage -t --long src/sage/repl/load.py  # 1 doctest failed
}}}

URL: https://trac.sagemath.org/26304
Reported by: strogdon
Ticket author(s): Steven Trogdon
Reviewer(s): Erik Bray
  • Loading branch information
Release Manager authored and vbraun committed Jan 23, 2019
2 parents f35fa3d + 224ab7b commit f22d8d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/sage/repl/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def load_attach_path(path=None, replace=False):
sage: t_dir = tmp_dir()
sage: fullpath = os.path.join(t_dir, 'test.py')
sage: _ = open(fullpath, 'w').write("print(37 * 3)")
We put SAGE_TMP on the attach path for testing (otherwise this will
load ``test.py`` from the current working directory if that happens
to exist)::
sage: load_attach_path(SAGE_TMP, replace=True)
sage: attach('test.py')
Traceback (most recent call last):
...
Expand All @@ -180,6 +186,7 @@ def load_attach_path(path=None, replace=False):
sage: sage.repl.attach.reset(); reset_load_attach_path()
sage: load_attach_path() == ['.']
True
sage: load_attach_path(SAGE_TMP, replace=True)
sage: load('test.py')
Traceback (most recent call last):
...
Expand All @@ -205,7 +212,7 @@ def load_attach_path(path=None, replace=False):
if path is None:
return search_paths
else:
if isinstance(path, six.string_types):
if not isinstance(path, list):
path = [path]
if replace:
search_paths = path
Expand Down Expand Up @@ -432,7 +439,7 @@ def detach(filename):
sage: t_dir = tmp_dir()
sage: fullpath = os.path.join(t_dir, 'test.py')
sage: _ = open(fullpath, 'w').write("print(37 * 3)")
sage: load_attach_path(t_dir)
sage: load_attach_path(t_dir, replace=True)
sage: attach('test.py')
111
sage: attached_files() == [os.path.normpath(fullpath)]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/repl/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def load(filename, globals, attach=False):
sage: fullpath = os.path.join(t_dir, fname)
sage: with open(fullpath, 'w') as f:
....: _ = f.write("print(37 * 3)")
sage: load_attach_path(t_dir)
sage: load_attach_path(t_dir, replace=True)
sage: attach(fname)
111
sage: sage.repl.attach.reset(); reset_load_attach_path() # clean up
Expand Down

0 comments on commit f22d8d8

Please sign in to comment.