checkpoint: massive refactor
This commit is contained in:
@@ -3,22 +3,22 @@ import textwrap
|
||||
from scripts.ai_style_formatter import format_code
|
||||
|
||||
def test_basic_indentation():
|
||||
source = textwrap.dedent("""\
|
||||
source = textwrap.dedent("""\
|
||||
def hello():
|
||||
print("world")
|
||||
if True:
|
||||
print("nested")
|
||||
""")
|
||||
expected = (
|
||||
"def hello():\n"
|
||||
" print(\"world\")\n"
|
||||
" if True:\n"
|
||||
" print(\"nested\")\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
expected = (
|
||||
"def hello():\n"
|
||||
" print(\"world\")\n"
|
||||
" if True:\n"
|
||||
" print(\"nested\")\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
|
||||
def test_top_level_blank_lines():
|
||||
source = textwrap.dedent("""\
|
||||
source = textwrap.dedent("""\
|
||||
def a():
|
||||
pass
|
||||
|
||||
@@ -26,31 +26,31 @@ def test_top_level_blank_lines():
|
||||
def b():
|
||||
pass
|
||||
""")
|
||||
expected = (
|
||||
"def a():\n"
|
||||
" pass\n"
|
||||
"\n"
|
||||
"def b():\n"
|
||||
" pass\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
expected = (
|
||||
"def a():\n"
|
||||
" pass\n"
|
||||
"\n"
|
||||
"def b():\n"
|
||||
" pass\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
|
||||
def test_inner_blank_lines():
|
||||
source = textwrap.dedent("""\
|
||||
source = textwrap.dedent("""\
|
||||
def a():
|
||||
print("start")
|
||||
|
||||
print("end")
|
||||
""")
|
||||
expected = (
|
||||
"def a():\n"
|
||||
" print(\"start\")\n"
|
||||
" print(\"end\")\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
expected = (
|
||||
"def a():\n"
|
||||
" print(\"start\")\n"
|
||||
" print(\"end\")\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
|
||||
def test_multiline_string_safety():
|
||||
source = textwrap.dedent("""\
|
||||
source = textwrap.dedent("""\
|
||||
def a():
|
||||
'''
|
||||
This is a multiline
|
||||
@@ -60,21 +60,20 @@ def test_multiline_string_safety():
|
||||
'''
|
||||
pass
|
||||
""")
|
||||
# Note: the indentation of the ''' itself becomes 1 space.
|
||||
# The content inside remains exactly as in source.
|
||||
# textwrap.dedent will remove the common leading whitespace from the source.
|
||||
# The source's ''' is at 4 spaces. Content is at 4 spaces.
|
||||
# After dedent:
|
||||
# def a():
|
||||
# '''
|
||||
# This is a...
|
||||
|
||||
result = format_code(source)
|
||||
assert " This is a multiline" in result
|
||||
assert result.startswith("def a():\n '''")
|
||||
# Note: the indentation of the ''' itself becomes 1 space.
|
||||
# The content inside remains exactly as in source.
|
||||
# textwrap.dedent will remove the common leading whitespace from the source.
|
||||
# The source's ''' is at 4 spaces. Content is at 4 spaces.
|
||||
# After dedent:
|
||||
# def a():
|
||||
# '''
|
||||
# This is a...
|
||||
result = format_code(source)
|
||||
assert " This is a multiline" in result
|
||||
assert result.startswith("def a():\n '''")
|
||||
|
||||
def test_continuation_indentation():
|
||||
source = textwrap.dedent("""\
|
||||
source = textwrap.dedent("""\
|
||||
def long_func(
|
||||
a,
|
||||
b
|
||||
@@ -84,20 +83,20 @@ def test_continuation_indentation():
|
||||
b
|
||||
)
|
||||
""")
|
||||
expected = (
|
||||
"def long_func(\n"
|
||||
" a,\n"
|
||||
" b\n"
|
||||
"):\n"
|
||||
" return (\n"
|
||||
" a +\n"
|
||||
" b\n"
|
||||
" )\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
expected = (
|
||||
"def long_func(\n"
|
||||
" a,\n"
|
||||
" b\n"
|
||||
"):\n"
|
||||
" return (\n"
|
||||
" a +\n"
|
||||
" b\n"
|
||||
" )\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
|
||||
def test_multiple_top_level_definitions():
|
||||
source = textwrap.dedent("""\
|
||||
source = textwrap.dedent("""\
|
||||
class MyClass:
|
||||
def __init__(self):
|
||||
self.x = 1
|
||||
@@ -109,14 +108,14 @@ def test_multiple_top_level_definitions():
|
||||
def top_level():
|
||||
pass
|
||||
""")
|
||||
expected = (
|
||||
"class MyClass:\n"
|
||||
" def __init__(self):\n"
|
||||
" self.x = 1\n"
|
||||
" def method(self):\n"
|
||||
" pass\n"
|
||||
"\n"
|
||||
"def top_level():\n"
|
||||
" pass\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
expected = (
|
||||
"class MyClass:\n"
|
||||
" def __init__(self):\n"
|
||||
" self.x = 1\n"
|
||||
" def method(self):\n"
|
||||
" pass\n"
|
||||
"\n"
|
||||
"def top_level():\n"
|
||||
" pass\n"
|
||||
)
|
||||
assert format_code(source) == expected
|
||||
|
||||
Reference in New Issue
Block a user