Skip to content

Commit

Permalink
Enhance version_path_separator behaviour by adding a multiline option
Browse files Browse the repository at this point in the history
References: sqlalchemy#1509

Fix changelog ticket number

References: sqlalchemy#1509
  • Loading branch information
pristupa committed Jul 25, 2024
1 parent 6153e6b commit d2dca13
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion alembic/script/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def from_config(cls, config: Config) -> ScriptDirectory:
split_on_path = {
None: None,
"space": " ",
"newline": "\n",
"os": os.pathsep,
":": ":",
";": ";",
Expand All @@ -200,7 +201,7 @@ def from_config(cls, config: Config) -> ScriptDirectory:
raise ValueError(
"'%s' is not a valid value for "
"version_path_separator; "
"expected 'space', 'os', ':', ';'" % version_path_separator
"expected 'space', 'newline', 'os', ':', ';'" % version_path_separator
) from ke
else:
if split_char is None:
Expand Down
1 change: 1 addition & 0 deletions alembic/templates/async/alembic.ini.mako
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ prepend_sys_path = .
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
Expand Down
1 change: 1 addition & 0 deletions alembic/templates/generic/alembic.ini.mako
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ prepend_sys_path = .
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
Expand Down
1 change: 1 addition & 0 deletions alembic/templates/multidb/alembic.ini.mako
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ prepend_sys_path = .
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
Expand Down
11 changes: 7 additions & 4 deletions alembic/testing/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _ErrorContainer:


@contextlib.contextmanager
def _expect_raises(except_cls, msg=None, check_context=False):
def _expect_raises(except_cls, msg=None, check_context=False, text_exact=False):
ec = _ErrorContainer()
if check_context:
are_we_already_in_a_traceback = sys.exc_info()[0]
Expand All @@ -85,7 +85,10 @@ def _expect_raises(except_cls, msg=None, check_context=False):
ec.error = err
success = True
if msg is not None:
assert re.search(msg, str(err), re.UNICODE), f"{msg} !~ {err}"
if text_exact:
assert str(err) == msg, f"{msg} != {err}"
else:
assert re.search(msg, str(err), re.UNICODE), f"{msg} !~ {err}"
if check_context and not are_we_already_in_a_traceback:
_assert_proper_exception_context(err)
print(str(err).encode("utf-8"))
Expand All @@ -98,8 +101,8 @@ def expect_raises(except_cls, check_context=True):
return _expect_raises(except_cls, check_context=check_context)


def expect_raises_message(except_cls, msg, check_context=True):
return _expect_raises(except_cls, msg=msg, check_context=check_context)
def expect_raises_message(except_cls, msg, check_context=True, text_exact=False):
return _expect_raises(except_cls, msg=msg, check_context=check_context, text_exact=text_exact)


def eq_ignore_whitespace(a, b, msg=None):
Expand Down
6 changes: 6 additions & 0 deletions docs/build/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Changelog
:version: 1.13.3
:include_notes_from: unreleased

.. change::
:tags: feature, environment
:tickets: 1509

Enhance ``version_locations`` parsing to handle paths containing newlines.

.. changelog::
:version: 1.13.2
:released: June 26, 2024
Expand Down
1 change: 1 addition & 0 deletions docs/build/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ The file generated with the "generic" configuration looks like::
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
Expand Down
10 changes: 8 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ def test_attributes_constructor(self):
"/foo /bar",
["/foo", "/bar"],
),
(
"multiline string 1",
"newline",
"/foo\n/bar",
["/foo", "/bar"],
),
(
"Linux pathsep 1",
":",
Expand Down Expand Up @@ -171,7 +177,7 @@ def test_attributes_constructor(self):
"/foo|/bar",
ValueError(
"'|' is not a valid value for version_path_separator; "
"expected 'space', 'os', ':', ';'"
"expected 'space', 'newline', 'os', ':', ';'"
),
),
id_="iaaa",
Expand All @@ -188,7 +194,7 @@ def test_version_locations(self, separator, string_value, expected_result):
cfg.set_main_option("version_locations", string_value)

if isinstance(expected_result, ValueError):
with expect_raises_message(ValueError, expected_result.args[0]):
with expect_raises_message(ValueError, str(expected_result), text_exact=True):
ScriptDirectory.from_config(cfg)
else:
s = ScriptDirectory.from_config(cfg)
Expand Down

0 comments on commit d2dca13

Please sign in to comment.