Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge with primary schema #4

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[merge-with-primary-schema] Added test for merged schemas.
nixjdm committed Feb 7, 2018
commit 90edb8b2feaea3de09fd535638683fabbdeaa600
59 changes: 59 additions & 0 deletions tests/functional/test_basics.py
Original file line number Diff line number Diff line change
@@ -92,6 +92,30 @@ class ConfigFileProcessor3(ConfigFileReader):
]


# -----------------------------------------------------------------------------
# TEST CANDIDATE 4: With config_section_schemas_to_merge_with_primary
# -----------------------------------------------------------------------------
@assign_param_names
class ConfigSectionSchema4(object):

@matches_section("hello4")
class Hello(SectionSchema):
first_name = Param(type=str)

@matches_section("hellomore4")
class HelloMore(SectionSchema):
last_name = Param(type=str)

class ConfigFileProcessor4(ConfigFileReader):
config_files = ["hello4.ini"]
config_section_schemas_to_merge_with_primary = [
ConfigSectionSchema4.HelloMore,
]
config_section_schemas = [
ConfigSectionSchema4.Hello,
] + config_section_schemas_to_merge_with_primary


# -----------------------------------------------------------------------------
# TEST SUITE
# -----------------------------------------------------------------------------
@@ -378,3 +402,38 @@ def test_config_searchpath__param_from_primary_file_overrides_secondary(self,
config = ConfigFileProcessor3.read_config()
assert config == dict(name="Alice")
assert config["name"] == "Alice" # -- FROM: config_file1 (prefered)

class TestCandidate4(object):

def test_configfile__use_default_section_to_storage_name_mapping(self,
cli_runner_isolated):
assert ConfigFileProcessor4.config_files[0] == "hello4.ini"
assert not os.path.exists("hello4.cfg")
CONFIG_FILE_CONTENTS = """
[hello4]
first_name = Alice

[hellomore4]
last_name = Doe
"""
write_configfile_with_contents("hello4.ini", CONFIG_FILE_CONTENTS)
assert os.path.exists("hello4.ini")

CONTEXT_SETTINGS = dict(default_map=ConfigFileProcessor4.read_config())

@click.command(context_settings=CONTEXT_SETTINGS)
@click.option("-n", "--first-name", default="__CMDLINE__")
@click.option("-n", "--last-name", default="__CMDLINE__")
@click.pass_context
def hello4(ctx, first_name, last_name):
click.echo("Hello4 first_name = %s" % first_name)
click.echo("Hello4 last_name = %s" % last_name)

assert os.path.exists("hello4.ini")
result = cli_runner_isolated.invoke(hello4)
expected_output = """\
Hello4 first_name = Alice
Hello4 last_name = Doe
"""
assert result.output == expected_output
assert result.exit_code == 0