Skip to content

Commit

Permalink
#90 fix type error when using --config-file
Browse files Browse the repository at this point in the history
  • Loading branch information
tbcvl committed Oct 30, 2020
1 parent 361864c commit e0f7f9e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion septentrion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def split_envvar_value(self, rv: str):
callback=load_config,
help="Config file to use (env: SEPTENTRION_CONFIG_FILE) "
f"[default: {' or '.join(str(p) for p in configuration.ALL_CONFIGURATION_FILES)}]",
type=click.File("rb"),
type=click.File("r"),
)
@click.version_option(__version__, "-V", "--version", prog_name="septentrion")
@click.option(
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pathlib

from septentrion import __main__, configuration
from septentrion import db as db_module

Expand Down Expand Up @@ -59,3 +61,15 @@ def test_current_database_state(cli_runner, db):
assert "Version 1.1" in result.output
assert "Applying 1.1-index-ddl.sql ..." in result.output
assert "Applied 1.1-index-ddl.sql" in result.output


def test_configuration_file_from_cli(cli_runner, temporary_directory, mocker):
mocker.patch("septentrion.core.describe_migration_plan")
mocker.patch("septentrion.db.create_table")
path = pathlib.Path(__file__).parents[2] / "tests/test_data/config_file.ini"
result = cli_runner.invoke(
__main__.main,
[f"--config-file={path}", "show-migrations"],
catch_exceptions=False,
)
assert result.exit_code == 0, (result.output,)
9 changes: 9 additions & 0 deletions tests/test_data/config_file.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[septentrion]
schema_version=20.10
target_version=20.11
schema_template=schema_{}.sql
before_schema_file=
roles.sql
after_schema_file=
after_schemas.sql
fixtures_template=fixtures_{}.sql
7 changes: 7 additions & 0 deletions tests/unit/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def test_load_configuration_files_value(caplog, conf, expected, has_warning):
)


def test_load_configuration_files_value_from_file(caplog, mocker):
with open(
pathlib.Path(__file__).parents[2] / "tests/test_data/config_file.ini", "r"
) as f:
configuration.load_configuration_files(value=f)


@pytest.mark.parametrize(
"conf, filename, expected, has_warning",
[
Expand Down

0 comments on commit e0f7f9e

Please sign in to comment.