Skip to content

Commit

Permalink
Cleaned up module wildcard imports in pywbem_mock
Browse files Browse the repository at this point in the history
Details:

* Some pywbem_mock submodules were missing the '__all__' variable. This caused
  all names defined in and imported into the submodule to become visible in
  the 'pywbem_mock' namespace, which is undesirable.
  Added '__all__' where missing, with only the intended public names.

* Fixed use of incorrectly imported names in unit tests, that were used
  from the 'pywbem_mock' namespace. Used them from their defining submodules.

* Added import of the 'config' submodule into the 'pywbem_mock' namespace,
  in order to make sure that it is impoirted only once wnd that config variables
  can be modified.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Jun 19, 2022
1 parent 3a9f88b commit 3d600a5
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 7 deletions.
8 changes: 7 additions & 1 deletion pywbem_mock/__init__.py
Expand Up @@ -23,6 +23,13 @@

from __future__ import absolute_import

# The config namespace is imported as a sub-namespace to make the config
# variables accessible directly via their defining namespace. Importing
# them into the pywbem_mock namespace would duplicate their names and thus
# would cause changes to the config variables not to be visible in their
# original namespace.
from . import config # noqa: F401

from ._wbemconnection_mock import * # noqa: F403,F401
from ._dmtf_cim_schema import * # noqa: F403,F401
from ._resolvermixin import * # noqa: F403,F401
Expand All @@ -38,5 +45,4 @@
from ._methodprovider import * # noqa: F403,F401
from ._namespaceprovider import * # noqa: F403,F401
from ._subscriptionproviders import * # noqa: F403,F401

from ._utils import * # noqa: F403,F401
2 changes: 2 additions & 0 deletions pywbem_mock/_baseprovider.py
Expand Up @@ -46,6 +46,8 @@
# pywbem_mock implementation configuration variables that are used in
# request responsders.

__all__ = ['BaseProvider']


class BaseProvider(object):
"""
Expand Down
2 changes: 2 additions & 0 deletions pywbem_mock/_baserepository.py
Expand Up @@ -48,6 +48,8 @@
from abc import abstractmethod, abstractproperty
from six import PY2

__all__ = ['BaseObjectStore', 'BaseRepository']


def compatibleabstractproperty(func):
"""
Expand Down
1 change: 1 addition & 0 deletions pywbem_mock/_mainprovider.py
Expand Up @@ -73,6 +73,7 @@
# The following config items only apply to open/pull operations
from .config import DEFAULT_MAX_OBJECT_COUNT, OPEN_MAX_TIMEOUT

__all__ = ['MainProvider']

# per DSP0200, the default behavior for EnumerateInstance DeepInheritance
# if not set by in the client request. Default is True so that the mock server
Expand Down
2 changes: 2 additions & 0 deletions pywbem_mock/_mockmofwbemconnection.py
Expand Up @@ -34,6 +34,8 @@
from pywbem._utils import _format
from ._resolvermixin import ResolverMixin

__all__ = []


class _MockMOFWBEMConnection(ResolverMixin, BaseRepositoryConnection):
"""
Expand Down
1 change: 0 additions & 1 deletion pywbem_mock/_namespaceprovider.py
Expand Up @@ -40,7 +40,6 @@
from .config import OBJECTMANAGERNAME, SYSTEMNAME, SYSTEMCREATIONCLASSNAME, \
OBJECTMANAGERCREATIONCLASSNAME


__all__ = ['CIMNamespaceProvider']

# CIM class name of the namespace class implemented in this provider
Expand Down
2 changes: 2 additions & 0 deletions pywbem_mock/_providerdispatcher.py
Expand Up @@ -52,6 +52,8 @@
from ._instancewriteprovider import InstanceWriteProvider
from ._methodprovider import MethodProvider

__all__ = ['ProviderDispatcher']


class ProviderDispatcher(BaseProvider):
"""
Expand Down
2 changes: 2 additions & 0 deletions pywbem_mock/_resolvermixin.py
Expand Up @@ -45,6 +45,8 @@

