From c0f71776792ec6c858083d212c6c7b70d7fba400 Mon Sep 17 00:00:00 2001 From: Thomas Ecuer Date: Mon, 3 Aug 2020 18:00:06 +0200 Subject: [PATCH] Ensure env-vars are handled as strings This avoids suprocess.run to fail ambiguously due to non-string values inherited from configuration (like postgresql' port number). Refs #83. --- septentrion/runner.py | 2 +- tests/integration/test_runner.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/septentrion/runner.py b/septentrion/runner.py index 3c12c7d..1a65fd8 100644 --- a/septentrion/runner.py +++ b/septentrion/runner.py @@ -38,7 +38,7 @@ def _env(self): "PGUSER": self.settings.USERNAME, "PGPASSWORD": self.settings.PASSWORD, } - return {key: value for key, value in environment.items() if value} + return {key: str(value) for key, value in environment.items() if value} def _run_simple(self): diff --git a/tests/integration/test_runner.py b/tests/integration/test_runner.py index c6aa5ca..fba4c38 100644 --- a/tests/integration/test_runner.py +++ b/tests/integration/test_runner.py @@ -58,6 +58,18 @@ def test_run_psql_not_found(run_script, env): ) +def test_run_integer_in_settings(db, settings_factory, env, tmp_path): + settings = settings_factory(**db) + # settings are noew stringified to prevent subprocess.run + # crashing while building the appropriate command line. + settings.PORT = 5432 + path = tmp_path / "script.sql" + path.write_text("SELECT 1;") + with io.open(path, "r", encoding="utf8") as f: + script = Script(settings, f, path) + script.run() + + def test_run_with_meta_loop(db, settings_factory, run_script): settings = settings_factory(**db)