cpython: 8452c23139c6 (original) (raw)

--- a/Lib/test/test_tools.py +++ b/Lib/test/test_tools.py @@ -9,10 +9,13 @@ import sys import importlib.machinery import unittest from unittest import mock +import shutil +import subprocess import sysconfig import tempfile +import textwrap from test import support -from test.script_helper import assert_python_ok +from test.script_helper import assert_python_ok, temp_dir if not sysconfig.is_python_build(): # XXX some installers do contain the tools, should we detect that @@ -36,6 +39,327 @@ class ReindentTests(unittest.TestCase): self.assertGreater(err, b'') +class PindentTests(unittest.TestCase):

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+ + class TestSundryScripts(unittest.TestCase): # At least make sure the rest don't have syntax errors. When tests are # added for a script it should be added to the whitelist below.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -621,6 +621,8 @@ Extension Modules Tests ----- +- Issue #15539: Added regression tests for Tools/scripts/pindent.py. +

--- a/Tools/scripts/pindent.py +++ b/Tools/scripts/pindent.py @@ -79,8 +79,9 @@

Defaults

STEPSIZE = 8 TABSIZE = 8 -EXPANDTABS = 0 +EXPANDTABS = False +import io import re import sys @@ -89,7 +90,8 @@ next['if'] = next['elif'] = 'elif', 'els next['while'] = next['for'] = 'else', 'end' next['try'] = 'except', 'finally' next['except'] = 'except', 'else', 'finally', 'end' -next['else'] = next['finally'] = next['def'] = next['class'] = 'end' +next['else'] = next['finally'] = next['with'] = [](#l3.19)

next['end'] = () start = 'if', 'while', 'for', 'try', 'with', 'def', 'class' @@ -105,11 +107,11 @@ class PythonIndenter: self.expandtabs = expandtabs self._write = fpo.write self.kwprog = re.compile(

@@ -125,7 +127,7 @@ class PythonIndenter: def readline(self): line = self.fpi.readline()

@@ -173,10 +172,9 @@ class PythonIndenter: kw2 = m.group('kw') if not stack: self.error('unexpected end')

@@ -208,23 +206,23 @@ class PythonIndenter: def delete(self): begin_counter = 0 end_counter = 0

@@ -234,17 +232,12 @@ class PythonIndenter: # end def delete def complete(self):

@@ -269,7 +262,9 @@ class PythonIndenter: thiskw = '' # end if # end if

@@ -278,11 +273,11 @@ class PythonIndenter: else: s = '# end %s\n' % firstkw # end if

@@ -297,18 +292,18 @@ class PythonIndenter: else: s = '# end %s\n' % firstkw # end if

@@ -326,7 +321,6 @@ class PythonIndenter: self.write(line) # end while # end def complete -

end class PythonIndenter

Simplified user interface

@@ -352,76 +346,34 @@ def reformat_filter(input = sys.stdin, o pi.reformat()

end def reformat_filter

-class StringReader:

-# end class StringReader - -class StringWriter:

-# end class StringWriter - def complete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):

end def complete_string

def delete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):

end def delete_string

def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):

end def reformat_string

def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):

@@ -429,14 +381,16 @@ def complete_file(filename, stepsize = S try: os.rename(filename, filename + '~') except OSError: pass # end try

end def complete_file

def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):

@@ -444,14 +398,16 @@ def delete_file(filename, stepsize = STE try: os.rename(filename, filename + '~') except OSError: pass # end try

end def delete_file

def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):

@@ -459,9 +415,9 @@ def reformat_file(filename, stepsize = S try: os.rename(filename, filename + '~') except OSError: pass # end try

end def reformat_file

@@ -474,7 +430,7 @@ usage: pindent (-c|-d|-r) [-s stepsize] -r : reformat a completed program (use #end directives) -s stepsize: indentation step (default %(STEPSIZE)d) -t tabsize : the worth in spaces of a tab (default %(TABSIZE)d) --e : expand TABs into spaces (defailt OFF) +-e : expand TABs into spaces (default OFF) [file] ... : files are changed in place, with backups in file~ If no files are specified or a single - is given, the program acts as a filter (reads stdin, writes stdout). @@ -517,7 +473,7 @@ def test(): elif o == '-t': tabsize = int(a) elif o == '-e':