Skip to content

Commit

Permalink
Use Field.get_callback to handle quiet/verbose and http_debug/http_fu…
Browse files Browse the repository at this point in the history
…ll_debug options
  • Loading branch information
dmach committed Jan 24, 2024
1 parent 8a38a9d commit c7af0e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def apiurl_aliases(self):
description=textwrap.dedent(
"""
Reduce amount of printed information to bare minimum.
Takes priority over ``verbose``.
If enabled, automatically sets ``verbose`` to ``False``.
"""
),
) # type: ignore[assignment]
Expand All @@ -574,8 +574,10 @@ def apiurl_aliases(self):
description=textwrap.dedent(
"""
Increase amount of printed information to stdout.
Automatically set to ``False`` when ``quiet`` is enabled.
"""
),
get_callback=lambda conf, value: False if conf.quiet else value,
) # type: ignore[assignment]

debug: bool = Field(
Expand All @@ -592,15 +594,18 @@ def apiurl_aliases(self):
description=textwrap.dedent(
"""
Print HTTP traffic to stderr.
Automatically set to ``True`` when``http_full_debug`` is enabled.
"""
),
get_callback=lambda conf, value: True if conf.http_full_debug else value,
) # type: ignore[assignment]

http_full_debug: bool = Field(
default=False,
description=textwrap.dedent(
"""
[CAUTION!] Print HTTP traffic incl. authentication data to stderr.
If enabled, automatically sets ``http_debug`` to ``True``.
"""
),
) # type: ignore[assignment]
Expand Down Expand Up @@ -1821,7 +1826,6 @@ def get_config(override_conffile=None,
overrides["http_debug"] = override_http_debug

if override_http_full_debug is not None:
overrides["http_debug"] = override_http_full_debug or overrides["http_debug"]
overrides["http_full_debug"] = override_http_full_debug

if override_traceback is not None:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,33 @@ def test_apiurl_aliases(self):
self.assertEqual(self.config["apiurl_aliases"], expected)


class TestOverrides(unittest.TestCase):
def test_verbose(self):
self.options = osc.conf.Options()
self.assertEqual(self.options.quiet, False)
self.assertEqual(self.options.verbose, False)

self.options.quiet = True
self.options.verbose = True
self.assertEqual(self.options.quiet, True)
# ``verbose`` is forced to ``False`` by the ``quiet`` option
self.assertEqual(self.options.verbose, False)

self.options.quiet = False
self.assertEqual(self.options.quiet, False)
self.assertEqual(self.options.verbose, True)

def test_http_debug(self):
self.options = osc.conf.Options()
self.assertEqual(self.options.http_debug, False)
self.assertEqual(self.options.http_full_debug, False)

self.options.http_full_debug = True
# ``http_debug`` forced to ``True`` by the ``http_full_debug`` option
self.assertEqual(self.options.http_debug, True)
self.assertEqual(self.options.http_full_debug, True)


class TestFromParent(unittest.TestCase):
def setUp(self):
self.options = osc.conf.Options()
Expand Down

0 comments on commit c7af0e4

Please sign in to comment.