Skip to content

Commit

Permalink
Extend tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Feb 4, 2024
1 parent 7378730 commit bfa30ab
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/antsibull_changelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,12 @@ def __init__(

self.output_formats = set()
for extension in self.config.get("output_formats", ["rst"]):
self.output_formats.add(TextFormat.from_extension(extension))
try:
self.output_formats.add(TextFormat.from_extension(extension))
except ValueError as exc:
raise ChangelogError(
f"Found unknown extension in output_formats: {exc}"
) from exc

self._validate_config(ignore_is_other_project)

Expand Down
59 changes: 59 additions & 0 deletions tests/functional/test_changelog_basic_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ def test_changelog_release_empty( # pylint: disable=redefined-outer-name
assert collection_changelog.run_tool("generate", ["-v", "--refresh"]) == 0
assert collection_changelog.diff().unchanged

assert (
collection_changelog.run_tool(
"generate", ["-v", "--refresh", "--output", "CHANGELOG.md"]
)
== 5
)
assert collection_changelog.diff().unchanged

assert (
collection_changelog.run_tool(
"release", ["-v", "--codename", "primetime", "--date", "2020-01-03"]
Expand Down Expand Up @@ -1385,6 +1393,57 @@ def test_changelog_release_simple( # pylint: disable=redefined-outer-name
"""
)

# Generate changelog for 1.0.0 only as MD
assert (
collection_changelog.run_tool(
"generate",
[
"-vvv",
"--output",
"changelog-1.0.0.md",
"--output-format",
"md",
"--only-latest",
"1.0.0",
],
)
== 0
)

diff = collection_changelog.diff()
assert diff.added_dirs == []
assert diff.added_files == ["changelog-1.0.0.md"]
assert diff.removed_dirs == []
assert diff.removed_files == []
assert diff.changed_files == []

assert diff.file_contents["changelog-1.0.0.md"].decode("utf-8") == (
r"""<a id="release-summary"></a>
## Release Summary
This is the first proper release\.
<a id="minor-changes"></a>
## Minor Changes
* baz lookup \- no longer ignores the <code>bar</code> option\.
* test \- has a new option <code>foo</code>\.
<a id="new-plugins"></a>
## New Plugins
<a id="lookup"></a>
### Lookup
* acme\.test\.bar \- A foo\_bar lookup
<a id="new-modules"></a>
## New Modules
* acme\.test\.test \- This is a TEST module
"""
)


def test_changelog_release_simple_no_galaxy( # pylint: disable=redefined-outer-name
collection_changelog,
Expand Down
8 changes: 8 additions & 0 deletions tests/units/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,11 @@ def test_collection_details(tmp_path):
assert details.get_name() == "asdf"
assert details.get_version() == "1.0.0"
assert details.get_flatmap() is False


def test_config_loading_bad_output_format(ansible_config_path):
ansible_config_path.write_text("output_formats: [foobar]")
paths = PathsConfig.detect()
collection_details = CollectionDetails(paths)
with pytest.raises(ChangelogError):
ChangelogConfig.load(paths, collection_details)

0 comments on commit bfa30ab

Please sign in to comment.