test_import_utils.py 467 B

123456789101112131415161718192021222324
  1. from abc import abstractmethod
  2. from dataclasses import dataclass
  3. from openhands.utils.import_utils import get_impl
  4. class Shape:
  5. @abstractmethod
  6. def get_area(self):
  7. """Get the area of this shape"""
  8. @dataclass
  9. class Square(Shape):
  10. length: float
  11. def get_area(self):
  12. return self.length**2
  13. def test_get_impl():
  14. ShapeImpl = get_impl(Shape, f'{Shape.__module__}.Square')
  15. shape = ShapeImpl(5)
  16. assert shape.get_area() == 25