Beispiel #1
0
def test_examples(fname):
    """Make sure that all code cells in documentation perform as expected."""
    app = use_app()
    app.start_timer(0, app.quit)
    if "OLD" in fname:
        with pytest.warns(FutureWarning):
            assert runpy.run_path(fname)
    else:
        assert runpy.run_path(fname)
Beispiel #2
0
def test_examples(fname):
    """Make sure that all code cells in documentation perform as expected."""
    app = use_app()
    app.start_timer(0, app.quit)
    if "OLD" in fname:
        with pytest.warns(FutureWarning):
            runpy.run_path(fname)
    else:
        try:
            runpy.run_path(fname)
        except ImportError as e:
            if "Numpy required to use images" in str(e):
                pytest.skip("numpy unavailable: skipping image example")
Beispiel #3
0
 def _label_width():
     measure = use_app().get_obj("get_text_width")
     return max(
         measure(w.label) for w in container
         if not isinstance(w, widgets._bases.ButtonWidget))
Beispiel #4
0
    A = "a"
    B = "b"


@pytest.mark.parametrize("Cls", [widgets.ComboBox, widgets.RadioButtons])
def test_categorical_widgets_with_enums(Cls):
    wdg = Cls(value=MyEnum.A, choices=MyEnum)

    wdg.changed = MagicMock(wraps=wdg.changed)
    assert isinstance(wdg, widgets._bases.CategoricalWidget)
    assert wdg.value == MyEnum.A
    assert wdg.current_choice == "A"
    wdg.changed.assert_not_called()
    wdg.value = MyEnum.B
    wdg.changed.assert_called_once()
    assert wdg.changed.call_args[1].get("value") == MyEnum.B
    assert wdg.value == MyEnum.B
    assert wdg.current_choice == "B"
    assert wdg.choices == tuple(MyEnum.__members__.values())


@pytest.mark.skipif(use_app().backend_name != "qt", reason="only on qt")
def test_radiobutton_reset_choices():
    """Test that reset_choices doesn't change the number of buttons."""
    from qtpy.QtWidgets import QRadioButton

    wdg = widgets.RadioButtons(choices=["a", "b", "c"])
    assert len(wdg.native.findChildren(QRadioButton)) == 3
    wdg.reset_choices()
    assert len(wdg.native.findChildren(QRadioButton)) == 3
def test_app_name():
    app = use_app("qt")
    assert app.native.applicationName() == APPLICATION_NAME
Beispiel #6
0
"""FileDialog with magicgui."""
from pathlib import Path
from typing import Sequence

from magicgui import magicgui, use_app


@magicgui(filename={"mode": "r"})
def filepicker(filename=Path("~")):
    """Take a filename and do something with it."""
    print("The filename is:", filename)
    return filename


# Sequence of paths
# We change the label using "label" for added clarity
# the filter argument restricts file types
@magicgui(filenames={"label": "Choose Tiff files:", "filter": "*.tif"})
def filespicker(filenames: Sequence[Path]):
    """Take a filename and do something with it."""
    print("The filenames are:", filenames)
    return filenames


filepicker.show()
filespicker.show()
filepicker.filename.changed.connect(lambda e: print(e.value))
filespicker.filenames.changed.connect(lambda e: print(e.value))

use_app().run()