From: Mike Bayer Date: Thu, 19 Sep 2019 20:19:25 +0000 (-0400) Subject: Add test for normalization of script_dir, version_locations X-Git-Tag: rel_1_2_0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ea6f4118b9e503da793f445a26c1c4e865f87a4;p=thirdparty%2Fsqlalchemy%2Falembic.git Add test for normalization of script_dir, version_locations Ensure ScriptDirectory normalizes paths. Change-Id: I9feea25e03eb3037321341776502619be413080e References: #590 --- diff --git a/tests/test_script_production.py b/tests/test_script_production.py index 220793c8..802a256f 100644 --- a/tests/test_script_production.py +++ b/tests/test_script_production.py @@ -1255,3 +1255,56 @@ def downgrade(): [rev.revision for rev in script.walk_revisions()], [self.model1, self.model2, self.model3], ) + + +class NormPathTest(TestBase): + def setUp(self): + self.env = staging_env() + + def test_script_location(self): + config = _no_sql_testing_config() + + script = ScriptDirectory.from_config(config) + + def normpath(path): + return path.replace("/", ":NORM:") + + normpath = mock.Mock(side_effect=normpath) + with mock.patch("os.path.normpath", normpath): + eq_( + script._version_locations, + ( + ":NORM:home:NORM:classic:NORM:dev:NORM:alembic" + ":NORM:scratch:NORM:scripts:NORM:versions", + ), + ) + + eq_( + script.versions, + ":NORM:home:NORM:classic:NORM:dev:NORM:alembic:NORM:scratch:" + "NORM:scripts:NORM:versions", + ) + + eq_(script.dir, "scratch/scripts") + + def test_script_location_muliple(self): + config = _multi_dir_testing_config() + + script = ScriptDirectory.from_config(config) + + def normpath(path): + return path.replace("/", ":NORM:") + + normpath = mock.Mock(side_effect=normpath) + with mock.patch("os.path.normpath", normpath): + eq_( + script._version_locations, + [ + ":NORM:home:NORM:classic:NORM:dev:NORM:alembic" + ":NORM:scratch:NORM:model1:NORM:", + ":NORM:home:NORM:classic:NORM:dev:NORM:alembic" + ":NORM:scratch:NORM:model2:NORM:", + ":NORM:home:NORM:classic:NORM:dev:NORM:alembic" + ":NORM:scratch:NORM:model3:NORM:", + ], + )