Skip to content

Commit

Permalink
tests: allow tests to run without a qt backend
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Jan 30, 2019
1 parent 69bf31c commit ed93b27
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def qt_app():
"""
try:
from enaml.qt.qt_application import QtApplication
except ImportError:
except Exception:
pytest.skip('No Qt binding found: %s' % format_exc())

app = QtApplication.instance()
Expand Down
6 changes: 5 additions & 1 deletion tests/core/test_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from enaml.fonts import (coerce_font, Font, _SIZES, _UNITS, _WEIGHTS, _STYLES,
_VARIANTS, _STRETCH)
from enaml.qt.q_resource_helpers import get_cached_qfont

# The order defining a CSS3 string is:
# style variant weight stretch size line-height family.
Expand Down Expand Up @@ -50,5 +49,10 @@ def test_font_coercion(family, size, weight, style, variant, stretch):
assert font.stretch == _STRETCH[stretch or 'normal']

assert font._tkdata is None

try:
from enaml.qt.q_resource_helpers import get_cached_qfont
except Exception:
return
get_cached_qfont(font)
assert font._tkdata is not None
6 changes: 5 additions & 1 deletion tests/test_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pickle

from enaml.colors import Color
from enaml.qt.q_resource_helpers import get_cached_qcolor


def test_color_initialization():
Expand All @@ -25,6 +24,11 @@ def test_color_initialization():
assert getattr(c, name) == 0

assert c._tkdata is None

try:
from enaml.qt.q_resource_helpers import get_cached_qcolor
except Exception:
return
get_cached_qcolor(c)
assert c._tkdata is not None

Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
try:
from enaml.qt import QtWebEngineWidgets
WEBVIEW_AVAILABLE = True
except ImportError:
except Exception:
WEBVIEW_AVAILABLE = False


Expand Down
24 changes: 12 additions & 12 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ def answer_question(app, dial):

@contextmanager
def cd(path, add_to_sys_path=False):
""" cd to the directory then return to the cwd
""" cd to the directory then return to the cwd
"""
cwd = os.getcwd()
if add_to_sys_path:
Expand All @@ -343,33 +343,33 @@ def cd(path, add_to_sys_path=False):


@pytest.fixture
def enaml_run(qtbot, monkeypatch):
""" Patches the QtApplication to allow using the qtbot when the
def enaml_run(enaml_qtbot, monkeypatch):
""" Patches the QtApplication to allow using the qtbot when the
enaml application is started. It also patches QApplication.exit as
recommended in the pytest-qt docs.
Yields
-------
handler: object
an object with a `run` attribute that can be set to a callback that
handler: object
an object with a `run` attribute that can be set to a callback that
will be invoked with the application and first window shown.
References
----------
1. https://pytest-qt.readthedocs.io/en/latest/app_exit.html
"""
from enaml.qt.qt_application import QtApplication, QApplication

app = Application.instance()
if app:
Application._instance = None

class Runner:
# Set this to a callback
run = None
runner = Runner()

def start(self):
for window in Window.windows:
wait_for_window_displayed(qtbot, window)
Expand Down

0 comments on commit ed93b27

Please sign in to comment.