def test_malformatted_toml_raises_error(self, testdir): pyproject = Path("pyproject.toml") pyproject.write_text("foo:bar,baz\n{dict}&&&&") default_map = dict() ctx = click.Context(click.Command("snakefmt"), default_map=default_map) param = mock.MagicMock() value = None with pytest.raises(click.FileError): read_snakefmt_defaults_from_pyproject_toml(ctx, param, value)
def test_no_value_passed_and_no_pyproject_changes_nothing(self, testdir): default_map = dict() ctx = click.Context(click.Command("snakefmt"), default_map=default_map) param = mock.MagicMock() value = None return_val = read_snakefmt_defaults_from_pyproject_toml(ctx, param, value) assert return_val is None actual_default_map = ctx.default_map expected_default_map = dict() assert actual_default_map == expected_default_map
def test_pyproject_present_but_empty_changes_nothing_returns_pyproject_path( self, testdir): pyproject = Path("pyproject.toml") pyproject.touch() default_map = dict() ctx = click.Context(click.Command("snakefmt"), default_map=default_map) param = mock.MagicMock() value = None actual_config_path = read_snakefmt_defaults_from_pyproject_toml( ctx, param, value) expected_config_path = str(pyproject) assert actual_config_path == expected_config_path assert ctx.default_map == dict()
def test_value_passed_reads_from_path(self, testdir): pyproject = Path("snakefmt.toml") pyproject.write_text("[tool.snakefmt]\nfoo = true") default_map = dict() ctx = click.Context(click.Command("snakefmt"), default_map=default_map) param = mock.MagicMock() actual_config_path = read_snakefmt_defaults_from_pyproject_toml( ctx, param, value=str(pyproject)) expected_config_path = str(pyproject) assert actual_config_path == expected_config_path actual_default_map = ctx.default_map expected_default_map = dict(foo=True) assert actual_default_map == expected_default_map
def test_no_value_passed_and_pyproject_present_changes_default_line_length( self, testdir): pyproject = Path("pyproject.toml") pyproject.write_text("[tool.snakefmt]\nline_length = 4") default_map = dict(line_length=88) ctx = click.Context(click.Command("snakefmt"), default_map=default_map) param = mock.MagicMock() value = None actual_config_path = read_snakefmt_defaults_from_pyproject_toml( ctx, param, value) expected_config_path = str(pyproject) assert actual_config_path == expected_config_path actual_default_map = ctx.default_map expected_default_map = dict(line_length=4) assert actual_default_map == expected_default_map
def test_value_passed_in_overrides_pyproject(self, testdir): snakefmt_config = Path("snakefmt.toml") snakefmt_config.write_text("[tool.snakefmt]\nfoo = true") pyproject = Path("pyproject.toml") pyproject.write_text("[tool.snakefmt]\n\nfoo = false\nline_length = 90") default_map = dict() ctx = click.Context(click.Command("snakefmt"), default_map=default_map) param = mock.MagicMock() value = str(snakefmt_config) actual_config_path = read_snakefmt_defaults_from_pyproject_toml( ctx, param, value ) expected_config_path = str(snakefmt_config) assert actual_config_path == expected_config_path actual_default_map = ctx.default_map expected_default_map = dict(foo=True) assert actual_default_map == expected_default_map