annotate Lib/test/test_tools.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents c3f0a0c825f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
1 """Tests for scripts in the Tools directory.
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
2
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
3 This file contains regression tests for some of the scripts found in the
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
4 Tools directory of a Python checkout or tarball, such as reindent.py.
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
5 """
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
6
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
7 import os
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
8 import sys
76877
626d5c6fbd95 Issue #13959: Have
Brett Cannon <brett@python.org>
parents: 76828
diff changeset
9 import importlib.machinery
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
10 import unittest
76251
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
11 from unittest import mock
81405
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
12 import shutil
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
13 import subprocess
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
14 import sysconfig
76134
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
15 import tempfile
81405
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
16 import textwrap
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
17 from test import support
81405
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
18 from test.script_helper import assert_python_ok, temp_dir
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
19
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
20 if not sysconfig.is_python_build():
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
21 # XXX some installers do contain the tools, should we detect that
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
22 # and run the tests in that case too?
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
23 raise unittest.SkipTest('test irrelevant for an installed Python')
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
24
78955
5493299df0a0 backport from the trunk, to fix test_tools with srcdir != builddir
doko@ubuntu.com
parents: 76134
diff changeset
25 basepath = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
5493299df0a0 backport from the trunk, to fix test_tools with srcdir != builddir
doko@ubuntu.com
parents: 76134
diff changeset
26 'Tools')
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
27 scriptsdir = os.path.join(basepath, 'scripts')
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
28
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
29
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
30 class ReindentTests(unittest.TestCase):
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
31 script = os.path.join(scriptsdir, 'reindent.py')
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
32
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
33 def test_noargs(self):
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
34 assert_python_ok(self.script)
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
35
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
36 def test_help(self):
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
37 rc, out, err = assert_python_ok(self.script, '-h')
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
38 self.assertEqual(out, b'')
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
39 self.assertGreater(err, b'')
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
40
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
41
81405
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
42 class PindentTests(unittest.TestCase):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
43 script = os.path.join(scriptsdir, 'pindent.py')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
44
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
45 def assertFileEqual(self, fn1, fn2):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
46 with open(fn1) as f1, open(fn2) as f2:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
47 self.assertEqual(f1.readlines(), f2.readlines())
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
48
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
49 def pindent(self, source, *args):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
50 with subprocess.Popen(
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
51 (sys.executable, self.script) + args,
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
52 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
53 universal_newlines=True) as proc:
82000
4be538a058a8 Fix test_tools hangs on Windows. Patch by Jeremy Kloth.
Serhiy Storchaka <storchaka@gmail.com>
parents: 81424
diff changeset
54 out, err = proc.communicate(source)
81405
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
55 self.assertIsNone(err)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
56 return out
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
57
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
58 def lstriplines(self, data):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
59 return '\n'.join(line.lstrip() for line in data.splitlines()) + '\n'
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
60
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
61 def test_selftest(self):
81424
a9990104f728 Issue #15539: Fix a backup file creation in pindent.py on Windows.
Serhiy Storchaka <storchaka@gmail.com>
parents: 81405
diff changeset
62 self.maxDiff = None
81405
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
63 with temp_dir() as directory:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
64 data_path = os.path.join(directory, '_test.py')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
65 with open(self.script) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
66 closed = f.read()
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
67 with open(data_path, 'w') as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
68 f.write(closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
69
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
70 rc, out, err = assert_python_ok(self.script, '-d', data_path)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
71 self.assertEqual(out, b'')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
72 self.assertEqual(err, b'')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
73 backup = data_path + '~'
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
74 self.assertTrue(os.path.exists(backup))
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
75 with open(backup) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
76 self.assertEqual(f.read(), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
77 with open(data_path) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
78 clean = f.read()
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
79 compile(clean, '_test.py', 'exec')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
80 self.assertEqual(self.pindent(clean, '-c'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
81 self.assertEqual(self.pindent(closed, '-d'), clean)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
82
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
83 rc, out, err = assert_python_ok(self.script, '-c', data_path)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
84 self.assertEqual(out, b'')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
85 self.assertEqual(err, b'')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
86 with open(backup) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
87 self.assertEqual(f.read(), clean)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
88 with open(data_path) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
89 self.assertEqual(f.read(), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
90
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
91 broken = self.lstriplines(closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
92 with open(data_path, 'w') as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
93 f.write(broken)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
94 rc, out, err = assert_python_ok(self.script, '-r', data_path)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
95 self.assertEqual(out, b'')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
96 self.assertEqual(err, b'')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
97 with open(backup) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
98 self.assertEqual(f.read(), broken)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
99 with open(data_path) as f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
100 indented = f.read()
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
101 compile(indented, '_test.py', 'exec')
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
102 self.assertEqual(self.pindent(broken, '-r'), indented)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
103
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
104 def pindent_test(self, clean, closed):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
105 self.assertEqual(self.pindent(clean, '-c'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
106 self.assertEqual(self.pindent(closed, '-d'), clean)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
107 broken = self.lstriplines(closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
108 self.assertEqual(self.pindent(broken, '-r', '-e', '-s', '4'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
109
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
110 def test_statements(self):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
111 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
112 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
113 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
114
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
115 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
116 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
117 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
118 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
119
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
120 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
121 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
122 elif:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
123 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
124 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
125 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
126
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
127 while a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
128 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
129
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
130 while a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
131 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
132 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
133 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
134
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
135 for i in a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
136 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
137
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
138 for i in a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
139 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
140 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
141 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
142
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
143 try:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
144 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
145 finally:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
146 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
147
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
148 try:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
149 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
150 except TypeError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
151 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
152 except ValueError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
153 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
154 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
155 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
156
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
157 try:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
158 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
159 except TypeError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
160 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
161 except ValueError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
162 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
163 finally:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
164 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
165
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
166 with a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
167 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
168
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
169 class A:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
170 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
171
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
172 def f():
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
173 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
174 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
175
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
176 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
177 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
178 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
179 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
180
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
181 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
182 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
183 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
184 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
185 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
186
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
187 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
188 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
189 elif:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
190 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
191 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
192 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
193 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
194
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
195 while a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
196 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
197 # end while
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
198
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
199 while a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
200 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
201 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
202 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
203 # end while
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
204
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
205 for i in a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
206 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
207 # end for
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
208
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
209 for i in a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
210 break
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
211 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
212 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
213 # end for
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
214
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
215 try:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
216 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
217 finally:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
218 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
219 # end try
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
220
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
221 try:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
222 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
223 except TypeError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
224 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
225 except ValueError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
226 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
227 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
228 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
229 # end try
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
230
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
231 try:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
232 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
233 except TypeError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
234 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
235 except ValueError:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
236 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
237 finally:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
238 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
239 # end try
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
240
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
241 with a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
242 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
243 # end with
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
244
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
245 class A:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
246 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
247 # end class A
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
248
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
249 def f():
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
250 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
251 # end def f
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
252 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
253 self.pindent_test(clean, closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
254
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
255 def test_multilevel(self):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
256 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
257 def foobar(a, b):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
258 if a == b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
259 a = a+1
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
260 elif a < b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
261 b = b-1
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
262 if b > a: a = a-1
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
263 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
264 print 'oops!'
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
265 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
266 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
267 def foobar(a, b):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
268 if a == b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
269 a = a+1
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
270 elif a < b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
271 b = b-1
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
272 if b > a: a = a-1
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
273 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
274 else:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
275 print 'oops!'
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
276 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
277 # end def foobar
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
278 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
279 self.pindent_test(clean, closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
280
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
281 def test_preserve_indents(self):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
282 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
283 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
284 if b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
285 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
286 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
287 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
288 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
289 if b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
290 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
291 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
292 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
293 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
294 self.assertEqual(self.pindent(clean, '-c'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
295 self.assertEqual(self.pindent(closed, '-d'), clean)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
296 broken = self.lstriplines(closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
297 self.assertEqual(self.pindent(broken, '-r', '-e', '-s', '9'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
298 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
299 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
300 \tif b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
301 \t\tpass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
302 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
303 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
304 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
305 \tif b:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
306 \t\tpass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
307 \t# end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
308 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
309 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
310 self.assertEqual(self.pindent(clean, '-c'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
311 self.assertEqual(self.pindent(closed, '-d'), clean)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
312 broken = self.lstriplines(closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
313 self.assertEqual(self.pindent(broken, '-r'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
314
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
315 def test_escaped_newline(self):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
316 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
317 class\\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
318 \\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
319 A:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
320 def\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
321 \\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
322 f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
323 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
324 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
325 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
326 class\\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
327 \\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
328 A:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
329 def\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
330 \\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
331 f:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
332 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
333 # end def f
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
334 # end class A
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
335 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
336 self.assertEqual(self.pindent(clean, '-c'), closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
337 self.assertEqual(self.pindent(closed, '-d'), clean)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
338
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
339 def test_empty_line(self):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
340 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
341 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
342
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
343 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
344 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
345 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
346 if a:
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
347
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
348 pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
349 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
350 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
351 self.pindent_test(clean, closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
352
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
353 def test_oneline(self):
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
354 clean = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
355 if a: pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
356 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
357 closed = textwrap.dedent("""\
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
358 if a: pass
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
359 # end if
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
360 """)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
361 self.pindent_test(clean, closed)
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
362
9df6b707aef9 Issue #15539: Fix a number of bugs in Tools/scripts/pindent.py.
Serhiy Storchaka <storchaka@gmail.com>
parents: 78955
diff changeset
363
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
364 class TestSundryScripts(unittest.TestCase):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
365 # At least make sure the rest don't have syntax errors. When tests are
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
366 # added for a script it should be added to the whitelist below.
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
367
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
368 # scripts that have independent tests.
76251
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
369 whitelist = ['reindent.py', 'pdeps.py', 'gprof2html']
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
370 # scripts that can't be imported without running
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
371 blacklist = ['make_ctype.py']
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
372 # scripts that use windows-only modules
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
373 windows_only = ['win_add2path.py']
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
374 # blacklisted for other reasons
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
375 other = ['analyze_dxp.py']
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
376
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
377 skiplist = blacklist + whitelist + windows_only + other
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
378
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
379 def setUp(self):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
380 cm = support.DirsOnSysPath(scriptsdir)
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
381 cm.__enter__()
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
382 self.addCleanup(cm.__exit__)
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
383
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
384 def test_sundry(self):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
385 for fn in os.listdir(scriptsdir):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
386 if fn.endswith('.py') and fn not in self.skiplist:
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
387 __import__(fn[:-3])
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
388
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
389 @unittest.skipIf(sys.platform != "win32", "Windows-only test")
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
390 def test_sundry_windows(self):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
391 for fn in self.windows_only:
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
392 __import__(fn[:-3])
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
393
76108
058f9a9f97cd test_tools fix: don't import analyze_dxp if no _thread module
R David Murray <rdmurray@bitdance.com>
parents: 76106
diff changeset
394 @unittest.skipIf(not support.threading, "test requires _thread module")
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
395 def test_analyze_dxp_import(self):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
396 if hasattr(sys, 'getdxp'):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
397 import analyze_dxp
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
398 else:
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
399 with self.assertRaises(RuntimeError):
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
400 import analyze_dxp
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
401
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
402
76134
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
403 class PdepsTests(unittest.TestCase):
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
404
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
405 @classmethod
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
406 def setUpClass(self):
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
407 path = os.path.join(scriptsdir, 'pdeps.py')
76877
626d5c6fbd95 Issue #13959: Have
Brett Cannon <brett@python.org>
parents: 76828
diff changeset
408 loader = importlib.machinery.SourceFileLoader('pdeps', path)
626d5c6fbd95 Issue #13959: Have
Brett Cannon <brett@python.org>
parents: 76828
diff changeset
409 self.pdeps = loader.load_module()
76134
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
410
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
411 @classmethod
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
412 def tearDownClass(self):
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
413 if 'pdeps' in sys.modules:
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
414 del sys.modules['pdeps']
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
415
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
416 def test_process_errors(self):
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
417 # Issue #14492: m_import.match(line) can be None.
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
418 with tempfile.TemporaryDirectory() as tmpdir:
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
419 fn = os.path.join(tmpdir, 'foo')
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
420 with open(fn, 'w') as stream:
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
421 stream.write("#!/this/will/fail")
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
422 self.pdeps.process(fn, {})
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
423
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
424 def test_inverse_attribute_error(self):
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
425 # Issue #14492: this used to fail with an AttributeError.
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
426 self.pdeps.inverse({'a': []})
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
427
e9b8115c5b25 #14492: fix some bugs in Tools/scripts/pdeps.py.
R David Murray <rdmurray@bitdance.com>
parents: 76108
diff changeset
428
76251
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
429 class Gprof2htmlTests(unittest.TestCase):
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
430
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
431 def setUp(self):
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
432 path = os.path.join(scriptsdir, 'gprof2html.py')
76877
626d5c6fbd95 Issue #13959: Have
Brett Cannon <brett@python.org>
parents: 76828
diff changeset
433 loader = importlib.machinery.SourceFileLoader('gprof2html', path)
626d5c6fbd95 Issue #13959: Have
Brett Cannon <brett@python.org>
parents: 76828
diff changeset
434 self.gprof = loader.load_module()
76251
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
435 oldargv = sys.argv
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
436 def fixup():
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
437 sys.argv = oldargv
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
438 self.addCleanup(fixup)
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
439 sys.argv = []
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
440
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
441 def test_gprof(self):
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
442 # Issue #14508: this used to fail with an NameError.
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
443 with mock.patch.object(self.gprof, 'webbrowser') as wmock, \
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
444 tempfile.TemporaryDirectory() as tmpdir:
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
445 fn = os.path.join(tmpdir, 'abc')
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
446 open(fn, 'w').close()
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
447 sys.argv = ['gprof2html', fn]
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
448 self.gprof.main()
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
449 self.assertTrue(wmock.open.called)
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
450
73fba223c0a5 #14508: make gprof2html script runnable under python3
R David Murray <rdmurray@bitdance.com>
parents: 76134
diff changeset
451
76814
f9344a3eaaa6 Issue #14695: Run Tools/parser/test_unparse.py as part of test_tools.
Mark Dickinson <mdickinson@enthought.com>
parents: 76251
diff changeset
452 # Run the tests in Tools/parser/test_unparse.py
f9344a3eaaa6 Issue #14695: Run Tools/parser/test_unparse.py as part of test_tools.
Mark Dickinson <mdickinson@enthought.com>
parents: 76251
diff changeset
453 with support.DirsOnSysPath(os.path.join(basepath, 'parser')):
76828
dbfacec7e368 Issue #14742: Don't include DirectoryTestCase from test_unparse in test_tools until we can speed it up.
Mark Dickinson <mdickinson@enthought.com>
parents: 76814
diff changeset
454 from test_unparse import UnparseTestCase
77614
0e5a698d3c4c Issue #14742: test_unparse now only checks a limited number of files unless the 'cpu' resource is specified.
Mark Dickinson <mdickinson@enthought.com>
parents: 76877
diff changeset
455 from test_unparse import DirectoryTestCase
76814
f9344a3eaaa6 Issue #14695: Run Tools/parser/test_unparse.py as part of test_tools.
Mark Dickinson <mdickinson@enthought.com>
parents: 76251
diff changeset
456
f9344a3eaaa6 Issue #14695: Run Tools/parser/test_unparse.py as part of test_tools.
Mark Dickinson <mdickinson@enthought.com>
parents: 76251
diff changeset
457
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
458 def test_main():
76106
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
459 support.run_unittest(*[obj for obj in globals().values()
62dde5dd475e #14490, #14491: add 'sundry'-style import tests for Tools/scripts.
R David Murray <rdmurray@bitdance.com>
parents: 75281
diff changeset
460 if isinstance(obj, type)])
75281
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
461
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
462
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
463 if __name__ == '__main__':
2887f5a97075 Add test file for scripts in Tools (#13447).
Éric Araujo <merwok@netwok.org>
parents:
diff changeset
464 unittest.main()