Loading lib/galaxy/model/migrations/scripts.py +9 −2 Original line number Diff line number Diff line Loading @@ -120,7 +120,13 @@ class LegacyScripts: def __init__(self, argv: List[str], cwd: Optional[str] = None) -> None: self.argv = argv self.cwd = cwd or os.getcwd() self.database = self.DEFAULT_DB_ARG self._database = None # Do not assign default value: `None` means we don't know yet. @property def database(self): if self._database is None: raise LegacyScriptsException("Attempt to access identifier of database before processing the script arguments") return self._database def run(self) -> None: """ Loading @@ -147,8 +153,9 @@ class LegacyScripts: If last argument is a valid database name, pop and assign it; otherwise assign default. """ arg = self.argv[-1] self._database = self.DEFAULT_DB_ARG if arg in ["galaxy", "install"]: self.database = self.argv.pop() self._database = self.argv.pop() def rename_config_argument(self) -> None: """ Loading test/unit/data/model/migrations/test_scripts.py +12 −0 Original line number Diff line number Diff line Loading @@ -145,3 +145,15 @@ class TestLegacyScripts: argv = ["caller", "--alembic-config", "path-to-alembic", "downgrade"] with pytest.raises(LegacyScriptsException): LegacyScripts(argv).convert_args() def test_access_database_id(self): db = "galaxy" argv = ["caller", "--alembic-config", "path-to-alembic", "upgrade", db] ls = LegacyScripts(argv) ls.run() assert ls.database == db def test_access_database_id_before_processing_script_args_raises_error(self): argv = ["caller", "--alembic-config", "path-to-alembic", "upgrade"] with pytest.raises(LegacyScriptsException): LegacyScripts(argv).database Loading
lib/galaxy/model/migrations/scripts.py +9 −2 Original line number Diff line number Diff line Loading @@ -120,7 +120,13 @@ class LegacyScripts: def __init__(self, argv: List[str], cwd: Optional[str] = None) -> None: self.argv = argv self.cwd = cwd or os.getcwd() self.database = self.DEFAULT_DB_ARG self._database = None # Do not assign default value: `None` means we don't know yet. @property def database(self): if self._database is None: raise LegacyScriptsException("Attempt to access identifier of database before processing the script arguments") return self._database def run(self) -> None: """ Loading @@ -147,8 +153,9 @@ class LegacyScripts: If last argument is a valid database name, pop and assign it; otherwise assign default. """ arg = self.argv[-1] self._database = self.DEFAULT_DB_ARG if arg in ["galaxy", "install"]: self.database = self.argv.pop() self._database = self.argv.pop() def rename_config_argument(self) -> None: """ Loading
test/unit/data/model/migrations/test_scripts.py +12 −0 Original line number Diff line number Diff line Loading @@ -145,3 +145,15 @@ class TestLegacyScripts: argv = ["caller", "--alembic-config", "path-to-alembic", "downgrade"] with pytest.raises(LegacyScriptsException): LegacyScripts(argv).convert_args() def test_access_database_id(self): db = "galaxy" argv = ["caller", "--alembic-config", "path-to-alembic", "upgrade", db] ls = LegacyScripts(argv) ls.run() assert ls.database == db def test_access_database_id_before_processing_script_args_raises_error(self): argv = ["caller", "--alembic-config", "path-to-alembic", "upgrade"] with pytest.raises(LegacyScriptsException): LegacyScripts(argv).database