Merge pull request #452 from joshbarrass/useasbool

Use util.asbool rather than manual true-value parsing
This commit is contained in:
tobi-wan-kenobi 2019-10-06 15:31:06 +02:00 committed by GitHub
commit 08ce5ae89b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -7,15 +7,14 @@ import json
import uuid import uuid
import bumblebee.store import bumblebee.store
import bumblebee.util
_TrueValues = ["true", "t", "yes", "y", "1"]
def scrollable(func): def scrollable(func):
def wrapper(module, widget): def wrapper(module, widget):
text = func(module, widget) text = func(module, widget)
if not text: return text if not text: return text
width = widget.get("theme.width", module.parameter("width", 30)) 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) widget.set("theme.minwidth", "A"*width)
if len(text) <= width: if len(text) <= width:
return text return text

View file

@ -69,5 +69,15 @@ class TestUtil(unittest.TestCase):
# test if which also works with garbage input # test if which also works with garbage input
self.assertTrue(bu.which("qwertygarbage") is None) 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 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4