test_module_import_helper.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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',
  8. script_path=os.path.join(current_path, 'child_class.py'),
  9. parent_type=ParentClass)
  10. assert module and module.__name__ == 'ChildClass'
  11. def test_load_import_module_from_source():
  12. current_path = os.getcwd()
  13. module = import_module_from_source(
  14. module_name='ChildClass',
  15. py_file_path=os.path.join(current_path, 'child_class.py'))
  16. assert module and module.__name__ == 'ChildClass'
  17. def test_lazy_loading_subclass_from_source():
  18. current_path = os.getcwd()
  19. clz = load_single_subclass_from_source(
  20. module_name='LazyLoadChildClass',
  21. script_path=os.path.join(current_path, 'lazy_load_class.py'),
  22. parent_type=ParentClass,
  23. use_lazy_loader=True)
  24. instance = clz('dify')
  25. assert instance.get_name() == 'dify'