From 6d175fbb4b3b7773ed58af482732ab491dc299eb Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Jun 2017 16:17:44 +0200 Subject: [PATCH] Get rid of configtypes.WebKitBytes --- qutebrowser/config/configtypes.py | 54 --------------------------- tests/unit/config/test_configtypes.py | 42 --------------------- 2 files changed, 96 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 682c02737..3d6e71426 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -915,60 +915,6 @@ class FormatString(BaseType): raise configexc.ValidationError(value, str(e)) -class WebKitBytes(BaseType): - - """A size with an optional suffix. - - Attributes: - maxsize: The maximum size to be used. - - Class attributes: - SUFFIXES: A mapping of size suffixes to multiplicators. - """ - - SUFFIXES = { - 'k': 1024 ** 1, - 'm': 1024 ** 2, - 'g': 1024 ** 3, - 't': 1024 ** 4, - 'p': 1024 ** 5, - 'e': 1024 ** 6, - 'z': 1024 ** 7, - 'y': 1024 ** 8, - } - - def __init__(self, maxsize=None, none_ok=False): - super().__init__(none_ok) - self.maxsize = maxsize - - def validate(self, value): - self._basic_validation(value) - if not value: - return - try: - val = self.transform(value) - except ValueError: - raise configexc.ValidationError(value, "must be a valid integer " - "with optional suffix!") - if self.maxsize is not None and val > self.maxsize: - raise configexc.ValidationError(value, "must be {} " - "maximum!".format(self.maxsize)) - if val < 0: - raise configexc.ValidationError(value, "must be 0 minimum!") - - def transform(self, value): - if not value: - return None - elif any(value.lower().endswith(c) for c in self.SUFFIXES): - suffix = value[-1].lower() - val = value[:-1] - multiplicator = self.SUFFIXES[suffix] - else: - val = value - multiplicator = 1 - return int(val) * multiplicator - - class ShellCommand(BaseType): """A shellcommand which is split via shlex. diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index b547be83b..378e78fdb 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -1387,48 +1387,6 @@ class TestDirectory: assert klass().transform('') is None -class TestWebKitByte: - - """Test WebKitBytes.""" - - @pytest.fixture - def klass(self): - return configtypes.WebKitBytes - - @pytest.mark.parametrize('maxsize, val', [ - (None, ''), - (None, '42'), - (None, '56k'), - (None, '56K'), - (10, '10'), - (2048, '2k'), - ]) - def test_validate_valid(self, klass, maxsize, val): - klass(none_ok=True, maxsize=maxsize).validate(val) - - @pytest.mark.parametrize('maxsize, val', [ - (None, ''), - (None, '-1'), - (None, '-1k'), - (None, '56x'), - (None, '56kk'), - (10, '11'), - (999, '1k'), - ]) - def test_validate_invalid(self, klass, maxsize, val): - with pytest.raises(configexc.ValidationError): - klass(maxsize=maxsize).validate(val) - - @pytest.mark.parametrize('val, expected', [ - ('', None), - ('10', 10), - ('1k', 1024), - ('1t', 1024 ** 4), - ]) - def test_transform(self, klass, val, expected): - assert klass().transform(val) == expected - - class TestShellCommand: """Test ShellCommand."""