Skip to content

Commit

Permalink
feat: グループ指定オプションの追加と関連テストの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarina committed Feb 9, 2025
1 parent 6c9519a commit b73ae89
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.0] - 2024-02-10

### Added
- New `-g/--group` option to build only specified groups
```bash
# Build only development group
pydantic_config_builder -g development

# Build multiple groups
pydantic_config_builder -g development -g staging
```

## [0.4.0] - 2024-02-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion pydantic_config_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
A tool to build YAML configurations by merging multiple files
"""

__version__ = "0.4.0"
__version__ = "0.5.0"
4 changes: 3 additions & 1 deletion pydantic_config_builder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def main(config: Path | None, verbose: bool, group: tuple[str]) -> None:
click.echo(f"Filtering groups: {', '.join(group)}")
filtered_builds = {k: v for k, v in config_model.builds.items() if k in group}
if not filtered_builds:
raise click.ClickException(f"None of the specified groups {group} exist in configuration")
raise click.ClickException(
f"None of the specified groups {group} exist in configuration"
)
config_model = ConfigModel(builds=filtered_builds)

# Build configurations
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pydantic-config-builder"
version = "0.4.0"
version = "0.5.0"
description = "A tool to build YAML configurations by merging multiple files"
authors = ["kiarina <kiarinadawa@gmail.com>"]
license = "MIT"
Expand Down
79 changes: 79 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,82 @@ def test_cli_invalid_config(temp_dir):
result = runner.invoke(main, ["-c", str(invalid_config)])
assert result.exit_code != 0
assert "Failed to load configuration file" in result.output


def test_cli_group_filter(temp_dir):
"""Test CLI with group filter."""
# Create config file with multiple groups
config = temp_dir / "pydantic_config_builder.yml"
config.write_text(
yaml.dump(
{
"group1": {
"input": ["base.yaml"],
"output": ["output1.yaml"],
},
"group2": {
"input": ["base.yaml"],
"output": ["output2.yaml"],
},
}
)
)

# Test building only group1
runner = CliRunner()
result = runner.invoke(main, ["-c", str(config), "-g", "group1"])
assert result.exit_code == 0
assert (temp_dir / "output1.yaml").exists()
assert not (temp_dir / "output2.yaml").exists()


def test_cli_multiple_groups(temp_dir):
"""Test CLI with multiple group filters."""
# Create config file with multiple groups
config = temp_dir / "pydantic_config_builder.yml"
config.write_text(
yaml.dump(
{
"group1": {
"input": ["base.yaml"],
"output": ["output1.yaml"],
},
"group2": {
"input": ["base.yaml"],
"output": ["output2.yaml"],
},
"group3": {
"input": ["base.yaml"],
"output": ["output3.yaml"],
},
}
)
)

# Test building group1 and group2
runner = CliRunner()
result = runner.invoke(main, ["-c", str(config), "-g", "group1", "-g", "group2"])
assert result.exit_code == 0
assert (temp_dir / "output1.yaml").exists()
assert (temp_dir / "output2.yaml").exists()
assert not (temp_dir / "output3.yaml").exists()


def test_cli_nonexistent_group(temp_dir):
"""Test CLI with nonexistent group."""
config = temp_dir / "pydantic_config_builder.yml"
config.write_text(
yaml.dump(
{
"group1": {
"input": ["base.yaml"],
"output": ["output1.yaml"],
}
}
)
)

runner = CliRunner()
result = runner.invoke(main, ["-c", str(config), "-g", "nonexistent"])
assert result.exit_code != 0
assert "None of the specified groups" in result.output

0 comments on commit b73ae89

Please sign in to comment.