From 029ffe3fc7ad905b1d75b16e61547a33e22a727f Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 13 Jul 2016 14:17:41 +0200 Subject: [PATCH] tests: add tests for usertypes.DownloadTarget --- .../utils/usertypes/test_downloadtarget.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/unit/utils/usertypes/test_downloadtarget.py diff --git a/tests/unit/utils/usertypes/test_downloadtarget.py b/tests/unit/utils/usertypes/test_downloadtarget.py new file mode 100644 index 000000000..e89401144 --- /dev/null +++ b/tests/unit/utils/usertypes/test_downloadtarget.py @@ -0,0 +1,54 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2016 Daniel Schadt +# +# This file is part of qutebrowser. +# +# 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 the DownloadTarget class.""" + +from qutebrowser.utils import usertypes + +import pytest + + +def test_base(): + with pytest.raises(NotImplementedError): + usertypes.DownloadTarget() + + +def test_filename(): + target = usertypes.FileDownloadTarget("/foo/bar") + assert target.filename == "/foo/bar" + + +def test_fileobj(): + fobj = object() + target = usertypes.FileObjDownloadTarget(fobj) + assert target.fileobj is fobj + + +def test_openfile(): + # Just make sure no error is raised, that should be enough. + usertypes.OpenFileDownloadTarget() + + +@pytest.mark.parametrize('obj', [ + usertypes.FileDownloadTarget('foobar'), + usertypes.FileObjDownloadTarget(None), + usertypes.OpenFileDownloadTarget(), +]) +def test_class_hierarchy(obj): + assert isinstance(obj, usertypes.DownloadTarget)