summaryrefslogtreecommitdiffstats
path: root/generic/tclInterp.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclInterp.c')
0 files changed, 0 insertions, 0 deletions
hl str"> for i in a: break # end for for i in a: break else: pass # end for try: pass finally: pass # end try try: pass except TypeError: pass except ValueError: pass else: pass # end try try: pass except TypeError: pass except ValueError: pass finally: pass # end try with a: pass # end with class A: pass # end class A def f(): pass # end def f """) self.pindent_test(clean, closed) def test_multilevel(self): clean = textwrap.dedent("""\ def foobar(a, b): if a == b: a = a+1 elif a < b: b = b-1 if b > a: a = a-1 else: print 'oops!' """) closed = textwrap.dedent("""\ def foobar(a, b): if a == b: a = a+1 elif a < b: b = b-1 if b > a: a = a-1 # end if else: print 'oops!' # end if # end def foobar """) self.pindent_test(clean, closed) def test_preserve_indents(self): clean = textwrap.dedent("""\ if a: if b: pass """) closed = textwrap.dedent("""\ if a: if b: pass # end if # end if """) self.assertEqual(self.pindent(clean, '-c'), closed) self.assertEqual(self.pindent(closed, '-d'), clean) broken = self.lstriplines(closed) self.assertEqual(self.pindent(broken, '-r', '-e', '-s', '9'), closed) clean = textwrap.dedent("""\ if a: \tif b: \t\tpass """) closed = textwrap.dedent("""\ if a: \tif b: \t\tpass \t# end if # end if """) self.assertEqual(self.pindent(clean, '-c'), closed) self.assertEqual(self.pindent(closed, '-d'), clean) broken = self.lstriplines(closed) self.assertEqual(self.pindent(broken, '-r'), closed) def test_escaped_newline(self): clean = textwrap.dedent("""\ class\\ \\ A: def\ \\ f: pass """) closed = textwrap.dedent("""\ class\\ \\ A: def\ \\ f: pass # end def f # end class A """) self.assertEqual(self.pindent(clean, '-c'), closed) self.assertEqual(self.pindent(closed, '-d'), clean) def test_empty_line(self): clean = textwrap.dedent("""\ if a: pass """) closed = textwrap.dedent("""\ if a: pass # end if """) self.pindent_test(clean, closed) def test_oneline(self): clean = textwrap.dedent("""\ if a: pass """) closed = textwrap.dedent("""\ if a: pass # end if """) self.pindent_test(clean, closed) 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. # scripts that have independent tests. whitelist = ['reindent.py', 'pdeps.py', 'gprof2html'] # scripts that can't be imported without running blacklist = ['make_ctype.py'] # scripts that use windows-only modules windows_only = ['win_add2path.py'] # blacklisted for other reasons other = ['analyze_dxp.py'] skiplist = blacklist + whitelist + windows_only + other def setUp(self): cm = support.DirsOnSysPath(scriptsdir) cm.__enter__() self.addCleanup(cm.__exit__) def test_sundry(self): for fn in os.listdir(scriptsdir): if fn.endswith('.py') and fn not in self.skiplist: __import__(fn[:-3]) @unittest.skipIf(sys.platform != "win32", "Windows-only test") def test_sundry_windows(self): for fn in self.windows_only: __import__(fn[:-3]) @unittest.skipIf(not support.threading, "test requires _thread module") def test_analyze_dxp_import(self): if hasattr(sys, 'getdxp'): import analyze_dxp else: with self.assertRaises(RuntimeError): import analyze_dxp class PdepsTests(unittest.TestCase): @classmethod def setUpClass(self): path = os.path.join(scriptsdir, 'pdeps.py') spec = importlib.util.spec_from_file_location('pdeps', path) self.pdeps = importlib._bootstrap._SpecMethods(spec).load() @classmethod def tearDownClass(self): if 'pdeps' in sys.modules: del sys.modules['pdeps'] def test_process_errors(self): # Issue #14492: m_import.match(line) can be None. with tempfile.TemporaryDirectory() as tmpdir: fn = os.path.join(tmpdir, 'foo') with open(fn, 'w') as stream: stream.write("#!/this/will/fail") self.pdeps.process(fn, {}) def test_inverse_attribute_error(self): # Issue #14492: this used to fail with an AttributeError. self.pdeps.inverse({'a': []}) class Gprof2htmlTests(unittest.TestCase): def setUp(self): path = os.path.join(scriptsdir, 'gprof2html.py') spec = importlib.util.spec_from_file_location('gprof2html', path) self.gprof = importlib._bootstrap._SpecMethods(spec).load() oldargv = sys.argv def fixup(): sys.argv = oldargv self.addCleanup(fixup) sys.argv = [] def test_gprof(self): # Issue #14508: this used to fail with an NameError. with mock.patch.object(self.gprof, 'webbrowser') as wmock, \ tempfile.TemporaryDirectory() as tmpdir: fn = os.path.join(tmpdir, 'abc') open(fn, 'w').close() sys.argv = ['gprof2html', fn] self.gprof.main() self.assertTrue(wmock.open.called) # Run the tests in Tools/parser/test_unparse.py with support.DirsOnSysPath(os.path.join(basepath, 'parser')): from test_unparse import UnparseTestCase from test_unparse import DirectoryTestCase def test_main(): support.run_unittest(*[obj for obj in globals().values() if isinstance(obj, type)]) if __name__ == '__main__': unittest.main()