diff --git a/src/pyMetricCli/__main__.py b/src/pyMetricCli/__main__.py index fb816bc..e759fb6 100644 --- a/src/pyMetricCli/__main__.py +++ b/src/pyMetricCli/__main__.py @@ -135,28 +135,9 @@ def _import_adapter(adapter_path: str) -> AdapterInterface: adapter_instance = adapter.Adapter() # Check all required attributes and methods of the adapter class. - # Must be done as Python does not enforce interfaces. if not isinstance(adapter_instance, AdapterInterface): LOG.error("The adapter class must inherit from AdapterInterface.") adapter_instance = None - elif not hasattr(adapter_instance, "output"): - LOG.error("The adapter class must have an 'output' attribute.") - adapter_instance = None - elif not hasattr(adapter_instance, "jira_config"): - LOG.error("The adapter class must have a 'jira_config' attribute.") - adapter_instance = None - elif not hasattr(adapter_instance, "polarion_config"): - LOG.error("The adapter class must have a 'polarion_config' attribute.") - adapter_instance = None - elif not hasattr(adapter_instance, "superset_config"): - LOG.error("The adapter class must have a 'superset_config' attribute.") - adapter_instance = None - elif not hasattr(adapter_instance, "handle_jira"): - LOG.error("The adapter class must have a 'handle_jira' method.") - adapter_instance = None - elif not hasattr(adapter_instance, "handle_polarion"): - LOG.error("The adapter class must have a 'handle_polarion' method.") - adapter_instance = None else: LOG.info("Adapter class successfully imported.") diff --git a/src/pyMetricCli/adapter_interface.py b/src/pyMetricCli/adapter_interface.py index ad96c07..42fe221 100644 --- a/src/pyMetricCli/adapter_interface.py +++ b/src/pyMetricCli/adapter_interface.py @@ -33,6 +33,8 @@ # Imports ################################################################################ +from abc import ABC, abstractmethod + ################################################################################ # Variables ################################################################################ @@ -42,16 +44,51 @@ ################################################################################ -class AdapterInterface(): +class AdapterInterface(ABC): """ Adapter interface class for handling different search results. """ - output: dict - jira_config: dict - polarion_config: dict - superset_config: dict + @property + @abstractmethod + def output(self) -> dict: + """ + Output dictionary. + """ + + @property + @abstractmethod + def jira_config(self) -> dict: + """ + JIRA configuration. + """ + @property + @abstractmethod + def polarion_config(self) -> dict: + """ + Polarion configuration. + """ + @property + @abstractmethod + def superset_config(self) -> dict: + """ + Superset configuration. + """ + + def __init__(self) -> None: + """ + Initializes the adapter. + Must be called after the definition of the properties. + """ + assert isinstance(self.output, dict), "output must be a dictionary" + assert isinstance(self.jira_config, + dict), "jira_config must be a dictionary" + assert isinstance(self.polarion_config, + dict), "polarion_config config must be a dictionary" + assert isinstance(self.superset_config, + dict), "superset_config config must be a dictionary" + @abstractmethod def handle_jira(self, _search_results: dict) -> bool: """ Handles the JIRA search results. @@ -62,8 +99,8 @@ def handle_jira(self, _search_results: dict) -> bool: Returns: bool: True if the search results were handled successfully, False otherwise. """ - return False + @abstractmethod def handle_polarion(self, _search_results: dict) -> bool: """ Handles the Polarion search results. @@ -74,7 +111,6 @@ def handle_polarion(self, _search_results: dict) -> bool: Returns: bool: True if the search results were handled successfully, False otherwise. """ - return False ################################################################################ # Functions