From 2c3fcda18e14c36cd3d39288cd622ad993fa1408 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 3 Apr 2017 09:32:13 +0200 Subject: [PATCH] Remove qtutils.ensure_not_null It's not used anymore. --- qutebrowser/utils/qtutils.py | 6 ----- tests/unit/utils/test_qtutils.py | 42 ++++++++++---------------------- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index e36fd0ffb..5c98a24da 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -174,12 +174,6 @@ def ensure_valid(obj): raise QtValueError(obj) -def ensure_not_null(obj): - """Ensure a Qt object with an .isNull() method is not null.""" - if obj.isNull(): - raise QtValueError(obj, null=True) - - def check_qdatastream(stream): """Check the status of a QDataStream and raise OSError if it's not ok.""" status_to_str = { diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py index b2de7b58d..74da2ac4f 100644 --- a/tests/unit/utils/test_qtutils.py +++ b/tests/unit/utils/test_qtutils.py @@ -209,48 +209,32 @@ class QtObject: return self._null -@pytest.mark.parametrize('func_name, obj, raising, exc_reason, exc_str', [ - # ensure_valid, good examples - ('ensure_valid', QtObject(valid=True, null=True), False, None, None), - ('ensure_valid', QtObject(valid=True, null=False), False, None, None), - # ensure_valid, bad examples - ('ensure_valid', QtObject(valid=False, null=True), True, None, - ' is not valid'), - ('ensure_valid', QtObject(valid=False, null=False), True, None, - ' is not valid'), - ('ensure_valid', QtObject(valid=False, null=True, error='Test'), True, - 'Test', ' is not valid: Test'), - # ensure_not_null, good examples - ('ensure_not_null', QtObject(valid=True, null=False), False, None, None), - ('ensure_not_null', QtObject(valid=False, null=False), False, None, None), - # ensure_not_null, bad examples - ('ensure_not_null', QtObject(valid=True, null=True), True, None, - ' is null'), - ('ensure_not_null', QtObject(valid=False, null=True), True, None, - ' is null'), - ('ensure_not_null', QtObject(valid=False, null=True, error='Test'), True, - 'Test', ' is null: Test'), +@pytest.mark.parametrize('obj, raising, exc_reason, exc_str', [ + # good examples + (QtObject(valid=True, null=True), False, None, None), + (QtObject(valid=True, null=False), False, None, None), + # bad examples + (QtObject(valid=False, null=True), True, None, ' is not valid'), + (QtObject(valid=False, null=False), True, None, ' is not valid'), + (QtObject(valid=False, null=True, error='Test'), True, 'Test', + ' is not valid: Test'), ]) -def test_ensure(func_name, obj, raising, exc_reason, exc_str): - """Test ensure_valid and ensure_not_null. - - The function is parametrized as they do nearly the same. +def test_ensure_valid(obj, raising, exc_reason, exc_str): + """Test ensure_valid. Args: - func_name: The name of the function to call. obj: The object to test with. raising: Whether QtValueError is expected to be raised. exc_reason: The expected .reason attribute of the exception. exc_str: The expected string of the exception. """ - func = getattr(qtutils, func_name) if raising: with pytest.raises(qtutils.QtValueError) as excinfo: - func(obj) + qtutils.ensure_valid(obj) assert excinfo.value.reason == exc_reason assert str(excinfo.value) == exc_str else: - func(obj) + qtutils.ensure_valid(obj) @pytest.mark.parametrize('status, raising, message', [