From f1410b7c1fce8afb579e3b9762e298c0f96ec541 Mon Sep 17 00:00:00 2001 From: WORD559 Date: Thu, 3 Oct 2019 16:36:26 +0100 Subject: [PATCH 1/2] Use util.asbool rather than manual true-value parsing --- bumblebee/output.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bumblebee/output.py b/bumblebee/output.py index f70b605..004dfe8 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -7,15 +7,14 @@ import json import uuid import bumblebee.store - -_TrueValues = ["true", "t", "yes", "y", "1"] +import bumblebee.util def scrollable(func): def wrapper(module, widget): text = func(module, widget) if not text: return text width = widget.get("theme.width", module.parameter("width", 30)) - if module.parameter("scrolling.makewide", "true").lower() in _TrueValues: + if bumblebee.util.asbool(module.parameter("scrolling.makewide", "true")): widget.set("theme.minwidth", "A"*width) if len(text) <= width: return text From fb2fb796da4c9f7ab840578d133f7800702e84ed Mon Sep 17 00:00:00 2001 From: WORD559 Date: Fri, 4 Oct 2019 15:18:11 +0100 Subject: [PATCH 2/2] add test for asbool --- tests/test_util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 07d6d3a..828728b 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -69,5 +69,15 @@ class TestUtil(unittest.TestCase): # test if which also works with garbage input self.assertTrue(bu.which("qwertygarbage") is None) + def test_asbool(self): + for val in ("t", "true", "y", "yes", "on", "1", 1, True): + self.assertTrue(bu.asbool(val)) + if isinstance(val, str): + self.assertTrue(bu.asbool(val.upper())) + + for val in ("f", "false", "n", "no", "off", "0", 0, False): + self.assertFalse(bu.asbool(val)) + if isinstance(val, str): + self.assertFalse(bu.asbool(val.upper())) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4