Skip to content

Commit

Permalink
Ensure env-vars are handled as strings
Browse files Browse the repository at this point in the history
This avoids suprocess.run to fail ambiguously due to non-string values inherited from configuration
(like postgresql' port number). Refs #83.
  • Loading branch information
ThomasEcuer committed Aug 3, 2020
1 parent deb8c8c commit c0f7177
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion septentrion/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c0f7177

Please sign in to comment.