Skip to content

Commit

Permalink
seperate SystemTests
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Jun 23, 2024
1 parent 4c533b3 commit a8126d5
Showing 1 changed file with 50 additions and 21 deletions.
71 changes: 50 additions & 21 deletions test/test_autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@

class UnitTests(unittest.TestCase):

maxDiff = None

def test_compile_value_error(self):
source = '"\\xhh" \\'
self.assertFalse(autopep8.check_syntax(source))
Expand Down Expand Up @@ -267,19 +265,23 @@ def test_format_block_comments_should_only_touch_real_comments(self):
fix_e266(commented_out_code))

def test_fix_file(self):
self.assertIn(
'import ',
autopep8.fix_file(
filename=os.path.join(ROOT_DIR, 'test', 'example.py')))
ret = autopep8.fix_file(
filename=os.path.join(ROOT_DIR, 'test', 'example.py')
)
self.assertNotEqual(None, ret)
if ret is not None:
self.assertIn('import ', ret)

def test_fix_file_with_diff(self):
filename = os.path.join(ROOT_DIR, 'test', 'example.py')

self.assertIn(
'@@',
autopep8.fix_file(
filename=filename,
options=autopep8.parse_args(['--diff', filename])))
ret = autopep8.fix_file(
filename=filename,
options=autopep8.parse_args(['--diff', filename])
)
self.assertNotEqual(None, ret)
if ret is not None:
self.assertIn('@@', ret)

def test_fix_lines(self):
self.assertEqual(
Expand Down Expand Up @@ -806,9 +808,7 @@ def test_get_fixed_long_line_empty(self):
self.assertEqual(line, autopep8.get_fixed_long_line(line, line, line))


class SystemTests(unittest.TestCase):

maxDiff = None
class SystemTestsE1(unittest.TestCase):

def test_e101(self):
line = """\
Expand Down Expand Up @@ -1781,6 +1781,9 @@ def test_e131_invalid_indent_with_select_option(self):
with autopep8_context(line, options=['--select=E131']) as result:
self.assertEqual(fixed, result)


class SystemTestsE2(unittest.TestCase):

def test_e201(self):
line = '( 1)\n'
fixed = '(1)\n'
Expand Down Expand Up @@ -2284,6 +2287,9 @@ def test_e274(self):
with autopep8_context(line) as result:
self.assertEqual(fixed, result)


class SystemTestsE3(unittest.TestCase):

def test_e306(self):
line = """
def test_descriptors(self):
Expand Down Expand Up @@ -2436,6 +2442,9 @@ def test_e305(self):
with autopep8_context(line) as result:
self.assertEqual(fixed, result)


class SystemTestsE4(unittest.TestCase):

def test_e401(self):
line = 'import os, sys\n'
fixed = 'import os\nimport sys\n'
Expand Down Expand Up @@ -2618,6 +2627,9 @@ def f():
with autopep8_context(line) as result:
self.assertEqual(fixed, result)


class SystemTestsE5(unittest.TestCase):

def test_e501_basic(self):
line = """\
Expand Down Expand Up @@ -3959,6 +3971,9 @@ def test_e502(self):
with autopep8_context(line) as result:
self.assertEqual(fixed, result)


class SystemTestsE7(unittest.TestCase):

def test_e701(self):
line = 'if True: print(True)\n'
fixed = 'if True:\n print(True)\n'
Expand Down Expand Up @@ -4469,6 +4484,9 @@ def test_e731_with_default_arguments(self):
with autopep8_context(line, options=['--select=E731']) as result:
self.assertEqual(fixed, result)


class SystemTestsE9(unittest.TestCase):

@unittest.skipIf(sys.version_info >= (3, 12), 'not detect in Python3.12+')
def test_e901_should_cause_indentation_screw_up(self):
line = """\
Expand All @@ -4494,6 +4512,9 @@ def test_should_preserve_vertical_tab(self):
with autopep8_context(line) as result:
self.assertEqual(fixed, result)


class SystemTestsW1(unittest.TestCase):

def test_w191_should_ignore_multiline_strings(self):
line = """\
print(3 != 4, '''
Expand Down Expand Up @@ -4544,6 +4565,9 @@ def test_w191_should_ignore_tabs_in_strings(self):
with autopep8_context(line, options=['--aggressive']) as result:
self.assertEqual(fixed, result)


class SystemTestsW2(unittest.TestCase):

def test_w291(self):
line = "print('a b ')\t \n"
fixed = "print('a b ')\n"
Expand Down Expand Up @@ -4575,6 +4599,9 @@ def test_w293(self):
with autopep8_context(line, options=['--aggressive']) as result:
self.assertEqual(fixed, result)


class SystemTestsW3(unittest.TestCase):

def test_w391(self):
line = ' \n'
fixed = ''
Expand All @@ -4587,6 +4614,9 @@ def test_w391_more_complex(self):
with autopep8_context(line, options=['--aggressive']) as result:
self.assertEqual(fixed, result)


class SystemTestsW5(unittest.TestCase):

def test_w503(self):
line = '(width == 0\n + height == 0)\n'
fixed = '(width == 0 +\n height == 0)\n'
Expand Down Expand Up @@ -4900,6 +4930,9 @@ def test_w503_and_w504_conflict(self):
with autopep8_context(line, options=['-aa', '--select=E,W50']) as result:
self.assertEqual(fixed, result)


class SystemTestsW6(unittest.TestCase):

def test_w605_simple(self):
line = "escape = '\\.jpg'\n"
fixed = "escape = '\\\\.jpg'\n"
Expand Down Expand Up @@ -5416,8 +5449,6 @@ def test_get_module_imports_case_of_autopep8(self):

class CommandLineTests(unittest.TestCase):

maxDiff = None

def test_e122_and_e302_with_backslash(self):
line = """\
import sys
Expand Down Expand Up @@ -5482,7 +5513,7 @@ def test_diff_with_standard_in(self):

def test_indent_size_is_zero(self):
line = "'abc'\n"
with autopep8_subprocess(line, ['--indent-size=0']) as (result, retcode):
with autopep8_subprocess(line, ['--indent-size=0']) as (_, retcode):
self.assertEqual(retcode, autopep8.EXIT_CODE_ARGPARSE_ERROR)

def test_exit_code_with_io_error(self):
Expand Down Expand Up @@ -5642,7 +5673,7 @@ def test_parallel_jobs_with_diff_option(self):

with temporary_file_context(line) as filename_a:
with temporary_file_context(line) as filename_b:
files = list(set([filename_a, filename_b]))
files = list({filename_a, filename_b})
p = Popen(list(AUTOPEP8_CMD_TUPLE) + files +
['--jobs=3', '--diff'], stdout=PIPE)
p.wait()
Expand Down Expand Up @@ -6108,8 +6139,6 @@ def test_setupcfg_with_pycodestyle_config(self):

class ExperimentalSystemTests(unittest.TestCase):

maxDiff = None

def test_e501_experimental_basic(self):
line = """\
print(111, 111, 111, 111, 222, 222, 222, 222, 222, 222, 222, 222, 222, 333, 333, 333, 333)
Expand Down Expand Up @@ -7403,7 +7432,7 @@ def autopep8_subprocess(line, options, timeout=None):
p.kill()
raise Exception("subprocess is timed out")
_stdout, _ = p.communicate()
yield (_stdout.decode('utf-8'), p.returncode)
yield _stdout.decode('utf-8'), p.returncode


@contextlib.contextmanager
Expand Down

0 comments on commit a8126d5

Please sign in to comment.