from pywbem._utils import _format

__all__ = []


class ResolverMixin(object): # pylint: disable=too-few-public-methods
"""
Expand Down
3 changes: 3 additions & 0 deletions pywbem_mock/_subscriptionproviders.py
Expand Up @@ -52,6 +52,9 @@
from ._instancewriteprovider import InstanceWriteProvider
from .config import SYSTEMNAME, SYSTEMCREATIONCLASSNAME

__all__ = ['CIMIndicationFilterProvider', 'CIMListenerDestinationProvider',
'CIMIndicationSubscriptionProvider']

# CIM class name of the classes implemented in these providers
SUBSCRIPTION_CLASSNAME = 'CIM_IndicationSubscription'
FILTER_CLASSNAME = 'CIM_IndicationFilter'
Expand Down
2 changes: 2 additions & 0 deletions pywbem_mock/_utils.py
Expand Up @@ -30,6 +30,8 @@

import six

__all__ = []

STDOUT_ENCODING = getattr(sys.stdout, 'encoding', None)
if not STDOUT_ENCODING:
STDOUT_ENCODING = locale.getpreferredencoding()
Expand Down
1 change: 0 additions & 1 deletion pywbem_mock/_wbemconnection_mock.py
Expand Up @@ -37,7 +37,6 @@
# from mock import Mock
import six


from pywbem import WBEMConnection, CIMClass, CIMClassName, \
CIMInstance, CIMInstanceName, CIMParameter, CIMQualifierDeclaration, \
cimtype, CIMError, CIM_ERR_FAILED, DEFAULT_NAMESPACE, MOFCompiler, \
Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/pywbem/test_subscriptionmanager.py
Expand Up @@ -39,7 +39,7 @@
CIMInstance, CIMDateTime, CIMError, CIM_ERR_ALREADY_EXISTS # noqa: E402
from pywbem._subscription_manager import SUBSCRIPTION_CLASSNAME, \
DESTINATION_CLASSNAME, FILTER_CLASSNAME # noqa: E402
from pywbem_mock import OBJECTMANAGERNAME, \
from pywbem_mock.config import OBJECTMANAGERNAME, \
SYSTEMNAME # noqa: E402
pywbem_mock = import_installed('pywbem_mock')
# pylint: enable=wrong-import-position, wrong-import-order, invalid-name
Expand Down
5 changes: 3 additions & 2 deletions tests/unittest/pywbem_mock/test_wbemconnection_mock.py
Expand Up @@ -79,8 +79,9 @@

pywbem_mock = import_installed('pywbem_mock')
from pywbem_mock import FakedWBEMConnection, DMTFCIMSchema, \
InstanceWriteProvider, MethodProvider, BaseProvider, \
IGNORE_INSTANCE_IQ_PARAM, IGNORE_INSTANCE_ICO_PARAM # noqa: E402
InstanceWriteProvider, MethodProvider, BaseProvider # noqa: E402
from pywbem_mock.config import IGNORE_INSTANCE_IQ_PARAM, \
IGNORE_INSTANCE_ICO_PARAM # noqa: E402
# pylint: enable=wrong-import-position, wrong-import-order, invalid-name


Expand Down
2 changes: 1 addition & 1 deletion tests/unittest/utils/wbemserver_mock.py
Expand Up @@ -16,7 +16,7 @@
CIMInstanceName # noqa: E402
pywbem_mock = import_installed('pywbem_mock')
from pywbem_mock import FakedWBEMConnection # noqa: E402
from pywbem_mock import OBJECTMANAGERCREATIONCLASSNAME, \
from pywbem_mock.config import OBJECTMANAGERCREATIONCLASSNAME, \
SYSTEMCREATIONCLASSNAME, OBJECTMANAGERNAME, \
SYSTEMNAME # noqa: E402
# pylint: enable=wrong-import-position, wrong-import-order, invalid-name
Expand Down

0 comments on commit 3d600a5

Please sign in to comment.