test_module_import_helper.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. from core.helper.module_import_helper import import_module_from_source, load_single_subclass_from_source
  3. from tests.integration_tests.utils.parent_class import ParentClass
  4. def test_loading_subclass_from_source():
  5. current_path = os.getcwd()
  6. module = load_single_subclass_from_source(
  7. module_name="ChildClass", script_path=os.path.join(current_path, "child_class.py"), parent_type=ParentClass
  8. )
  9. assert module and module.__name__ == "ChildClass"
  10. def test_load_import_module_from_source():
  11. current_path = os.getcwd()
  12. module = import_module_from_source(
  13. module_name="ChildClass", py_file_path=os.path.join(current_path, "child_class.py")
  14. )
  15. assert module and module.__name__ == "ChildClass"
  16. def test_lazy_loading_subclass_from_source():
  17. current_path = os.getcwd()
  18. clz = load_single_subclass_from_source(
  19. module_name="LazyLoadChildClass",
  20. script_path=os.path.join(current_path, "lazy_load_class.py"),
  21. parent_type=ParentClass,
  22. use_lazy_loader=True,
  23. )
  24. instance = clz("dify")
  25. assert instance.get_name() == "dify"