Skip to content

Commit 1c19d43

Browse files
author
Matthias Koeppe
committed
src/sage/misc/replace_dot_all.py: Fix doctests
1 parent fe617e9 commit 1c19d43

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/sage/misc/replace_dot_all.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ def find_replacements(location, package_regex=None, verbose=False):
100100
EXAMPLES::
101101
102102
sage: from sage.misc.replace_dot_all import *
103-
sage: location = sage.env.SAGE_SRC + '/sage/structure/element.pyx'
104-
sage: find_replacements(location, verbose=True)
103+
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py')
104+
sage: find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True)
105+
[[..., ..., 'from sage.plot.graphics import Graphics']]
105106
"""
106107
if package_regex is None:
107108
package_regex = default_package_regex
@@ -259,7 +260,7 @@ def find_replacements(location, package_regex=None, verbose=False):
259260
return replacements
260261

261262

262-
def process_line(location, line, replacements, import_index, verbose=False):
263+
def process_line(location, line, replacements, row_index, verbose=False):
263264
r"""
264265
Modify a single source code ``line`` according to the given ``replacements``.
265266
@@ -268,7 +269,7 @@ def process_line(location, line, replacements, import_index, verbose=False):
268269
- ``location`` -- a file path; only used for logging
269270
- ``line`` -- a source code line
270271
- ``replacements`` -- the array output from :func:`find_replacements`
271-
- ``import_index`` -- the column number where ``import`` appears
272+
- ``row_index`` -- the line number where ``import`` appears
272273
- ``verbose`` -- if True, issue print statements when interesting examples are found
273274
274275
OUTPUT:
@@ -283,22 +284,27 @@ def process_line(location, line, replacements, import_index, verbose=False):
283284
Replacing the first line which needs a replacement in the file with filepath ``src/sage/structure/element.pyx``::
284285
285286
sage: from sage.misc.replace_dot_all import *
286-
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/structure/element.pyx')
287-
sage: replacements = find_replacements(location, verbose=True)
287+
sage: location = os.path.join(sage.env.SAGE_SRC, 'sage/plot/arc.py')
288+
sage: replacements = find_replacements(location, package_regex='sage[.]plot[.]all', verbose=True); replacements
289+
[[471, 24, 'from sage.plot.graphics import Graphics']]
288290
sage: with open(location, "r") as file:
289291
....: lines = file.readlines()
290-
sage: row_index, import_index, *_ = replacements[0]
291-
sage: line = lines[row_index]; line
292-
sage: new_line, replacements = process_line(location, line, replacements, import_index)
293-
sage: new_line
292+
sage: row_index, col_number, *_ = replacements[0]
293+
sage: line = lines[row_index]
294+
sage: print(line.rstrip())
295+
from sage.plot.all import Graphics
296+
sage: new_line, replacements = process_line(location, line, replacements, row_index)
297+
sage: print(new_line)
298+
from sage.plot.graphics import Graphics
294299
sage: replacements
300+
[]
295301
"""
296302
line = line.rstrip() # stripping line break
297303
new_line = ''
298304
global log_messages, interesting_examples
299305
if len(replacements) == 0:
300306
return line, replacements
301-
if import_index == replacements[0][0]: # if line marked as containing .all
307+
if row_index == replacements[0][0]: # if line marked as containing .all
302308
replacement = replacements.pop(0)
303309
leading_space = 0
304310
while line and line[leading_space] == ' ' and leading_space < len(line)-1:

0 commit comments

Comments
 (0)