Skip to content

Commit 537fe64

Browse files
committed
Fix spelling.
1 parent d1aaa4c commit 537fe64

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/pytsql/tsql.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ def _process_replacement(line: str, parameters: dict[str, Any]) -> str:
4040
return new_line
4141

4242

43-
def _parametrize(
43+
def _parameterize(
4444
source: str,
4545
parameters: dict[str, Any],
4646
start: str = _REPLACE_START,
4747
end: str = _REPLACE_END,
4848
) -> str:
49-
"""Replace all {start} and {end} statements, i.e. parametrizes the SQL script.
49+
"""Replace all {start} and {end} statements, i.e. parameterizes the SQL script.
5050
5151
Parameters
5252
----------
@@ -57,19 +57,19 @@ def _parametrize(
5757
the input source code, separated by newlines, with parameter replacements
5858
"""
5959

60-
def parametrization_replacer(match: Match) -> str:
60+
def parameterization_replacer(match: Match) -> str:
6161
return _process_replacement(match.group(1), parameters)
6262

63-
# The pattern matches all parametrization patterns, including those within a string literal.
63+
# The pattern matches all parameterization patterns, including those within a string literal.
6464
pattern = re.compile(
6565
rf"/\* {re.escape(start)} \*/.*?/\* {re.escape(end)}(.*?) \*/",
6666
re.DOTALL | re.MULTILINE,
6767
)
6868

69-
parametrized = re.sub(pattern, parametrization_replacer, source)
69+
parameterized = re.sub(pattern, parameterization_replacer, source)
7070

7171
non_empty_stripped_lines = [
72-
x.strip() for x in parametrized.split("\n") if x.strip() != ""
72+
x.strip() for x in parameterized.split("\n") if x.strip() != ""
7373
]
7474

7575
return "\n".join(non_empty_stripped_lines)
@@ -235,13 +235,13 @@ def executes(
235235
None
236236
237237
"""
238-
parametrized_code = _parametrize(code, parameters) if parameters else code
238+
parameterized_code = _parameterize(code, parameters) if parameters else code
239239
with engine.connect().execution_options(isolation_level="AUTOCOMMIT") as conn:
240240
# Since the prints table is a temporary one, it will be local to the connection and it will be dropped once the
241241
# connection is closed. Caveat: sqlalchemy engines can pool connections, so we still have to drop it preemtively.
242242
conn.execute(_text(f"DROP TABLE IF EXISTS {_PRINTS_TABLE}"))
243243
conn.execute(_text(f"CREATE TABLE {_PRINTS_TABLE} (p NVARCHAR(4000))"))
244-
for batch in _split(parametrized_code, isolate_top_level_statements):
244+
for batch in _split(parameterized_code, isolate_top_level_statements):
245245
sql_batch = _text(batch)
246246
conn.execute(sql_batch)
247247
_fetch_and_clear_prints(conn)

tests/unit/test_parametrize.py tests/unit/test_parameterize.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from pytsql.tsql import _parametrize
3+
from pytsql.tsql import _parameterize
44

55

66
def test_replace_comment():
@@ -14,7 +14,7 @@ def test_replace_comment():
1414
/* </replace> select {alpha},b,{charlie} from x */
1515
""" # noqa: W291
1616
expected = """select first,b,second from x"""
17-
assert _parametrize(seed, {"alpha": "first", "charlie": "second"}) == expected
17+
assert _parameterize(seed, {"alpha": "first", "charlie": "second"}) == expected
1818

1919

2020
def test_replace_comment_second():
@@ -26,7 +26,7 @@ def test_replace_comment_second():
2626
"""
2727
expected = """USE master;
2828
select * from [master].[dbo].[new_table];"""
29-
assert _parametrize(seed, {"tableName": "new_table"}) == expected
29+
assert _parameterize(seed, {"tableName": "new_table"}) == expected
3030

3131

3232
def test_replace_comment_int():
@@ -38,7 +38,7 @@ def test_replace_comment_int():
3838
"""
3939
expected = """USE master;
4040
select top 1337 * from [master].[dbo].[table];"""
41-
assert _parametrize(seed, {"n_rows": 1337}) == expected
41+
assert _parameterize(seed, {"n_rows": 1337}) == expected
4242

4343

4444
def test_replace_comment_class():
@@ -57,7 +57,7 @@ def __str__(self):
5757
"""
5858
expected = """USE master;
5959
select * from master.dbo.table;"""
60-
assert _parametrize(seed, {"table_qualifier": MyClass("table")}) == expected
60+
assert _parameterize(seed, {"table_qualifier": MyClass("table")}) == expected
6161

6262

6363
def test_none_replacement():
@@ -68,7 +68,7 @@ def test_none_replacement():
6868
/* </replace> select * from [master].[dbo].[{tableName}]; */
6969
"""
7070
with pytest.raises(ValueError):
71-
_parametrize(seed, {"tableName": None})
71+
_parameterize(seed, {"tableName": None})
7272

7373

7474
def test_double_replacement():
@@ -84,7 +84,7 @@ def test_double_replacement():
8484
FROM dbo.new_table t1
8585
JOIN dbo.new_table t2
8686
ON t1.id = t2.id;""" # noqa: W291
87-
assert _parametrize(seed, {"tableName": "new_table"}) == expected
87+
assert _parameterize(seed, {"tableName": "new_table"}) == expected
8888

8989

9090
def test_multiline_replacement():
@@ -96,7 +96,7 @@ def test_multiline_replacement():
9696
"""
9797
expected = """USE master;
9898
select * from [master].[dbo].[new_table];"""
99-
assert _parametrize(seed, {"tableName": "new_table"}) == expected
99+
assert _parameterize(seed, {"tableName": "new_table"}) == expected
100100

101101

102102
def test_multi_multiline_replacements():
@@ -115,7 +115,7 @@ def test_multi_multiline_replacements():
115115
USE newTable;
116116
select * from [master].[dbo].[second_table];""" # noqa: W291
117117
assert (
118-
_parametrize(seed, {"tableName": "new_table", "otherTable": "second_table"})
118+
_parameterize(seed, {"tableName": "new_table", "otherTable": "second_table"})
119119
== expected
120120
)
121121

@@ -127,7 +127,7 @@ def test_regular_comment_stays():
127127
"""
128128
expected = """USE master; /* this is a regular comment */
129129
select * from [master].[dbo].[table];"""
130-
assert _parametrize(seed, {"branch": "new_master"}) == expected
130+
assert _parameterize(seed, {"branch": "new_master"}) == expected
131131

132132

133133
def test_unknown_parameter_exception():
@@ -138,15 +138,15 @@ def test_unknown_parameter_exception():
138138
select * from [master].[dbo].[table];
139139
"""
140140
with pytest.raises(KeyError):
141-
_parametrize(seed, {"key": "value"})
141+
_parameterize(seed, {"key": "value"})
142142

143143

144144
def test_same_line_replacement():
145145
seed = """
146146
select a,b,/* <replace> */c/* </replace>{otherC} */ from x
147147
"""
148148
expected = """select a,b,newC from x"""
149-
assert _parametrize(seed, {"otherC": "newC"}) == expected
149+
assert _parameterize(seed, {"otherC": "newC"}) == expected
150150

151151

152152
def test_multi_same_line_replacements():
@@ -156,12 +156,12 @@ def test_multi_same_line_replacements():
156156
"""
157157
expected = """SELECT newA, newB
158158
FROM table;"""
159-
assert _parametrize(seed, {"newA": "newA", "newB": "newB"}) == expected
159+
assert _parameterize(seed, {"newA": "newA", "newB": "newB"}) == expected
160160

161161

162162
def test_replace_in_string_literal():
163163
seed = """SELECT '/* <replace> */a/* </replace>{newA} */'"""
164-
assert _parametrize(seed, {"newA": "newA"}) == "SELECT 'newA'"
164+
assert _parameterize(seed, {"newA": "newA"}) == "SELECT 'newA'"
165165

166166

167167
def test_custom_replace_keywords():
@@ -170,7 +170,7 @@ def test_custom_replace_keywords():
170170
"""
171171
expected = """SELECT a,/* <replace> */b/* </replace>{otherB} */,newC FROM x"""
172172
assert (
173-
_parametrize(
173+
_parameterize(
174174
seed,
175175
{"otherB": "newB", "otherC": "newC"},
176176
start="*repl_start*",

0 commit comments

Comments
 (0)