|
1 | 1 | import os
|
| 2 | +import sys |
2 | 3 | import tempfile
|
3 | 4 |
|
4 | 5 | from alembic import config
|
@@ -201,6 +202,104 @@ def test_version_locations(self, separator, string_value, expected_result):
|
201 | 202 | s = ScriptDirectory.from_config(cfg)
|
202 | 203 | eq_(s.version_locations, expected_result)
|
203 | 204 |
|
| 205 | + @testing.combinations( |
| 206 | + ( |
| 207 | + "legacy raw string 1", |
| 208 | + None, |
| 209 | + "/foo", |
| 210 | + ["/foo"], |
| 211 | + ), |
| 212 | + ( |
| 213 | + "legacy raw string 2", |
| 214 | + None, |
| 215 | + "/foo /bar", |
| 216 | + ["/foo", "/bar"], |
| 217 | + ), |
| 218 | + ( |
| 219 | + "legacy raw string 3", |
| 220 | + "space", |
| 221 | + "/foo", |
| 222 | + ["/foo"], |
| 223 | + ), |
| 224 | + ( |
| 225 | + "legacy raw string 4", |
| 226 | + "space", |
| 227 | + "/foo /bar", |
| 228 | + ["/foo", "/bar"], |
| 229 | + ), |
| 230 | + ( |
| 231 | + "multiline string 1", |
| 232 | + "newline", |
| 233 | + " /foo \n/bar ", |
| 234 | + ["/foo", "/bar"], |
| 235 | + ), |
| 236 | + ( |
| 237 | + "Linux pathsep 1", |
| 238 | + ":", |
| 239 | + "/Project A", |
| 240 | + ["/Project A"], |
| 241 | + ), |
| 242 | + ( |
| 243 | + "Linux pathsep 2", |
| 244 | + ":", |
| 245 | + "/Project A:/Project B", |
| 246 | + ["/Project A", "/Project B"], |
| 247 | + ), |
| 248 | + ( |
| 249 | + "Windows pathsep 1", |
| 250 | + ";", |
| 251 | + r"C:\Project A", |
| 252 | + [r"C:\Project A"], |
| 253 | + ), |
| 254 | + ( |
| 255 | + "Windows pathsep 2", |
| 256 | + ";", |
| 257 | + r"C:\Project A;C:\Project B", |
| 258 | + [r"C:\Project A", r"C:\Project B"], |
| 259 | + ), |
| 260 | + ( |
| 261 | + "os pathsep", |
| 262 | + "os", |
| 263 | + r"path_number_one%(sep)spath_number_two%(sep)s" |
| 264 | + % {"sep": os.pathsep}, |
| 265 | + [r"path_number_one", r"path_number_two"], |
| 266 | + ), |
| 267 | + ( |
| 268 | + "invalid pathsep 2", |
| 269 | + "|", |
| 270 | + "/foo|/bar", |
| 271 | + ValueError( |
| 272 | + "'|' is not a valid value for prepend_sys_path_separator; " |
| 273 | + "expected 'space', 'newline', 'os', ':', ';'" |
| 274 | + ), |
| 275 | + ), |
| 276 | + id_="iaaa", |
| 277 | + argnames="separator, string_value, expected_result", |
| 278 | + ) |
| 279 | + def test_prepend_sys_path_locations(self, separator, string_value, expected_result): |
| 280 | + cfg = config.Config() |
| 281 | + if separator is not None: |
| 282 | + cfg.set_main_option( |
| 283 | + "prepend_sys_path_separator", |
| 284 | + separator, |
| 285 | + ) |
| 286 | + cfg.set_main_option("script_location", tempfile.gettempdir()) |
| 287 | + cfg.set_main_option("prepend_sys_path", string_value) |
| 288 | + |
| 289 | + if isinstance(expected_result, ValueError): |
| 290 | + message = str(expected_result) |
| 291 | + with expect_raises_message(ValueError, message, text_exact=True): |
| 292 | + ScriptDirectory.from_config(cfg) |
| 293 | + else: |
| 294 | + restore_path = list(sys.path) |
| 295 | + try: |
| 296 | + sys.path.clear() |
| 297 | + |
| 298 | + ScriptDirectory.from_config(cfg) |
| 299 | + eq_(sys.path, expected_result) |
| 300 | + finally: |
| 301 | + sys.path = restore_path |
| 302 | + |
204 | 303 |
|
205 | 304 | class StdoutOutputEncodingTest(TestBase):
|
206 | 305 | def test_plain(self):
|
|
0 commit comments