Skip to content

Commit

Permalink
format code style
Browse files Browse the repository at this point in the history
  • Loading branch information
cocolato committed Jan 19, 2024
1 parent 5d3e742 commit ab8e747
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
9 changes: 5 additions & 4 deletions mako/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,12 @@ def match_text(self):
r"""
(.*?) # anything, followed by:
(
(?<=\n)(?=[ \t]*(?=%(?!%)|\#\#)) # an eval or line-based
# comment, preceded by a
# consumed newline and whitespace
(?<=\n)(?=[ \t]*(?=%(?!%)|\#\#)) # an eval or line-based
# comment, preceded by a
# consumed newline and whitespace
|
(?<!%)(?=%%+) # consume the first percent sign out of a group of percent signs
(?<!%)(?=%%+) # consume the first percent sign
# out of a group of percent signs
|
(?=\${) # an expression
|
Expand Down
7 changes: 2 additions & 5 deletions mako/testing/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ def result_lines(result):
if x.strip() != ""
]


def result_raw_lines(result):
return [
x
for x in re.split(r"\r?\n", result)
if x.strip() != ""
]
return [x for x in re.split(r"\r?\n", result) if x.strip() != ""]


def make_path(
Expand Down
21 changes: 12 additions & 9 deletions test/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,14 @@ def test_percent_escape2(self):
{},
[
Text("% do something\n", (1, 2)),
Text("%% do something\nif <some condition>:\n ", (2, 2)),
Text(
"%% do something\nif <some condition>:\n ", (2, 2)
),
Text("%%% do something\n ", (4, 6)),
],
),
)

def test_percent_escape_with_control_block(self):
template = """
% for i in [1, 2, 3]:
Expand All @@ -241,13 +243,14 @@ def test_percent_escape_with_control_block(self):
TemplateNode(
{},
[
Text('\n', (1, 1)),
ControlLine('for', 'for i in [1, 2, 3]:', False, (2, 1)),
Text(' ', (3, 1)),
Text('% do something ', (3, 6)),
Expression('i', [], (3, 21)),
Text('\n', (3, 25)),
ControlLine('for', 'endfor', True, (4, 1))]
Text("\n", (1, 1)),
ControlLine("for", "for i in [1, 2, 3]:", False, (2, 1)),
Text(" ", (3, 1)),
Text("% do something ", (3, 6)),
Expression("i", [], (3, 21)),
Text("\n", (3, 25)),
ControlLine("for", "endfor", True, (4, 1)),
],
),
)

Expand Down
9 changes: 5 additions & 4 deletions test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from mako.testing.config import config
from mako.testing.fixtures import TemplateTest
from mako.testing.helpers import flatten_result
from mako.testing.helpers import result_lines, result_raw_lines
from mako.testing.helpers import result_lines
from mako.testing.helpers import result_raw_lines


class ctx:
Expand Down Expand Up @@ -1672,7 +1673,7 @@ def test_future_import(self):
class EscapeTest(TemplateTest):
def test_percent_escape(self):
t = Template(
"""%% do something
"""%% do something
%%% do something
if <some condition>:
%%%% do something
Expand All @@ -1684,10 +1685,10 @@ def test_percent_escape(self):
"if <some condition>:",
" %%% do something",
]

def test_percent_escape2(self):
t = Template(
"""
"""
% for i in [1, 2, 3]:
%% do something ${i}
% endfor
Expand Down

0 comments on commit ab8e747

Please sign in to comment.