chore: replace `imp` built-in module usage for future Python3.12 usage (#31622)
Signed-off-by: hainenber <dotronghai96@gmail.com> Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
This commit is contained in:
parent
109e6c69ff
commit
5484db34f9
|
|
@ -18,7 +18,7 @@
|
||||||
"""Unit tests for Superset"""
|
"""Unit tests for Superset"""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import imp
|
from importlib.util import find_spec
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from typing import Any, Union, Optional
|
from typing import Any, Union, Optional
|
||||||
from unittest.mock import Mock, patch, MagicMock
|
from unittest.mock import Mock, patch, MagicMock
|
||||||
|
|
@ -256,11 +256,11 @@ class SupersetTestCase(TestCase):
|
||||||
return db.session.query(SqlaTable).filter_by(id=table_id).one()
|
return db.session.query(SqlaTable).filter_by(id=table_id).one()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_module_installed(module_name):
|
def is_module_installed(module_name: str) -> bool:
|
||||||
try:
|
try:
|
||||||
imp.find_module(module_name)
|
spec = find_spec(module_name)
|
||||||
return True
|
return spec is not None
|
||||||
except ImportError:
|
except (ModuleNotFoundError, ValueError, TypeError, ImportError):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_or_create(self, cls, criteria, **kwargs):
|
def get_or_create(self, cls, criteria, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue