MINOR - Fallback for testsuite imports (#18710)

This commit is contained in:
Pere Miquel Brull 2024-11-20 17:31:48 +01:00 committed by GitHub
parent dc101044d9
commit 6623ab17dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 6 deletions

View File

@ -112,10 +112,14 @@ class BaseTestSuiteRunner:
entity=self.entity, metadata=self.ometa_client entity=self.entity, metadata=self.ometa_client
) )
test_suite_class = import_test_suite_class( test_suite_class = import_test_suite_class(
ServiceType.Database, source_type=self._interface_type ServiceType.Database,
source_type=self._interface_type,
source_config_type=self.service_conn_config.type.value,
) )
sampler_class = import_sampler_class( sampler_class = import_sampler_class(
ServiceType.Database, source_type=self._interface_type ServiceType.Database,
source_type=self._interface_type,
source_config_type=self.service_conn_config.type.value,
) )
# This is shared between the sampler and DQ interfaces # This is shared between the sampler and DQ interfaces
_orm = self._build_table_orm(self.entity) _orm = self._build_table_orm(self.entity)

View File

@ -14,6 +14,7 @@ from metadata.profiler.interface.profiler_interface import ProfilerInterface
from metadata.sampler.sampler_interface import SamplerInterface from metadata.sampler.sampler_interface import SamplerInterface
from metadata.utils.importer import ( from metadata.utils.importer import (
TYPE_SEPARATOR, TYPE_SEPARATOR,
DynamicImportException,
get_class_path, get_class_path,
get_module_dir, get_module_dir,
import_from_module, import_from_module,
@ -112,14 +113,34 @@ def import_profiler_class(
def import_test_suite_class( def import_test_suite_class(
service_type: ServiceType, source_type: str service_type: ServiceType,
source_type: str,
source_config_type: Optional[str] = None,
) -> Type[TestSuiteInterface]: ) -> Type[TestSuiteInterface]:
class_path = BaseSpec.get_for_source(service_type, source_type).test_suite_class try:
class_path = BaseSpec.get_for_source(service_type, source_type).test_suite_class
except DynamicImportException:
if source_config_type:
class_path = BaseSpec.get_for_source(
service_type, source_config_type.lower()
).test_suite_class
else:
raise
return cast(Type[TestSuiteInterface], import_from_module(class_path)) return cast(Type[TestSuiteInterface], import_from_module(class_path))
def import_sampler_class( def import_sampler_class(
service_type: ServiceType, source_type: str service_type: ServiceType,
source_type: str,
source_config_type: Optional[str] = None,
) -> Type[SamplerInterface]: ) -> Type[SamplerInterface]:
class_path = BaseSpec.get_for_source(service_type, source_type).sampler_class try:
class_path = BaseSpec.get_for_source(service_type, source_type).sampler_class
except DynamicImportException:
if source_config_type:
class_path = BaseSpec.get_for_source(
service_type, source_config_type.lower()
).sampler_class
else:
raise
return cast(Type[SamplerInterface], import_from_module(class_path)) return cast(Type[SamplerInterface], import_from_module(class_path))