Add test for _uptime()

This commit is contained in:
George Edward Bulmer 2018-02-13 20:09:19 +00:00
parent ca8d935cf4
commit 29ff4259d6
3 changed files with 12 additions and 17 deletions

View File

@ -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

View File

@ -18,7 +18,7 @@
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import pytest
from PyQt5.QtCore import pyqtSignal, QUrl, QObject
from PyQt5.QtCore import QUrl
from qutebrowser.misc import httpclient, pastebin

View File

@ -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)