summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@users.noreply.github.com>2022-12-09 15:46:09 -0600
committerGitHub <noreply@github.com>2022-12-09 13:46:09 -0800
commit791b4aae083b5861422b8a3ffc9e541c7ac7b422 (patch)
treeae3cb0ccdcc14330bcb3809d5cda5b04c209fc50
parent1e32d0c2c03a1f5aa7c0e4aacf6064502903a4bf (diff)
downloadtox-git-791b4aae083b5861422b8a3ffc9e541c7ac7b422.tar.gz
Add repr() calls to "invalid value" exception message in StrConverter.to_bool (#2666)
* Use !r and repr to make exception messages clearer. * Use !r and repr to make exception messages clearer. Add changelog file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Reverted repr() on VALID_BOOL list; updated relevant test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed test-breaking typo Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
-rw-r--r--docs/changelog/2665.bugfix.rst1
-rw-r--r--src/tox/config/loader/str_convert.py6
-rw-r--r--tests/config/test_sets.py2
3 files changed, 6 insertions, 3 deletions
diff --git a/docs/changelog/2665.bugfix.rst b/docs/changelog/2665.bugfix.rst
new file mode 100644
index 00000000..a4be5e9d
--- /dev/null
+++ b/docs/changelog/2665.bugfix.rst
@@ -0,0 +1 @@
+Use ``!r`` and ``repr()`` to better display erroneous values in exception from ``StrConverter.to_bool()`` - by :user:`ptmcg`.
diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py
index dd518e5e..e31c034f 100644
--- a/src/tox/config/loader/str_convert.py
+++ b/src/tox/config/loader/str_convert.py
@@ -81,13 +81,15 @@ class StrConvert(Convert[str]):
@staticmethod
def to_bool(value: str) -> bool:
- norm = value.strip().lower()
+ norm = str(value).strip().lower()
if norm in StrConvert.TRUTHFUL_VALUES:
return True
elif norm in StrConvert.FALSE_VALUES:
return False
else:
- raise TypeError(f"value {value} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}")
+ raise TypeError(
+ f"value {value!r} cannot be transformed to bool, valid: {', '.join(StrConvert.VALID_BOOL)}",
+ )
__all__ = ("StrConvert",)
diff --git a/tests/config/test_sets.py b/tests/config/test_sets.py
index ca577875..0faa68ac 100644
--- a/tests/config/test_sets.py
+++ b/tests/config/test_sets.py
@@ -89,7 +89,7 @@ def test_config_bad_bool(conf_builder: ConfBuilder) -> None:
config_set.add_config(keys="bad_bool", of_type=bool, default=False, desc="bad_bool")
with pytest.raises(TypeError) as context:
assert config_set["bad_bool"]
- error = "value whatever cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes"
+ error = "value 'whatever' cannot be transformed to bool, valid: , 0, 1, false, no, off, on, true, yes"
assert str(context.value) == error