Improve version.opengl_vendor()

On Windows with OpenGL ES we can't use versionFunctions, so we just return None
early.

Also, this fixes some lint and adds a smoke test.
This commit is contained in:
Florian Bruhin 2017-05-30 19:23:27 +02:00
parent b8a32c577f
commit 912cea6e7d
2 changed files with 19 additions and 5 deletions

View File

@ -380,12 +380,15 @@ def version():
def opengl_vendor(): # pragma: no cover
"""Get the OpenGL vendor used."""
"""Get the OpenGL vendor used.
This returns a string such as 'nouveau' or
'Intel Open Source Technology Center'; or None if the vendor can't be
determined.
"""
# We're doing those imports here because this is only available with Qt 5.4
# or newer.
from PyQt5.QtWidgets import QOpenGLWidget
from PyQt5.QtOpenGL import QGLWidget
from PyQt5.QtGui import QOpenGLContext, QSurfaceFormat, QOpenGLVersionProfile, QOffscreenSurface
from PyQt5.QtGui import QOpenGLContext, QOpenGLVersionProfile, QOffscreenSurface
assert QApplication.instance()
assert QOpenGLContext.currentContext() is None
@ -393,6 +396,10 @@ def opengl_vendor(): # pragma: no cover
surface.create()
ctx = QOpenGLContext()
if ctx.isOpenGLES():
# Can't use versionFunctions there
return None
ok = ctx.create()
assert ok

View File

@ -34,7 +34,7 @@ import pkg_resources
import pytest
import qutebrowser
from qutebrowser.utils import version, usertypes
from qutebrowser.utils import version, usertypes, qtutils
from qutebrowser.browser import pdfjs
@ -918,3 +918,10 @@ def test_version_output(git_commit, frozen, style, with_webkit,
expected = template.rstrip('\n').format(**substitutions)
assert version.version() == expected
@pytest.mark.skipif(not qtutils.version_check('5.4'),
reason="Needs Qt >= 5.4.")
def test_opengl_vendor():
"""Simply call version.opengl_vendor() and see if it doesn't crash."""
return version.opengl_vendor()