# Path: os_win/tests/unit/test_base.py
# class TestingException(Exception):
# class FakeWMIExc(exceptions.x_wmi):
# class BaseTestCase(base.BaseTestCase):
# class OsWinBaseTestCase(BaseTestCase):
#     def __init__(self, hresult=None):
#     def setUp(self):
#     def _patch_autospec_classes(self):
#     def setUp(self):
# 
# Path: os_win/utils/baseutils.py
# LOG = logging.getLogger(__name__)
#     _WMI_CONS = {}
# class BaseUtils(object):
# class BaseUtilsVirt(BaseUtils):
# class SynchronizedMeta(type):
#     def _get_wmi_obj(self, moniker, **kwargs):
#     def _get_wmi_conn(self, moniker, **kwargs):
#     def __init__(self, host='.'):
#     def _conn(self):
#     def _compat_conn(self):
#     def _vs_man_svc(self):
#     def _get_wmi_compat_conn(self, moniker, **kwargs):
#     def _get_wmi_obj(self, moniker, compatibility_mode=False, **kwargs):
#     def __init__(cls, cls_name, bases, attrs):
#     def _synchronize(func, cls_name, rlock):
#         def wrapper(*args, **kwargs):


from unittest import mock
from os_win.tests.unit import test_base
from os_win.utils import baseutils
import six
import importlib
    def test_vs_man_svc_2012(self, mock_wmi):
        baseutils.BaseUtilsVirt._old_wmi = None
        mock_os = mock.MagicMock(Version='6.2.0')
        mock_wmi.WMI.return_value.Win32_OperatingSystem.return_value = [
            mock_os]
        fake_module_path = '/fake/path/to/module'
        mock_wmi.__path__ = [fake_module_path]

        spec = importlib.util.spec_from_file_location.return_value
        module = importlib.util.module_from_spec.return_value
        old_conn = module.WMI.return_value

        expected = old_conn.Msvm_VirtualSystemManagementService()[0]
        self.assertEqual(expected, self.utils._vs_man_svc)
        self.assertIsNone(self.utils._vs_man_svc_attr)
        importlib.util.spec_from_file_location.assert_called_once_with(
            'old_wmi', '%s.py' % fake_module_path)
        spec.loader.exec_module.assert_called_once_with(module)
        importlib.util.module_from_spec.assert_called_once_with(
            importlib.util.spec_from_file_location.return_value)

    @mock.patch.object(baseutils.BaseUtilsVirt, '_get_wmi_compat_conn')
    def test_get_wmi_obj_compatibility_6_3(self, mock_get_wmi_compat):
        mock_os = mock.MagicMock(Version='6.3.0')
        self._mock_wmi.WMI.return_value.Win32_OperatingSystem.return_value = [
            mock_os]

        result = self.utils._get_wmi_obj(mock.sentinel.moniker, True)
        self.assertEqual(self._mock_wmi.WMI.return_value, result)


# Path: os_win/tests/unit/test_base.py
# class TestingException(Exception):
# class FakeWMIExc(exceptions.x_wmi):
# class BaseTestCase(base.BaseTestCase):
# class OsWinBaseTestCase(BaseTestCase):
#     def __init__(self, hresult=None):
#     def setUp(self):
#     def _patch_autospec_classes(self):
#     def setUp(self):
# 
# Path: os_win/utils/baseutils.py
# LOG = logging.getLogger(__name__)
#     _WMI_CONS = {}
# class BaseUtils(object):
# class BaseUtilsVirt(BaseUtils):
# class SynchronizedMeta(type):
#     def _get_wmi_obj(self, moniker, **kwargs):
#     def _get_wmi_conn(self, moniker, **kwargs):
#     def __init__(self, host='.'):
#     def _conn(self):
#     def _compat_conn(self):
#     def _vs_man_svc(self):
#     def _get_wmi_compat_conn(self, moniker, **kwargs):
#     def _get_wmi_obj(self, moniker, compatibility_mode=False, **kwargs):
#     def __init__(cls, cls_name, bases, attrs):
#     def _synchronize(func, cls_name, rlock):
#         def wrapper(*args, **kwargs):


# Path: os_win/tests/unit/utils/test_baseutils.py
from unittest import mock
from os_win.tests.unit import test_base
from os_win.utils import baseutils
import six
import importlib

    def test_vs_man_svc_2012(self, mock_wmi):
        baseutils.BaseUtilsVirt._old_wmi = None
        mock_os = mock.MagicMock(Version='6.2.0')
        mock_wmi.WMI.return_value.Win32_OperatingSystem.return_value = [
            mock_os]
        fake_module_path = '/fake/path/to/module'
        mock_wmi.__path__ = [fake_module_path]

        spec = importlib.util.spec_from_file_location.return_value
        module = importlib.util.module_from_spec.return_value
        old_conn = module.WMI.return_value

        expected = old_conn.Msvm_VirtualSystemManagementService()[0]
        self.assertEqual(expected, self.utils._vs_man_svc)
        self.assertIsNone(self.utils._vs_man_svc_attr)
        importlib.util.spec_from_file_location.assert_called_once_with(
            'old_wmi', '%s.py' % fake_module_path)
        spec.loader.exec_module.assert_called_once_with(module)
        importlib.util.module_from_spec.assert_called_once_with(
            importlib.util.spec_from_file_location.return_value)

    @mock.patch.object(baseutils.BaseUtilsVirt, '_get_wmi_compat_conn')
    def test_get_wmi_obj_compatibility_6_3(self, mock_get_wmi_compat):
        mock_os = mock.MagicMock(Version='6.3.0')
        self._mock_wmi.WMI.return_value.Win32_OperatingSystem.return_value = [
            mock_os]

        result = self.utils._get_wmi_obj(mock.sentinel.moniker, True)
        self.assertEqual(self._mock_wmi.WMI.return_value, result)


    @mock.patch.object(baseutils.BaseUtilsVirt, '_get_wmi_compat_conn')