Daniel Watkins be26dc7adc Add cloudinit.tests.util for shared testing code.
Starting with keeping the try/except to find mock on both Python 2 and
Python 3 in one place.

Change-Id: I4fa5e6e3f6610f6eb2601d4c3cb51d76565dd3c0
2015-06-05 18:11:50 +01:00

47 lines
1.6 KiB
Python

# Copyright (C) 2015 Canonical Ltd.
# Copyright 2015 Cloudbase Solutions Srl
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
from cloudinit.osys import base
from cloudinit.tests.util import mock
class TestOSUtils(unittest.TestCase):
@mock.patch('importlib.import_module')
@mock.patch('platform.linux_distribution')
@mock.patch('platform.system')
def _test_getosutils(self, mock_system,
mock_linux_distribution, mock_import_module,
linux=False):
if linux:
os_name = 'Linux'
else:
os_name = 'Windows'
mock_system.return_value = os_name
mock_linux_distribution.return_value = (os_name, None, None)
module = base.get_osutils()
mock_import_module.assert_called_once_with(
"cloudinit.osys.{0}.base".format(os_name.lower()))
self.assertEqual(mock_import_module.return_value.OSUtils,
module)
def test_getosutils(self):
self._test_getosutils(linux=True)
self._test_getosutils(linux=False)