Skip to content
Snippets Groups Projects
Commit d4b109ce authored by Sebastian Müller's avatar Sebastian Müller 🐈
Browse files

Component: don't require to overwrite _validate or _finalize

parent 8db78a62
No related branches found
No related tags found
1 merge request!156Component: don't require to overwrite _validate or _finalize
Pipeline #126286 passed with stages
in 2 minutes and 55 seconds
......@@ -116,11 +116,9 @@ class Component(IComponent, Loggable, ABC):
def _validate(self):
"""Validate the correctness of the component's settings and coupling.
Components must overwrite this method.
Components should overwrite this method.
"""
raise NotImplementedError(
f"Method `_validate` must be implemented by all components, but implementation is missing in {self.name}."
)
self.logger.debug("Method `_validate` not implemented by user.")
@final
def update(self):
......@@ -163,11 +161,9 @@ class Component(IComponent, Loggable, ABC):
def _finalize(self):
"""Finalize and clean up the component.
Components must overwrite this method.
Components should overwrite this method.
"""
raise NotImplementedError(
f"Method `_finalize` must be implemented by all components, but implementation is missing in {self.name}."
)
self.logger.debug("Method `_finalize` not implemented by user.")
@property
def inputs(self):
......
"""
Unit tests for the sdk implementations.
"""
import logging
import unittest
from datetime import datetime
......@@ -466,20 +467,32 @@ class TestNotImplemented(unittest.TestCase):
with self.assertRaises(NotImplementedError):
comp._connect()
with self.assertRaises(NotImplementedError):
# check that the debug log for not implementing _validate is there
with self.assertLogs(level=logging.DEBUG) as captured:
comp.validate()
with self.assertRaises(NotImplementedError):
self.assertEqual(len(captured.records), 2)
self.assertEqual(captured.records[0].levelno, logging.DEBUG)
self.assertEqual(captured.records[1].levelno, logging.DEBUG)
with self.assertLogs(level=logging.DEBUG) as captured:
comp._validate()
self.assertEqual(len(captured.records), 1)
self.assertEqual(captured.records[0].levelno, logging.DEBUG)
with self.assertRaises(NotImplementedError):
comp.update()
with self.assertRaises(NotImplementedError):
comp._update()
with self.assertRaises(NotImplementedError):
# check that the debug log for not implementing _finalize is there
with self.assertLogs(level=logging.DEBUG) as captured:
comp.finalize()
with self.assertRaises(NotImplementedError):
self.assertEqual(len(captured.records), 2)
self.assertEqual(captured.records[0].levelno, logging.DEBUG)
self.assertEqual(captured.records[1].levelno, logging.DEBUG)
with self.assertLogs(level=logging.DEBUG) as captured:
comp._finalize()
self.assertEqual(len(captured.records), 1)
self.assertEqual(captured.records[0].levelno, logging.DEBUG)
def test_adapter_not_implemented(self):
adapter = NotImplAdapter()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment