From ec870b66370fe5f918bca138a387f34c2c41429e Mon Sep 17 00:00:00 2001 From: Ashley Anderson Date: Wed, 23 Nov 2022 20:54:55 -0500 Subject: [PATCH 1/4] Fix PackageMetadata validation error with extra provided key (should be ignored) --- npe2/manifest/_package_metadata.py | 6 +++++- tests/test_package_meta.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/npe2/manifest/_package_metadata.py b/npe2/manifest/_package_metadata.py index fdb3fb87..d2af3c13 100644 --- a/npe2/manifest/_package_metadata.py +++ b/npe2/manifest/_package_metadata.py @@ -174,7 +174,11 @@ class Config: def _validate_root(cls, values): if "metadata_version" not in values: fields = cls.__fields__ - mins = {fields[n].field_info.extra.get("min_ver", "1.0") for n in values} + mins = { + fields[n].field_info.extra.get("min_ver", "1.0") + for n in values + if n in fields + } values["metadata_version"] = str(max(float(x) for x in mins)) return values diff --git a/tests/test_package_meta.py b/tests/test_package_meta.py index 5b178909..3f3a72b4 100644 --- a/tests/test_package_meta.py +++ b/tests/test_package_meta.py @@ -17,3 +17,24 @@ def test_package_metadata_version(): def test_hashable(): hash(PackageMetadata(name="test", version="1.0")) + + +def test_package_metadata_extra_keys(): + pkg = { + "name": "test", + "version": "1.0", + "maintainer": "bob", + "extra_key_that_is_definitely_not_in_the_model": False, + } + + try: + p = PackageMetadata(**pkg) + except Exception: + raise AssertionError( + "failed to parse PackageMetadata from a dict with an extra key" + ) + + assert p.name == "test" + assert p.version == "1.0" + assert p.maintainer == "bob" + assert not hasattr(p, "extra_key_that_is_definitely_not_in_the_model") From 9aa92c53ab494a860fa7cc02688df9b2206f2422 Mon Sep 17 00:00:00 2001 From: Ashley Anderson Date: Wed, 23 Nov 2022 21:04:59 -0500 Subject: [PATCH 2/4] Rename key -> field --- tests/test_package_meta.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_package_meta.py b/tests/test_package_meta.py index 3f3a72b4..fab9f823 100644 --- a/tests/test_package_meta.py +++ b/tests/test_package_meta.py @@ -19,22 +19,22 @@ def test_hashable(): hash(PackageMetadata(name="test", version="1.0")) -def test_package_metadata_extra_keys(): +def test_package_metadata_extra_field(): pkg = { "name": "test", "version": "1.0", "maintainer": "bob", - "extra_key_that_is_definitely_not_in_the_model": False, + "extra_field_that_is_definitely_not_in_the_model": False, } try: p = PackageMetadata(**pkg) except Exception: raise AssertionError( - "failed to parse PackageMetadata from a dict with an extra key" + "failed to parse PackageMetadata from a dict with an extra field" ) assert p.name == "test" assert p.version == "1.0" assert p.maintainer == "bob" - assert not hasattr(p, "extra_key_that_is_definitely_not_in_the_model") + assert not hasattr(p, "extra_field_that_is_definitely_not_in_the_model") From 60cdb1d42a81d73c1ff0a809a65f735318683556 Mon Sep 17 00:00:00 2001 From: Gonzalo Pena-Castellanos Date: Fri, 25 Nov 2022 15:05:01 -0500 Subject: [PATCH 3/4] Add pyside6 to tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70067bf4..d335e62f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: python -m pip install -e ./napari-from-github python -m pip install -e .[json] # bare minimum required to test napari/plugins - python -m pip install pytest scikit-image[data] zarr xarray hypothesis matplotlib + python -m pip install pytest scikit-image[data] zarr xarray hypothesis matplotlib pyside6 - name: Run napari plugin headless tests run: pytest -W 'ignore::DeprecationWarning' napari/plugins napari/settings napari/layers napari/components From 01fa689f4d8da0ebd1e97867f9d4e5c8c9f5be42 Mon Sep 17 00:00:00 2001 From: Ashley Anderson Date: Mon, 28 Nov 2022 19:08:42 -0500 Subject: [PATCH 4/4] Revert "Add pyside6 to tests" This reverts commit cf639c23790d4ea22dc2b44e5eaf9c4ff78d56e3. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d335e62f..70067bf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: python -m pip install -e ./napari-from-github python -m pip install -e .[json] # bare minimum required to test napari/plugins - python -m pip install pytest scikit-image[data] zarr xarray hypothesis matplotlib pyside6 + python -m pip install pytest scikit-image[data] zarr xarray hypothesis matplotlib - name: Run napari plugin headless tests run: pytest -W 'ignore::DeprecationWarning' napari/plugins napari/settings napari/layers napari/components