Skip to content

Commit

Permalink
Few more code fixes, make the widget testing more ropbust for paralle…
Browse files Browse the repository at this point in the history
…l tests. Adjust conda build dependencies
  • Loading branch information
gb119 committed Jan 3, 2024
1 parent 9d208a3 commit 6c5b9ce
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Stoner/Core.py
Expand Up @@ -147,7 +147,7 @@ class DataFile(

def __new__(cls, *args, **kargs):
"""Prepare the basic DataFile instance before the mixins add their bits."""
self = metadataObject.__new__(cls, *args)
self = metadataObject.__new__(cls)
object.__setattr__(self, "debug", kargs.pop("debug", False))
self._masks = [False]
self._filename = None
Expand Down
3 changes: 0 additions & 3 deletions Stoner/Image/core.py
Expand Up @@ -774,9 +774,6 @@ class ImageFile(metadataObject):
# pylint: disable=no-member

_protected_attrs = ["_fromstack"] # these won't be passed through to self.image attrs
_patterns = ["*.png", "*.tif", "*.jpeg", "*.jpg"]
mime_type = ["image/png", "image/jpeg", "image/tiff", "application/octet-stream"]
priority = 32

def __init__(self, *args, **kargs):
"""Mostly a pass through to ImageArray constructor.
Expand Down
15 changes: 9 additions & 6 deletions Stoner/core/base.py
Expand Up @@ -354,7 +354,8 @@ def __init__(self, *args: Any, **kargs: Any) -> None:
# _typehint dict
value = super().__getitem__(key)
super().__delitem__(key)
self[key] = value # __Setitem__ has the logic to handle embedded type hints correctly
# __Setitem__ has the logic to handle embedded type hints correctly
self[key] = value

@property
def types(self) -> Dict:
Expand Down Expand Up @@ -425,7 +426,8 @@ def __mungevalue(self, typ: str, value: Any) -> Any:
if matched is not None:
if isinstance(valuetype, _evaluatable):
try:
if isinstance(value, string_types): # we've got a string already don't need repr
# we've got a string already don't need repr
if isinstance(value, string_types):
ret = literal_eval(value)
else:
ret = literal_eval(repr(value)) # pylint: disable=eval-used
Expand Down Expand Up @@ -765,7 +767,7 @@ def save(self, filename: Filename = None, **kargs: Any):
raise NotImplementedError("Save is not implemented in the base class.")

@classmethod
def load(self, filename: Filename, *args: Any, **kargs: Any) -> "metadataObject":
def load(cls, filename: Filename, *args: Any, **kargs: Any) -> "metadataObject":
"""Stub method for a load function."""
raise NotImplementedError("Save is not implemented in the base class.")

Expand All @@ -775,7 +777,7 @@ class SortedMultivalueDict(OrderedDict):
"""Implement a simple multivalued dictionary where the values are always sorted lists of elements."""

@classmethod
def _matching(cls, val):
def _matching(cls, val: Tuple[int, str] | List[Tuple[int, str]]) -> List[Tuple[int, str]]:
match val:
case (int(p), item):
return [(p, item)]
Expand All @@ -793,7 +795,7 @@ def get_value_list(self, name):
def __setitem__(self, name: Any, val: Union[List[Tuple[int, Any]], Tuple[int, Any]]) -> None:
"""Insert or replace a value and then sort the values."""
values = self._matching(val)
for p, value in values:
for p, value in values: # pylint: disable=not-an-iterable
for ix, (_, old_value) in enumerate(self.get(name, [])):
if old_value == value: # replacing existing value
self[name][ix] = (p, value)
Expand All @@ -803,7 +805,8 @@ def __setitem__(self, name: Any, val: Union[List[Tuple[int, Any]], Tuple[int, An
super().__setitem__(name, sorted(self[name], key=lambda item: (item[0], str(item[1]))))


if pd is not None and not hasattr(pd.DataFrame, "metadata"): # Don;t double add metadata
# Don't double add metadata
if pd is not None and not hasattr(pd.DataFrame, "metadata"):

@pd.api.extensions.register_dataframe_accessor("metadata")
class PandasMetadata(typeHintedDict):
Expand Down
12 changes: 6 additions & 6 deletions recipe/meta.yaml
Expand Up @@ -22,16 +22,16 @@ requirements:
- pytest-runner

run:
- python >=3.7
- scipy>1.7
- numpy >=1.18
- matplotlib >=3.0
- scikit-image >=0.17
- python >=3.10
- scipy>1.10
- numpy >=1.22
- matplotlib >=3.6
- scikit-image >=0.19
- h5py
- cycler >=0.10.0
- filemagic >=1.6
- image-registration >=0.2.1
- lmfit >=0.9.7
- lmfit >=1.0
- memoization >=0.1.4
- npTDMS >=0.11
- python-dateutil >=2.7.0
Expand Down
7 changes: 6 additions & 1 deletion tests/Stoner/tools/test_widgets.py
Expand Up @@ -21,7 +21,7 @@
from Stoner import Data, DataFolder


def test_filedialog():
def _fix_widgets():
def dummy(mode="getOpenFileName"):
modes = {
"getOpenFileName": ret_pth,
Expand Down Expand Up @@ -57,6 +57,10 @@ def dummy(mode="getOpenFileName"):
widgets = sys.modules["Stoner.tools.widgets"]
app = getattr(widgets, "App")
setattr(app, "modes", modes)
return widgets

def test_filedialog():
widgets=_fix_widgets()

assert widgets.fileDialog.openDialog() == ret_pth
assert widgets.fileDialog.openDialog(title="Test", start=".") == ret_pth
Expand All @@ -69,6 +73,7 @@ def dummy(mode="getOpenFileName"):


def test_loader():
_fix_widgets()
d = Data(False)
assert d.shape == (1676, 3), "Failed to load data with dialog box"
with pytest.raises(RuntimeError):
Expand Down

0 comments on commit 6c5b9ce

Please sign in to comment.