From c0d044447d8b411c77ef6d8eaafdcd3b640e88b5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 17 May 2016 17:21:14 +0200 Subject: [PATCH] Add tests for qutebrowser.utils.typing --- qutebrowser/utils/typing.py | 2 +- scripts/dev/check_coverage.py | 2 ++ tests/unit/utils/test_typing.py | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/unit/utils/test_typing.py diff --git a/qutebrowser/utils/typing.py b/qutebrowser/utils/typing.py index 87d741a6e..f4b0dd990 100644 --- a/qutebrowser/utils/typing.py +++ b/qutebrowser/utils/typing.py @@ -67,5 +67,5 @@ class FakeUnion(metaclass=FakeUnionMeta): try: from typing import Union -except ImportError: +except ImportError: # pragma: no cover Union = FakeUnion diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index e82229545..185f91641 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -136,6 +136,8 @@ PERFECT_FILES = [ 'qutebrowser/utils/jinja.py'), ('tests/unit/utils/test_error.py', 'qutebrowser/utils/error.py'), + ('tests/unit/utils/test_typing.py', + 'qutebrowser/utils/typing.py'), ] diff --git a/tests/unit/utils/test_typing.py b/tests/unit/utils/test_typing.py new file mode 100644 index 000000000..3beefb424 --- /dev/null +++ b/tests/unit/utils/test_typing.py @@ -0,0 +1,44 @@ +# Copyright 2016 Florian Bruhin (The Compiler) +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Tests for qutebrowser.utils.typing.""" + +import pytest + +from qutebrowser.utils import typing + + +@pytest.fixture +def pytyping(): + """A fixture to get the python 3.5+ typing module.""" + pytyping = pytest.importorskip('typing') + return pytyping + + +class TestUnion: + + def test_python_subclass(self, pytyping): + assert issubclass(pytyping.Union[str, int], pytyping.Union) + + def test_qute_subclass(self): + assert issubclass(typing.FakeUnion[str, int], typing.FakeUnion) + + def test_python_params(self, pytyping): + assert pytyping.Union[str, int].__union_params__ == (str, int) + + def test_qute_params(self): + assert typing.FakeUnion[str, int].__union_params__ == (str, int)