Skip to content

Commit

Permalink
Add title_format tests and drop a line (#299)
Browse files Browse the repository at this point in the history
* Add title_format tests and drop a line

* flake8

* Add 299.misc.rst

* Add test docstrings

* update test

* Update test_build.py

* Update test_build.py

* remove whitespace from a blank line

* Apply suggestions from code review

Co-authored-by: Adi Roiban <[email protected]>

* fixup

* expound case in test docstring

* add brief explanation of title_format outside the example

Co-authored-by: Adi Roiban <[email protected]>
  • Loading branch information
altendky and adiroiban authored Dec 20, 2020
1 parent 5f37912 commit 46c3157
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ Towncrier has the following global options, which can be specified in the toml f
If a single file is used, the content of that file gets overwritten each time.

If ``title_format`` is unspecified or an empty string, the default format will be used.
If set to ``false``, no title will be created.
This can be useful if the specified template creates the title itself.

Furthermore, you can add your own fragment types using:

.. code-block:: ini
Expand Down
Empty file.
108 changes: 108 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,111 @@ def test_bullet_points_false(self):
"""
).lstrip(),
)

def test_title_format_custom(self):
"""
A non-empty title format adds the specified title.
"""
runner = CliRunner()

with runner.isolated_filesystem():
with open("pyproject.toml", "w") as f:
f.write(dedent("""\
[tool.towncrier]
package = "foo"
title_format = "[{project_date}] CUSTOM RELEASE for {name} version {version}"
"""))
os.mkdir("foo")
os.mkdir("foo/newsfragments")
with open("foo/newsfragments/123.feature", "w") as f:
f.write("Adds levitation")
# Towncrier ignores .rst extension
with open("foo/newsfragments/124.feature.rst", "w") as f:
f.write("Extends levitation")

result = runner.invoke(
_main,
[
"--name",
"FooBarBaz",
"--version",
"7.8.9",
"--date",
"20-01-2001",
"--draft",
],
)

expected_output = dedent("""\
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.
[20-01-2001] CUSTOM RELEASE for FooBarBaz version 7.8.9
=======================================================
Features
--------
- Adds levitation (#123)
- Extends levitation (#124)
""")

self.assertEqual(0, result.exit_code)
self.assertEqual(expected_output, result.output)

def test_title_format_false(self):
"""
Setting the title format to false disables the explicit title. This
would be used, for example, when the template creates the title itself.
"""
runner = CliRunner()

with runner.isolated_filesystem():
with open("pyproject.toml", "w") as f:
f.write(dedent("""\
[tool.towncrier]
package = "foo"
title_format = false
"""))
os.mkdir("foo")
os.mkdir("foo/newsfragments")
# Towncrier ignores .rst extension
with open("foo/newsfragments/124.feature.rst", "w") as f:
f.write("Extends levitation")

result = runner.invoke(
_main,
[
"--name",
"FooBarBaz",
"--version",
"7.8.9",
"--date",
"20-01-2001",
"--draft",
],
)

expected_output = dedent("""\
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.
FooBarBaz 7.8.9 (20-01-2001)
============================
Features
--------
- Extends levitation (#124)
""")

self.assertEqual(0, result.exit_code)
self.assertEqual(expected_output, result.output)

0 comments on commit 46c3157

Please sign in to comment.