From 0ea6f4118b9e503da793f445a26c1c4e865f87a4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 19 Sep 2019 16:19:25 -0400 Subject: [PATCH] Add test for normalization of script_dir, version_locations Ensure ScriptDirectory normalizes paths. Change-Id: I9feea25e03eb3037321341776502619be413080e References: #590 --- tests/test_script_production.py | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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:", + ], + ) -- 2.47.2