Skip to content

Commit

Permalink
fix #204 (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Apr 4, 2021
1 parent e021216 commit f0bfa8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ jupytext
numpy
imageio
sphinx-autodoc-typehints
sphinxcontrib-bibtex>=2.2.0
sphinxcontrib-bibtex<2.0.0
5 changes: 3 additions & 2 deletions magicgui/widgets/_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ def __init__(
super().__init__(**kwargs)
self.margins = (0, 0, 0, 0)
self._show_file_dialog = use_app().get_obj("show_file_dialog")
self.choose_btn.changed.connect(self._on_choose_clicked)
self.choose_btn.changed.disconnect()
self.line_edit.changed.disconnect()
self.choose_btn.changed.connect(self._on_choose_clicked)
self.line_edit.changed.connect(lambda x: self.changed(value=self.value))

@property
Expand Down Expand Up @@ -527,7 +528,7 @@ def value(self) -> tuple[Path, ...] | Path:
def value(self, value: Sequence[PathLike] | PathLike):
"""Set current file path."""
if isinstance(value, (list, tuple)):
value = ", ".join([os.fspath(p) for p in value])
value = ", ".join(os.fspath(p) for p in value)
if not isinstance(value, (str, Path)):
raise TypeError(
f"value must be a string, or list/tuple of strings, got {type(value)}"
Expand Down
15 changes: 12 additions & 3 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import inspect
from enum import Enum
from unittest.mock import MagicMock
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest
from tests import MyInt
Expand Down Expand Up @@ -510,14 +511,22 @@ def func(x: int, y: str):

def test_file_dialog_events():
"""Test that file dialog events emit the value of the line_edit."""
from pathlib import Path

fe = widgets.FileEdit(value="hi")
fe.changed = MagicMock(wraps=fe.changed)
fe.line_edit.value = "world"
fe.changed.assert_called_once_with(value=Path("world"))


def test_file_dialog_button_events():
"""Test that clicking the file dialog button doesn't emit an event."""
fe = widgets.FileEdit(value="hi")
fe.changed = MagicMock(wraps=fe.changed)
with patch.object(fe, "_show_file_dialog", return_value=""):
fe.choose_btn.changed()
fe.changed.assert_not_called()
assert fe.value == Path("hi")


@pytest.mark.parametrize("WdgClass", [widgets.FloatSlider, widgets.FloatSpinBox])
@pytest.mark.parametrize("value", [1, 1e6, 1e12, 1e16, 1e22])
def test_extreme_floats(WdgClass, value):
Expand Down

0 comments on commit f0bfa8f

Please sign in to comment.