Codebase list autopep8 / 9d1b9c4
Import upstream version 2.0.1 Debian Janitor 1 year, 4 months ago
7 changed file(s) with 45 addition(s) and 381 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 2.1
11 Name: autopep8
2 Version: 2.0.0
2 Version: 2.0.1
33 Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide
44 Home-page: https://github.com/hhatto/autopep8
55 Author: Hideo Hattori
2020 Classifier: Programming Language :: Python :: 3.10
2121 Classifier: Topic :: Software Development :: Libraries :: Python Modules
2222 Classifier: Topic :: Software Development :: Quality Assurance
23 Requires-Python: >=3.6
2324 License-File: LICENSE
2425 License-File: AUTHORS.rst
2526
270271 W391 - Remove trailing blank lines.
271272 W503 - Fix line break before binary operator.
272273 W504 - Fix line break after binary operator.
273 W601 - Use "in" rather than "has_key()".
274 W602 - Fix deprecated form of raising exception.
275 W603 - Use "!=" instead of "<>"
276 W604 - Use "repr()" instead of backticks.
277274 W605 - Fix invalid escape sequence 'x'.
278275 W690 - Fix various deprecated code (via lib2to3).
279276
327324 to fix various types of indentation issues::
328325
329326 $ autopep8 --select=E1,W1 <filename>
330
331 Similarly, to just fix deprecated code::
332
333 $ autopep8 --aggressive --select=W6 <filename>
334
335 The above is useful when trying to port a single code base to work with both
336 Python 2 and Python 3 at the same time.
337327
338328 If the file being fixed is large, you may want to enable verbose progress
339329 messages::
379369 Or with options:
380370
381371 >>> import autopep8
382 >>> autopep8.fix_code('x.has_key(y)\n',
383 ... options={'aggressive': 1})
384 'y in x\n'
385372 >>> autopep8.fix_code('print( 123 )\n',
386373 ... options={'ignore': ['E']})
387374 'print( 123 )\n'
430417 Test cases are in ``test/test_autopep8.py``. They can be run directly via
431418 ``python test/test_autopep8.py`` or via tox_. The latter is useful for
432419 testing against multiple Python interpreters. (We currently test against
433 CPython versions 2.7, 3.6 3.7 and 3.8. We also test against PyPy.)
420 CPython versions 3.7, 3.8, 3.9 and 3.10. We also test against PyPy.)
434421
435422 .. _`tox`: https://pypi.org/project/tox/
436423
244244 W391 - Remove trailing blank lines.
245245 W503 - Fix line break before binary operator.
246246 W504 - Fix line break after binary operator.
247 W601 - Use "in" rather than "has_key()".
248 W602 - Fix deprecated form of raising exception.
249 W603 - Use "!=" instead of "<>"
250 W604 - Use "repr()" instead of backticks.
251247 W605 - Fix invalid escape sequence 'x'.
252248 W690 - Fix various deprecated code (via lib2to3).
253249
301297 to fix various types of indentation issues::
302298
303299 $ autopep8 --select=E1,W1 <filename>
304
305 Similarly, to just fix deprecated code::
306
307 $ autopep8 --aggressive --select=W6 <filename>
308
309 The above is useful when trying to port a single code base to work with both
310 Python 2 and Python 3 at the same time.
311300
312301 If the file being fixed is large, you may want to enable verbose progress
313302 messages::
353342 Or with options:
354343
355344 >>> import autopep8
356 >>> autopep8.fix_code('x.has_key(y)\n',
357 ... options={'aggressive': 1})
358 'y in x\n'
359345 >>> autopep8.fix_code('print( 123 )\n',
360346 ... options={'ignore': ['E']})
361347 'print( 123 )\n'
404390 Test cases are in ``test/test_autopep8.py``. They can be run directly via
405391 ``python test/test_autopep8.py`` or via tox_. The latter is useful for
406392 testing against multiple Python interpreters. (We currently test against
407 CPython versions 2.7, 3.6 3.7 and 3.8. We also test against PyPy.)
393 CPython versions 3.7, 3.8, 3.9 and 3.10. We also test against PyPy.)
408394
409395 .. _`tox`: https://pypi.org/project/tox/
410396
00 Metadata-Version: 2.1
11 Name: autopep8
2 Version: 2.0.0
2 Version: 2.0.1
33 Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide
44 Home-page: https://github.com/hhatto/autopep8
55 Author: Hideo Hattori
2020 Classifier: Programming Language :: Python :: 3.10
2121 Classifier: Topic :: Software Development :: Libraries :: Python Modules
2222 Classifier: Topic :: Software Development :: Quality Assurance
23 Requires-Python: >=3.6
2324 License-File: LICENSE
2425 License-File: AUTHORS.rst
2526
270271 W391 - Remove trailing blank lines.
271272 W503 - Fix line break before binary operator.
272273 W504 - Fix line break after binary operator.
273 W601 - Use "in" rather than "has_key()".
274 W602 - Fix deprecated form of raising exception.
275 W603 - Use "!=" instead of "<>"
276 W604 - Use "repr()" instead of backticks.
277274 W605 - Fix invalid escape sequence 'x'.
278275 W690 - Fix various deprecated code (via lib2to3).
279276
327324 to fix various types of indentation issues::
328325
329326 $ autopep8 --select=E1,W1 <filename>
330
331 Similarly, to just fix deprecated code::
332
333 $ autopep8 --aggressive --select=W6 <filename>
334
335 The above is useful when trying to port a single code base to work with both
336 Python 2 and Python 3 at the same time.
337327
338328 If the file being fixed is large, you may want to enable verbose progress
339329 messages::
379369 Or with options:
380370
381371 >>> import autopep8
382 >>> autopep8.fix_code('x.has_key(y)\n',
383 ... options={'aggressive': 1})
384 'y in x\n'
385372 >>> autopep8.fix_code('print( 123 )\n',
386373 ... options={'ignore': ['E']})
387374 'print( 123 )\n'
430417 Test cases are in ``test/test_autopep8.py``. They can be run directly via
431418 ``python test/test_autopep8.py`` or via tox_. The latter is useful for
432419 testing against multiple Python interpreters. (We currently test against
433 CPython versions 2.7, 3.6 3.7 and 3.8. We also test against PyPy.)
420 CPython versions 3.7, 3.8, 3.9 and 3.10. We also test against PyPy.)
434421
435422 .. _`tox`: https://pypi.org/project/tox/
436423
0 pycodestyle>=2.9.1
0 pycodestyle>=2.10.0
1
2 [:python_version < "3.11"]
13 tomli
8888 from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX
8989
9090
91 __version__ = '2.0.0'
91 __version__ = '2.0.1'
9292
9393
9494 CR = '\r'
128128 # to be enabled, disable both of them
129129 CONFLICTING_CODES = ('W503', 'W504')
130130
131 SELECTED_GLOBAL_FIXED_METHOD_CODES = ['W602', ]
132
133131 # W602 is handled separately due to the need to avoid "with_traceback".
134132 CODE_TO_2TO3 = {
135133 'E231': ['ws_comma'],
136134 'E721': ['idioms'],
137 'W601': ['has_key'],
138 'W603': ['ne'],
139 'W604': ['repr'],
140135 'W690': ['apply',
141136 'except',
142137 'exitfunc',
17781773 filename=filename)
17791774
17801775
1781 def fix_w602(source, aggressive=True):
1782 """Fix deprecated form of raising exception."""
1783 if not aggressive:
1784 return source
1785
1786 return refactor(source, ['raise'], ignore='with_traceback')
1787
1788
17891776 def find_newline(source):
17901777 """Return type of newline used in source.
17911778
33423329 continue
33433330
33443331 if r['line'] in commented_out_code_line_numbers:
3345 if issue_id.startswith(('e26', 'e501')):
3332 if issue_id.startswith(('e261', 'e262', 'e501')):
33463333 continue
33473334
33483335 # Do not touch indentation if there is a token error caused by
35463533 # Disable "apply_local_fixes()" for now due to issue #175.
35473534 fixed_source = tmp_source
35483535 else:
3549 pep8_options = {
3550 'ignore': options.ignore,
3551 'select': options.select,
3552 'max_line_length': options.max_line_length,
3553 'hang_closing': options.hang_closing,
3554 }
3555 sio = io.StringIO(tmp_source)
3556 contents = sio.readlines()
3557 results = _execute_pep8(pep8_options, contents)
3558 codes = {result['id'] for result in results
3559 if result['id'] in SELECTED_GLOBAL_FIXED_METHOD_CODES}
35603536 # Apply global fixes only once (for efficiency).
35613537 fixed_source = apply_global_fixes(tmp_source,
35623538 options,
3563 filename=filename,
3564 codes=codes)
3539 filename=filename)
35653540
35663541 passes = 0
35673542 long_line_ignore_cache = set()
36833658 )
36843659
36853660 for (code, function) in global_fixes():
3686 if code.upper() in SELECTED_GLOBAL_FIXED_METHOD_CODES \
3687 and code.upper() not in codes:
3688 continue
36893661 if code_match(code, select=options.select, ignore=options.ignore):
36903662 if options.verbose:
36913663 print('---> Applying {} fix for {}'.format(where,
40454017
40464018 def read_pyproject_toml(args, parser):
40474019 """Read pyproject.toml and load configuration."""
4048 import tomli
4020 if sys.version_info >= (3, 11):
4021 import tomllib
4022 else:
4023 import tomli as tomllib
40494024
40504025 config = None
40514026
40524027 if os.path.exists(args.global_config):
40534028 with open(args.global_config, "rb") as fp:
4054 config = tomli.load(fp)
4029 config = tomllib.load(fp)
40554030
40564031 if not args.ignore_local_config:
40574032 parent = tail = args.files and os.path.abspath(
40604035 pyproject_toml = os.path.join(parent, "pyproject.toml")
40614036 if os.path.exists(pyproject_toml):
40624037 with open(pyproject_toml, "rb") as fp:
4063 config = tomli.load(fp)
4038 config = tomllib.load(fp)
40644039 break
40654040 (parent, tail) = os.path.split(parent)
40664041
99
1010
1111 INSTALL_REQUIRES = (
12 ['pycodestyle >= 2.9.1', 'tomli']
12 ['pycodestyle >= 2.10.0', 'tomli; python_version < "3.11"']
1313 )
1414
1515
5050 ],
5151 keywords='automation, pep8, format, pycodestyle',
5252 install_requires=INSTALL_REQUIRES,
53 python_requires=">=3.6",
5354 test_suite='test.test_autopep8',
5455 py_modules=['autopep8'],
5556 zip_safe=False,
270270 commented_out_code = '#x = 1'
271271 self.assertEqual(
272272 commented_out_code,
273 fix_e265_and_e266(commented_out_code))
273 fix_e266(commented_out_code))
274274
275275 def test_fix_file(self):
276276 self.assertIn(
322322 self.assertEqual(
323323 'print( 123 )\n',
324324 autopep8.fix_code('print( 123 )\n', options={'ignore': ['E']}))
325
326 self.assertEqual(
327 'y in x\n',
328 autopep8.fix_code('x.has_key(y)\n', options={'aggressive': True}))
329325
330326 def test_fix_code_with_bad_options(self):
331327 with self.assertRaises(ValueError):
710706 1,
711707 autopep8.count_unbalanced_brackets(
712708 "'','.join(['%s=%s' % (col, col)')"))
713
714 def test_refactor_with_2to3(self):
715 self.assertEqual(
716 '1 in {}\n',
717 autopep8.refactor_with_2to3('{}.has_key(1)\n', ['has_key']))
718
719 def test_refactor_with_2to3_should_handle_syntax_error_gracefully(self):
720 self.assertEqual(
721 '{}.has_key(1\n',
722 autopep8.refactor_with_2to3('{}.has_key(1\n', ['has_key']))
723709
724710 def test_commented_out_code_lines(self):
725711 self.assertEqual(
991977
992978 def test_e101_should_ignore_multiline_strings_complex(self):
993979 line = """\
994 print(3 <> 4, '''
980 print(3 != 4, '''
995981 while True:
996982 if True:
997983 \t1
998 \t''', 4 <> 5)
984 \t''', 4 != 5)
999985 """
1000986 fixed = """\
1001987 print(3 != 4, '''
22512237 with autopep8_context(line, options=['--select=E265']) as result:
22522238 self.assertEqual(fixed, result)
22532239
2240 def test_e265_issue662(self):
2241 line = "#print(\" \")\n"
2242 fixed = "# print(\" \")\n"
2243 with autopep8_context(line, options=['--select=E265']) as result:
2244 self.assertEqual(fixed, result)
2245
22542246 def test_ignore_e265(self):
22552247 line = "## A comment\n#B comment\n123\n"
22562248 fixed = "# A comment\n#B comment\n123\n"
22672259 line = "## A comment\n#B comment\n123\n"
22682260 fixed = "# A comment\n#B comment\n123\n"
22692261 with autopep8_context(line, options=['--select=E266']) as result:
2262 self.assertEqual(fixed, result)
2263
2264 def test_e266_issue662(self):
2265 line = "## comment\n"
2266 fixed = "# comment\n"
2267 with autopep8_context(line) as result:
22702268 self.assertEqual(fixed, result)
22712269
22722270 def test_ignore_e266(self):
31803178 # http://foo.bar/abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-
31813179
31823180 # The following is ugly commented-out code and should not be touched.
3183 #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
3181 # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
31843182 """
31853183 with autopep8_context(line, options=['--aggressive']) as result:
31863184 self.assertEqual(fixed, result)
44434441
44444442 def test_w191_should_ignore_multiline_strings(self):
44454443 line = """\
4446 print(3 <> 4, '''
4444 print(3 != 4, '''
44474445 while True:
44484446 if True:
44494447 \t1
4450 \t''', 4 <> 5)
4448 \t''', 4 != 5)
44514449 if True:
44524450 \t123
44534451 """
48454843 with autopep8_context(line, options=['-aa', '--select=E,W5']) as result:
48464844 self.assertEqual(fixed, result)
48474845 with autopep8_context(line, options=['-aa', '--select=E,W50']) as result:
4848 self.assertEqual(fixed, result)
4849
4850 def test_w601(self):
4851 line = 'a = {0: 1}\na.has_key(0)\n'
4852 fixed = 'a = {0: 1}\n0 in a\n'
4853 with autopep8_context(line, options=['--aggressive']) as result:
4854 self.assertEqual(fixed, result)
4855
4856 def test_w601_word(self):
4857 line = 'my_dict = {0: 1}\nmy_dict.has_key(0)\n'
4858 fixed = 'my_dict = {0: 1}\n0 in my_dict\n'
4859 with autopep8_context(line, options=['--aggressive']) as result:
4860 self.assertEqual(fixed, result)
4861
4862 def test_w601_conditional(self):
4863 line = 'a = {0: 1}\nif a.has_key(0):\n print 1\n'
4864 fixed = 'a = {0: 1}\nif 0 in a:\n print 1\n'
4865 with autopep8_context(line, options=['--aggressive']) as result:
4866 self.assertEqual(fixed, result)
4867
4868 def test_w601_self(self):
4869 line = 'self.a.has_key(0)\n'
4870 fixed = '0 in self.a\n'
4871 with autopep8_context(line, options=['--aggressive']) as result:
4872 self.assertEqual(fixed, result)
4873
4874 def test_w601_self_with_conditional(self):
4875 line = 'if self.a.has_key(0):\n print 1\n'
4876 fixed = 'if 0 in self.a:\n print 1\n'
4877 with autopep8_context(line, options=['--aggressive']) as result:
4878 self.assertEqual(fixed, result)
4879
4880 def test_w601_with_multiple(self):
4881 line = 'a.has_key(0) and b.has_key(0)\n'
4882 fixed = '0 in a and 0 in b\n'
4883 with autopep8_context(line, options=['--aggressive']) as result:
4884 self.assertEqual(fixed, result)
4885
4886 def test_w601_with_multiple_nested(self):
4887 line = 'alpha.has_key(nested.has_key(12)) and beta.has_key(1)\n'
4888 fixed = '(12 in nested) in alpha and 1 in beta\n'
4889 with autopep8_context(line, options=['--aggressive']) as result:
4890 self.assertEqual(fixed, result)
4891
4892 def test_w601_with_more_complexity(self):
4893 line = 'y.has_key(0) + x.has_key(x.has_key(0) + x.has_key(x.has_key(0) + x.has_key(1)))\n'
4894 fixed = '(0 in y) + ((0 in x) + ((0 in x) + (1 in x) in x) in x)\n'
4895 with autopep8_context(line, options=['--aggressive']) as result:
4896 self.assertEqual(fixed, result)
4897
4898 def test_w601_precedence(self):
4899 line = 'if self.a.has_key(1 + 2):\n print 1\n'
4900 fixed = 'if 1 + 2 in self.a:\n print 1\n'
4901 with autopep8_context(line, options=['--aggressive']) as result:
4902 self.assertEqual(fixed, result)
4903
4904 def test_w601_with_parens(self):
4905 line = 'foo(12) in alpha\n'
4906 with autopep8_context(line, options=['--aggressive']) as result:
4907 self.assertEqual(line, result)
4908
4909 def test_w601_with_multiline(self):
4910 line = """\
4911 a.has_key(
4912 0
4913 )
4914 """
4915 fixed = '0 in a\n'
4916 with autopep8_context(line, options=['--aggressive']) as result:
4917 self.assertEqual(fixed, result)
4918
4919 def test_w601_with_non_ascii(self):
4920 line = """\
4921 # -*- coding: utf-8 -*-
4922 ## éはe
4923 correct = dict().has_key('good syntax ?')
4924 """
4925
4926 fixed = """\
4927 # -*- coding: utf-8 -*-
4928 # éはe
4929 correct = 'good syntax ?' in dict()
4930 """
4931
4932 with autopep8_context(line, options=['--aggressive']) as result:
4933 self.assertEqual(fixed, result)
4934
4935 def test_w602_arg_is_string(self):
4936 line = "raise ValueError, \"w602 test\"\n"
4937 fixed = "raise ValueError(\"w602 test\")\n"
4938 with autopep8_context(line, options=['--aggressive']) as result:
4939 self.assertEqual(fixed, result)
4940
4941 def test_w602_arg_is_string_with_comment(self):
4942 line = "raise ValueError, \"w602 test\" # comment\n"
4943 fixed = "raise ValueError(\"w602 test\") # comment\n"
4944 with autopep8_context(line, options=['--aggressive']) as result:
4945 self.assertEqual(fixed, result)
4946
4947 def test_w602_skip_ambiguous_case(self):
4948 line = "raise 'a', 'b', 'c'\n"
4949 with autopep8_context(line, options=['--aggressive']) as result:
4950 self.assertEqual(line, result)
4951
4952 def test_w602_with_logic(self):
4953 line = "raise TypeError, e or 'hello'\n"
4954 fixed = "raise TypeError(e or 'hello')\n"
4955 with autopep8_context(line, options=['--aggressive']) as result:
4956 self.assertEqual(fixed, result)
4957
4958 def test_w602_triple_quotes(self):
4959 line = 'raise ValueError, """hello"""\n1\n'
4960 fixed = 'raise ValueError("""hello""")\n1\n'
4961 with autopep8_context(line, options=['--aggressive']) as result:
4962 self.assertEqual(fixed, result)
4963
4964 def test_w602_multiline(self):
4965 line = 'raise ValueError, """\nhello"""\n'
4966 fixed = 'raise ValueError("""\nhello""")\n'
4967 with autopep8_context(line, options=['--aggressive']) as result:
4968 self.assertEqual(fixed, result)
4969
4970 def test_w602_with_complex_multiline(self):
4971 line = 'raise ValueError, """\nhello %s %s""" % (\n 1, 2)\n'
4972 fixed = 'raise ValueError("""\nhello %s %s""" % (\n 1, 2))\n'
4973 with autopep8_context(line, options=['--aggressive']) as result:
4974 self.assertEqual(fixed, result)
4975
4976 def test_w602_multiline_with_trailing_spaces(self):
4977 line = 'raise ValueError, """\nhello""" \n'
4978 fixed = 'raise ValueError("""\nhello""")\n'
4979 with autopep8_context(line, options=['--aggressive']) as result:
4980 self.assertEqual(fixed, result)
4981
4982 def test_w602_multiline_with_escaped_newline(self):
4983 line = 'raise ValueError, \\\n"""\nhello"""\n'
4984 fixed = 'raise ValueError("""\nhello""")\n'
4985 with autopep8_context(line, options=['--aggressive']) as result:
4986 self.assertEqual(fixed, result)
4987
4988 def test_w602_multiline_with_escaped_newline_and_comment(self):
4989 line = 'raise ValueError, \\\n"""\nhello""" # comment\n'
4990 fixed = 'raise ValueError("""\nhello""") # comment\n'
4991 with autopep8_context(line, options=['--aggressive']) as result:
4992 self.assertEqual(fixed, result)
4993
4994 def test_w602_multiline_with_multiple_escaped_newlines(self):
4995 line = 'raise ValueError, \\\n\\\n\\\n"""\nhello"""\n'
4996 fixed = 'raise ValueError("""\nhello""")\n'
4997 with autopep8_context(line, options=['--aggressive']) as result:
4998 self.assertEqual(fixed, result)
4999
5000 def test_w602_multiline_with_nested_quotes(self):
5001 line = 'raise ValueError, """hello\'\'\'blah"a"b"c"""\n'
5002 fixed = 'raise ValueError("""hello\'\'\'blah"a"b"c""")\n'
5003 with autopep8_context(line, options=['--aggressive']) as result:
5004 self.assertEqual(fixed, result)
5005
5006 def test_w602_with_multiline_with_single_quotes(self):
5007 line = "raise ValueError, '''\nhello'''\n"
5008 fixed = "raise ValueError('''\nhello''')\n"
5009 with autopep8_context(line, options=['--aggressive']) as result:
5010 self.assertEqual(fixed, result)
5011
5012 def test_w602_multiline_string_stays_the_same(self):
5013 line = 'raise """\nhello"""\n'
5014 with autopep8_context(line, options=['--aggressive']) as result:
5015 self.assertEqual(line, result)
5016
5017 def test_w602_escaped_lf(self):
5018 line = 'raise ValueError, \\\n"hello"\n'
5019 fixed = 'raise ValueError("hello")\n'
5020 with autopep8_context(line, options=['--aggressive']) as result:
5021 self.assertEqual(fixed, result)
5022
5023 def test_w602_escaped_crlf(self):
5024 line = 'raise ValueError, \\\r\n"hello"\r\n'
5025 fixed = 'raise ValueError("hello")\r\n'
5026 with autopep8_context(line, options=['--aggressive']) as result:
5027 self.assertEqual(fixed, result)
5028
5029 def test_w602_indentation(self):
5030 line = 'def foo():\n raise ValueError, "hello"\n'
5031 fixed = 'def foo():\n raise ValueError("hello")\n'
5032 with autopep8_context(line, options=['--aggressive']) as result:
5033 self.assertEqual(fixed, result)
5034
5035 def test_w602_escaped_cr(self):
5036 line = 'raise ValueError, \\\r"hello"\n\n'
5037 fixed = 'raise ValueError("hello")\n'
5038 with autopep8_context(line, options=['--aggressive']) as result:
5039 self.assertEqual(fixed, result)
5040
5041 def test_w602_multiple_statements(self):
5042 line = 'raise ValueError, "hello";print 1\n'
5043 fixed = 'raise ValueError("hello")\nprint 1\n'
5044 with autopep8_context(line, options=['--aggressive']) as result:
5045 self.assertEqual(fixed, result)
5046
5047 def test_w602_raise_argument_with_indentation(self):
5048 line = 'if True:\n raise ValueError, "error"\n'
5049 fixed = 'if True:\n raise ValueError("error")\n'
5050 with autopep8_context(line, options=['--aggressive']) as result:
5051 self.assertEqual(fixed, result)
5052
5053 def test_w602_skip_raise_argument_triple(self):
5054 line = 'raise ValueError, "info", traceback\n'
5055 with autopep8_context(line, options=['--aggressive']) as result:
5056 self.assertEqual(line, result)
5057
5058 def test_w602_skip_raise_argument_triple_with_comment(self):
5059 line = 'raise ValueError, "info", traceback # comment\n'
5060 with autopep8_context(line, options=['--aggressive']) as result:
5061 self.assertEqual(line, result)
5062
5063 def test_w602_raise_argument_triple_fake(self):
5064 line = 'raise ValueError, "info, info2"\n'
5065 fixed = 'raise ValueError("info, info2")\n'
5066 with autopep8_context(line, options=['--aggressive']) as result:
5067 self.assertEqual(fixed, result)
5068
5069 def test_w602_with_list_comprehension(self):
5070 line = 'raise Error, [x[0] for x in probs]\n'
5071 fixed = 'raise Error([x[0] for x in probs])\n'
5072 with autopep8_context(line, options=['--aggressive']) as result:
5073 self.assertEqual(fixed, result)
5074
5075 def test_w602_with_bad_syntax(self):
5076 line = "raise Error, 'abc\n"
5077 with autopep8_context(line, options=['--aggressive']) as result:
5078 self.assertEqual(line, result)
5079
5080 def test_w602_invalid_2to3_fixed_case(self):
5081 line = """\
5082 raise (ValueError
5083 if True else TypeError)
5084 """
5085 with autopep8_context(line, options=['--aggressive']) as result:
5086 self.assertEqual(line, result)
5087
5088 @unittest.skip('TODO')
5089 def test_w602_invalid_2to3_fixed_case_with_valid_syntax(self):
5090 line = """\
5091 raise (ValueError
5092 if True else TypeError)
5093 raise ValueError, "error"
5094 """
5095 fixed = """\
5096 raise (ValueError
5097 if True else TypeError)
5098 raise ValueError("error")
5099 """
5100 with autopep8_context(line, options=['--aggressive']) as result:
5101 self.assertEqual(fixed, result)
5102
5103 def test_w603(self):
5104 line = 'if 2 <> 2:\n print False'
5105 fixed = 'if 2 != 2:\n print False\n'
5106 with autopep8_context(line, options=['--aggressive']) as result:
5107 self.assertEqual(fixed, result)
5108
5109 def test_w604(self):
5110 line = '`1`\n'
5111 fixed = 'repr(1)\n'
5112 with autopep8_context(line, options=['--aggressive']) as result:
5113 self.assertEqual(fixed, result)
5114
5115 def test_w604_with_multiple_instances(self):
5116 line = '``1`` + ``b``\n'
5117 fixed = 'repr(repr(1)) + repr(repr(b))\n'
5118 with autopep8_context(line, options=['--aggressive']) as result:
5119 self.assertEqual(fixed, result)
5120
5121 def test_w604_with_multiple_lines(self):
5122 line = '`(1\n )`\n'
5123 fixed = 'repr((1\n ))\n'
5124 with autopep8_context(line, options=['--aggressive']) as result:
51254846 self.assertEqual(fixed, result)
51264847
51274848 def test_w605_simple(self):
67326453 # http://foo.bar/abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-abc-
67336454
67346455 # The following is ugly commented-out code and should not be touched.
6735 #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
6456 # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = 1
67366457 """
67376458 with autopep8_context(line, options=['--experimental',
67386459 '--aggressive']) as result:
75777298 self.assertEqual(fixed, result)
75787299
75797300
7301 def fix_e266(source):
7302 with autopep8_context(source, options=['--select=E266']) as result:
7303 return result
7304
7305
75807306 def fix_e265_and_e266(source):
75817307 with autopep8_context(source, options=['--select=E265,E266']) as result:
75827308 return result