diff --git a/mmif/serialize/mmif.py b/mmif/serialize/mmif.py index e8957682..004be991 100644 --- a/mmif/serialize/mmif.py +++ b/mmif/serialize/mmif.py @@ -868,7 +868,4 @@ def __getitem__(self, item: str) -> Union[Document, View, Annotation, MmifMetada ret = self.views._items.get(item) if ret is None: raise KeyError(f"Object with ID {item} not found in the MMIF object. ") - else: - return ret - else: - return ret + return ret diff --git a/mmif/serialize/model.py b/mmif/serialize/model.py index 3c5e6986..b052b0fb 100644 --- a/mmif/serialize/model.py +++ b/mmif/serialize/model.py @@ -337,14 +337,14 @@ def __contains__(self, key: str) -> bool: try: self.__getitem__(key) return True - except (TypeError, AttributeError, KeyError): + except (TypeError, KeyError): return False def __getitem__(self, key) -> Any: if key in self._named_attributes(): value = self.__dict__[key] elif self._unnamed_attributes is None: - raise AttributeError(f"Additional properties are disallowed by {self.__class__}: {key}") + raise KeyError(f"Additional properties are disallowed by {self.__class__}: {key}") else: value = self._unnamed_attributes[key] if key not in self._required_attributes and self.is_empty(value): diff --git a/tests/mmif_examples.py b/tests/mmif_examples.py index 7e860c0a..b19f9d9a 100644 --- a/tests/mmif_examples.py +++ b/tests/mmif_examples.py @@ -1,6 +1,7 @@ import itertools import os import subprocess +from pathlib import Path from string import Template from urllib import request @@ -20,8 +21,11 @@ def _load_from_url_or_git(url): If LOCALMMIF env var is set, use git show to load from local repo. LOCALMMIF should be the path to the local mmif repository. """ - localmmif = os.environ.get('LOCALMMIF') - if localmmif: + localmmif_str = os.environ.get('LOCALMMIF') + if localmmif_str: + localmmif = Path(localmmif_str) + if not localmmif.is_dir(): + raise ValueError(f"LOCALMMIF path is not a valid directory: {localmmif}") # Extract the version/branch and file path from the URL # URL format: https://raw.githubusercontent.com/clamsproject/mmif/{version}/{filepath} url_prefix = "https://raw.githubusercontent.com/clamsproject/mmif/" @@ -35,7 +39,7 @@ def _load_from_url_or_git(url): try: result = subprocess.run( ['git', 'show', git_ref], - cwd=localmmif, + cwd=str(localmmif), capture_output=True, text=True, check=True