-
Notifications
You must be signed in to change notification settings - Fork 123
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
Allowed fallback usage of project.name
for name
and package
if pyproject.toml exists
#687
Changes from all commits
205da9c
8f8c9f5
7eda8b3
45cc1bf
afe1f42
cfdb1f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
When used with an `pyproject.toml` file, when no explicit values are | ||
defined for [tool.towncrier.name|package] they will now fallback to | ||
the value of [project.name]. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,8 @@ | |||||
|
||||||
import os | ||||||
|
||||||
from textwrap import dedent | ||||||
|
||||||
from click.testing import CliRunner | ||||||
from twisted.trial.unittest import TestCase | ||||||
|
||||||
|
@@ -112,22 +114,6 @@ def test_template_extended(self): | |||||
|
||||||
self.assertEqual(config.template, ("towncrier.templates", "default.rst")) | ||||||
|
||||||
def test_missing(self): | ||||||
""" | ||||||
If the config file doesn't have the correct toml key, we error. | ||||||
""" | ||||||
project_dir = self.mktemp_project( | ||||||
pyproject_toml=""" | ||||||
[something.else] | ||||||
blah='baz' | ||||||
""" | ||||||
) | ||||||
|
||||||
with self.assertRaises(ConfigError) as e: | ||||||
load_config(project_dir) | ||||||
|
||||||
self.assertEqual(e.exception.failing_option, "all") | ||||||
|
||||||
def test_incorrect_single_file(self): | ||||||
""" | ||||||
single_file must be a bool. | ||||||
|
@@ -194,6 +180,93 @@ def test_towncrier_toml_preferred(self): | |||||
config = load_config(project_dir) | ||||||
self.assertEqual(config.package, "a") | ||||||
|
||||||
def test_pyproject_only_pyproject_toml(self): | ||||||
""" | ||||||
Towncrier will fallback to the [project.name] value in pyproject.toml. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a small suggestion to help understand the scope of this test.
Suggested change
Just asking. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. When it is a Python project with a |
||||||
|
||||||
This tests asserts that the minimal configuration is to do *nothing* | ||||||
when using a pyproject.toml file. | ||||||
""" | ||||||
project_dir = self.mktemp_project( | ||||||
pyproject_toml=""" | ||||||
[project] | ||||||
name = "a" | ||||||
""", | ||||||
) | ||||||
|
||||||
config = load_config(project_dir) | ||||||
self.assertEqual(config.package, "a") | ||||||
self.assertEqual(config.name, "a") | ||||||
|
||||||
def test_pyproject_assert_fallback(self): | ||||||
""" | ||||||
This test is an extensive test of the fallback scenarios | ||||||
for the `package` and `name` keys in the towncrier section. | ||||||
|
||||||
It will fallback to pyproject.toml:name in any case. | ||||||
And as such it checks the various fallback mechanisms | ||||||
if the fields are not present in the towncrier.toml, nor | ||||||
in the pyproject.toml files. | ||||||
|
||||||
This both tests when things are *only* in the pyproject.toml | ||||||
and default usage of the data in the towncrier.toml file. | ||||||
""" | ||||||
pyproject_toml = dedent( | ||||||
""" | ||||||
[project] | ||||||
name = "foo" | ||||||
[tool.towncrier] | ||||||
""" | ||||||
) | ||||||
towncrier_toml = dedent( | ||||||
""" | ||||||
[tool.towncrier] | ||||||
""" | ||||||
) | ||||||
tests = [ | ||||||
"", | ||||||
"name = '{name}'", | ||||||
"package = '{package}'", | ||||||
"name = '{name}'", | ||||||
"package = '{package}'", | ||||||
] | ||||||
|
||||||
def factory(name, package): | ||||||
def func(test): | ||||||
return dedent(test).format(name=name, package=package) | ||||||
|
||||||
return func | ||||||
|
||||||
for pp_fields in map(factory(name="a", package="b"), tests): | ||||||
pp_toml = pyproject_toml + pp_fields | ||||||
for tc_fields in map(factory(name="c", package="d"), tests): | ||||||
tc_toml = towncrier_toml + tc_fields | ||||||
|
||||||
# Create the temporary project | ||||||
project_dir = self.mktemp_project( | ||||||
pyproject_toml=pp_toml, | ||||||
towncrier_toml=tc_toml, | ||||||
) | ||||||
|
||||||
# Read the configuration file. | ||||||
config = load_config(project_dir) | ||||||
|
||||||
# Now the values depend on where the fallback | ||||||
# is. | ||||||
# If something is in towncrier.toml, it will be preferred | ||||||
# name fallsback to package | ||||||
if "package" in tc_fields: | ||||||
package = "d" | ||||||
else: | ||||||
package = "foo" | ||||||
self.assertEqual(config.package, package) | ||||||
|
||||||
if "name" in tc_fields: | ||||||
self.assertEqual(config.name, "c") | ||||||
else: | ||||||
# fall-back to package name | ||||||
self.assertEqual(config.name, package) | ||||||
|
||||||
@with_isolated_runner | ||||||
def test_load_no_config(self, runner: CliRunner): | ||||||
""" | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this test removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because now
towncrier
does not need anytool.towncrier
section for Python projects usingpyproject.toml
files.A
pyproject.toml
file requires thename
field, and hence everything can be used without problems.The removed test checked that it broke when
tool.towncrier
was not present, simply because it is not required.