From 29ff4259d69f3e3c994c3e66e93350d78a5d972f Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Tue, 13 Feb 2018 20:09:19 +0000 Subject: [PATCH] Add test for _uptime() --- tests/helpers/stubs.py | 10 ---------- tests/unit/misc/test_pastebin.py | 2 +- tests/unit/utils/test_version.py | 17 +++++++++++------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index ede322b74..27a23650d 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -585,13 +585,3 @@ class HTTPPostStub(QObject): def post(self, url, data=None): self.url = url self.data = data - - -@pytest.fixture -def pbclient(stubs): - http_stub = stubs.HTTPPostStub() - client = pastebin.PastebinClient(http_stub) - return client - - - diff --git a/tests/unit/misc/test_pastebin.py b/tests/unit/misc/test_pastebin.py index 9546bcf36..1d684dc4e 100644 --- a/tests/unit/misc/test_pastebin.py +++ b/tests/unit/misc/test_pastebin.py @@ -18,7 +18,7 @@ # along with qutebrowser. If not, see . import pytest -from PyQt5.QtCore import pyqtSignal, QUrl, QObject +from PyQt5.QtCore import QUrl from qutebrowser.misc import httpclient, pastebin diff --git a/tests/unit/utils/test_version.py b/tests/unit/utils/test_version.py index f4f7270ba..f6e7efb16 100644 --- a/tests/unit/utils/test_version.py +++ b/tests/unit/utils/test_version.py @@ -35,8 +35,6 @@ import datetime import attr import pkg_resources import pytest -from PyQt5.QtCore import pyqtSignal, QObject -from PyQt5.QtWidgets import QApplication import qutebrowser from qutebrowser.utils import version, usertypes, utils @@ -1011,7 +1009,14 @@ def test_pastebin_version_error(pbclient, caplog, monkeypatch): assert caplog.records[0].message == "Failed to pastebin version info: test" -def test_uptime(monkeypatch): - """Test _uptime runs without failing. Its effects are tested elsewhere.""" - QApplication.instance().launch_time = datetime.datetime(1, 1, 1) - version._uptime() +def test_uptime(monkeypatch, qapp): + """Test _uptime runs and check if microseconds are dropped.""" + launch_time = datetime.datetime(1, 1, 1, 1, 1, 1, 1) + qapp.launch_time = launch_time + + class FakeDateTime(datetime.datetime): + now = lambda x=datetime.datetime(1, 1, 1, 1, 1, 1, 2): x + monkeypatch.setattr('datetime.datetime', FakeDateTime) + + uptime_delta = version._uptime() + assert uptime_delta == datetime.timedelta(0)