mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
20ed2c6bcf
* salt/cloud/__init__.py: remove repr formatting * salt/cloud/clouds/azurearm.py: remove repr formatting * salt/cloud/clouds/ec2.py: remove repr formatting * salt/cloud/clouds/profitbricks.py: remove repr formatting * salt/loader.py: remove repr formatting * salt/modules/win_file.py: remove repr formatting * salt/modules/zypper.py: remove repr formatting * salt/pillar/consul_pillar.py: remove repr formatting * salt/renderers/pyobjects.py: remove repr formatting * salt/returners/sentry_return.py: remove repr formatting * salt/states/bower.py: remove repr formatting * salt/states/cabal.py: remove repr formatting * salt/states/cmd.py: remove repr formatting * salt/states/composer.py: remove repr formatting * salt/states/win_network.py: remove repr formatting * salt/states/eselect.py: remove repr formatting * salt/states/file.py: remove repr formatting * salt/states/htpasswd.py: remove repr formatting * salt/states/memcached.py: remove repr formatting * salt/states/npm.py: remove repr formatting * salt/states/pip_state.py: remove repr formatting * salt/states/pkg.py: remove repr formatting * salt/states/pkgrepo.py: remove repr formatting * salt/states/supervisord.py: remove repr formatting * salt/states/timezone.py: remove repr formatting * salt/states/virtualenv_mod.py: remove repr formatting * salt/states/dockerio.py: remove repr formatting * salt/states/win_system.py: remove repr formatting * salt/utils/nb_popen.py: remove repr formatting * salt/utils/cloud.py: remove repr formatting * Add pylint disable due to legit usage of repr flag See https://github.com/saltstack/salt-pylint/pull/6 * Fix composer tests These tests needed to be updated because quoting was changed in the state module in 9dc9146. There was an unnecessary !r used for the exception class there, which means that instead of the exception class being passed through the formatter and coming out with the equivalent value of err.__str__(), we get a repr'ed instance of the exception class (i.e. SaltException('',)) in the state output. The unit test was asserting that we have that repr'ed instance of SaltException in the output, a case of writing the test to confirm the badly-conceived output in the state. This has also been corrected. * salt/cloud/clouds/azurearm.py: lint fixes * salt/modules/boto_s3_bucket.py: lint fixes * salt/modules/minion.py: lint fixes * salt/modules/reg.py: lint fixes * salt/modules/testinframod.py: lint fixes * salt/modules/win_iis.py: lint fixes * salt/pillar/csvpillar.py: lint fixes * salt/utils/win_functions.py: lint fixes * salt/states/nxos.py: lint fixes * salt/returners/mongo_future_return.py: lint fixes * tests/integration/__init__.py: lint fixes * tests/unit/context_test.py: lint fixes * tests/integration/states/file.py: lint fixes * tests/integration/utils/test_reactor.py: lint fixes * tests/integration/utils/testprogram.py: lint fixes * tests/unit/__init__.py: lint fixes * tests/integration/shell/minion.py: lint fixes * tests/unit/modules/boto_apigateway_test.py: lint fixes * tests/unit/modules/boto_cognitoidentity_test.py: lint fixes * tests/unit/modules/boto_elasticsearch_domain_test.py: lint fixes * tests/unit/modules/k8s_test.py: lint fixes * tests/unit/modules/reg_win_test.py: lint fixes * tests/unit/states/boto_apigateway_test.py: lint fixes * tests/unit/states/boto_cognitoidentity_test.py: lint fixes * tests/unit/states/boto_elasticsearch_domain_test.py: lint fixes
80 lines
2.0 KiB
Python
80 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
'''
|
|
A lightweight version of tests.integration for testing of unit tests
|
|
|
|
This test class will not import the salt minion, runner and config modules.
|
|
'''
|
|
from __future__ import absolute_import
|
|
from salttesting.case import TestCase
|
|
from salttesting.parser import SaltTestcaseParser
|
|
|
|
__all__ = ['run_tests', 'ModuleTestCase']
|
|
|
|
|
|
def run_tests(*test_cases, **kwargs):
|
|
'''
|
|
Run unit tests for the chosen test cases.
|
|
|
|
:param test_cases: The list of test cases to execute
|
|
:type test_cases: ``list`` of :class:`TestCase`
|
|
'''
|
|
parser = SaltTestcaseParser()
|
|
parser.parse_args()
|
|
for case in test_cases:
|
|
if parser.run_testcase(case) is False:
|
|
parser.finalize(1)
|
|
parser.finalize(0)
|
|
|
|
|
|
def hasDependency(module, fake_module=None):
|
|
'''
|
|
Use this function in your test class setUp to
|
|
mock modules into your namespace
|
|
|
|
:param module: The module name
|
|
:type module: ``str``
|
|
|
|
:param fake_module: The module to inject into sys.modules
|
|
if not provided, a mock will be injected
|
|
:type fake_module: ``object``
|
|
|
|
..
|
|
hasDependency('super_module')
|
|
'''
|
|
import mock
|
|
import sys
|
|
if fake_module is None:
|
|
fake_module = mock.MagicMock()
|
|
sys.modules[module] = fake_module
|
|
|
|
|
|
class MockLoader(object):
|
|
'''
|
|
The default replacement for __salt__'s loader
|
|
class.
|
|
'''
|
|
def set_result(self, module, key, func):
|
|
if module.__salt__ is None:
|
|
module.__salt__ = {}
|
|
module.__salt__[key] = func
|
|
|
|
|
|
class ModuleTestCase(TestCase):
|
|
'''
|
|
A base class for test cases of execution modules
|
|
|
|
..
|
|
class MyModuleTestCase(ModuleTestCase):
|
|
def setUp(self):
|
|
self.setup_loader()
|
|
'''
|
|
# Set this class-level attribute to change
|
|
# the loader behavior
|
|
loaderCls = MockLoader
|
|
|
|
def setup_loader(self):
|
|
'''
|
|
Instantiate a loader to your test case
|
|
'''
|
|
self.loader = self.loaderCls()
|