Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-103997: Automatically dedent the argument to "-c"#103998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
16be08fe88216bbcb7c77fb8985a26f27a8417eff8924e0a69f956723f4a78b97f207904435eb4c4eca9f9c969b674f1e005d41699d53c4e689a13af0ac7ea71cad014549de80c3b90b1f5b746ca405891f17e232de2e1ec84616ca19b6757ce411fdea4301e06d40ca40d02895696551735d0fd3681b73b4a7bcf355760b1e89c9d1b4cd1e556bbf136c8b08e5cc7fcd14a0007d2273ed6e17bd1edb1b4c78c5738d2a4e42b633098c17e5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1055,57 +1055,63 @@ def test_cmd_dedent(self): | ||
| # test that -c auto-dedents its arguments | ||
| from textwrap import dedent | ||
sunmy2019 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| test_cases = [ | ||
sunmy2019 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| ( | ||
| """ | ||
| print('space-auto-dedent') | ||
| """, | ||
| "space-auto-dedent", | ||
| ), | ||
| ( | ||
| dedent( | ||
| """ | ||
| ^^^print('tab-auto-dedent') | ||
| """ | ||
| ).replace("^", "\t"), | ||
| "tab-auto-dedent", | ||
| ), | ||
| ( | ||
| dedent( | ||
| """ | ||
| ^^if 1: | ||
| ^^^^print('mixed-auto-dedent-1') | ||
| ^^print('mixed-auto-dedent-2') | ||
| """ | ||
| ).replace("^", "\t \t"), | ||
| "mixed-auto-dedent-1\nmixed-auto-dedent-2", | ||
| ), | ||
| ( | ||
| ''' | ||
| data = """$ | ||
| this data has an empty newline above and a newline with spaces below $ | ||
| $ | ||
| """$ | ||
| if 1: $ | ||
| print(repr(data))$ | ||
| '''.replace( | ||
| "$", "" | ||
| ), | ||
| # Note: entirely blank lines are normalized to \n, even if they | ||
| # are part of a data string. This is consistent with | ||
| # textwrap.dedent behavior, but might not be intuitive. | ||
| "'\\n\\nthis data has an empty newline above and a newline with spaces below \\n\\n'", | ||
| ), | ||
| ] | ||
| forcode, expected in test_cases: | ||
| # Run the auto-dedent case | ||
| args1 = sys.executable, '-c', code | ||
| proc1 = subprocess.run(args1, stdout=subprocess.PIPE) | ||
| self.assertEqual(proc1.returncode, 0, proc1) | ||
| output1 = proc1.stdout.strip().decode(encoding='utf-8') | ||
| # Manually dedent beforehand, check the result is the same. | ||
| args2 = sys.executable, '-c', dedent(code) | ||
| proc2 = subprocess.run(args2, stdout=subprocess.PIPE) | ||
| self.assertEqual(proc2.returncode, 0, proc2) | ||
| output2 = proc2.stdout.strip().decode(encoding='utf-8') | ||
| self.assertEqual(output1, output2) | ||
| self.assertEqual(output1.replace('\r\n', '\n'), expected) | ||
| def test_cmd_dedent_failcase(self): | ||
| # Mixing tabs and spaces is not allowed | ||
Uh oh!
There was an error while loading.Please reload this page.