]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Implement unit tests for prepend_sys_path_separator 1331/head
authorMike Werezak <mike.werezak@nrcan-rncan.gc.ca>
Wed, 2 Apr 2025 18:03:36 +0000 (14:03 -0400)
committerMike Werezak <mike.werezak@nrcan-rncan.gc.ca>
Wed, 2 Apr 2025 18:03:36 +0000 (14:03 -0400)
tests/test_config.py

index a98994c4d22914104f5fb90a8eb86eb468d62567..e295f585c5c66054a889a699f0d8d20518dd382a 100644 (file)
@@ -1,4 +1,5 @@
 import os
+import sys
 import tempfile
 
 from alembic import config
@@ -201,6 +202,104 @@ class ConfigTest(TestBase):
             s = ScriptDirectory.from_config(cfg)
             eq_(s.version_locations, expected_result)
 
+    @testing.combinations(
+        (
+            "legacy raw string 1",
+            None,
+            "/foo",
+            ["/foo"],
+        ),
+        (
+            "legacy raw string 2",
+            None,
+            "/foo /bar",
+            ["/foo", "/bar"],
+        ),
+        (
+            "legacy raw string 3",
+            "space",
+            "/foo",
+            ["/foo"],
+        ),
+        (
+            "legacy raw string 4",
+            "space",
+            "/foo /bar",
+            ["/foo", "/bar"],
+        ),
+        (
+            "multiline string 1",
+            "newline",
+            " /foo  \n/bar  ",
+            ["/foo", "/bar"],
+        ),
+        (
+            "Linux pathsep 1",
+            ":",
+            "/Project A",
+            ["/Project A"],
+        ),
+        (
+            "Linux pathsep 2",
+            ":",
+            "/Project A:/Project B",
+            ["/Project A", "/Project B"],
+        ),
+        (
+            "Windows pathsep 1",
+            ";",
+            r"C:\Project A",
+            [r"C:\Project A"],
+        ),
+        (
+            "Windows pathsep 2",
+            ";",
+            r"C:\Project A;C:\Project B",
+            [r"C:\Project A", r"C:\Project B"],
+        ),
+        (
+            "os pathsep",
+            "os",
+            r"path_number_one%(sep)spath_number_two%(sep)s"
+            % {"sep": os.pathsep},
+            [r"path_number_one", r"path_number_two"],
+        ),
+        (
+            "invalid pathsep 2",
+            "|",
+            "/foo|/bar",
+            ValueError(
+                "'|' is not a valid value for prepend_sys_path_separator; "
+                "expected 'space', 'newline', 'os', ':', ';'"
+            ),
+        ),
+        id_="iaaa",
+        argnames="separator, string_value, expected_result",
+    )
+    def test_prepend_sys_path_locations(self, separator, string_value, expected_result):
+        cfg = config.Config()
+        if separator is not None:
+            cfg.set_main_option(
+                "prepend_sys_path_separator",
+                separator,
+            )
+        cfg.set_main_option("script_location", tempfile.gettempdir())
+        cfg.set_main_option("prepend_sys_path", string_value)
+
+        if isinstance(expected_result, ValueError):
+            message = str(expected_result)
+            with expect_raises_message(ValueError, message, text_exact=True):
+                ScriptDirectory.from_config(cfg)
+        else:
+            restore_path = list(sys.path)
+            try:
+                sys.path.clear()
+
+                ScriptDirectory.from_config(cfg)
+                eq_(sys.path, expected_result)
+            finally:
+                sys.path = restore_path
+
 
 class StdoutOutputEncodingTest(TestBase):
     def test_plain(self):