Merge "[Tests] Ignore too long mock names"

This commit is contained in:
Jenkins 2016-09-12 11:49:16 +00:00 committed by Gerrit Code Review
commit c10c5f9c88
2 changed files with 18 additions and 16 deletions

View File

@ -63,27 +63,20 @@ class MuranoEnvironmentGeneratorTestCase(test.TestCase):
}
@mock.patch("%s.murano.utils.MuranoScenario._create_environment" % SCN)
def test_setup(self, mock_murano_scenario__create_environment):
mock_env = mock.MagicMock()
mock_murano_scenario__create_environment.return_value = mock_env
def test_setup(self, mock_create_env):
murano_ctx = murano_environments.EnvironmentGenerator(
self._get_context())
murano_ctx.setup()
self.assertEqual(2, len(murano_ctx.context["tenants"]))
tenant_id = murano_ctx.context["users"][0]["tenant_id"]
self.assertEqual([mock_env],
self.assertEqual([mock_create_env.return_value],
murano_ctx.context["tenants"][tenant_id][
"environments"])
@mock.patch("%s.murano.utils.MuranoScenario._create_environment" % SCN)
@mock.patch("%s.resource_manager.cleanup" % CTX)
def test_cleanup(self, mock_cleanup,
mock_murano_scenario__create_environment):
mock_env = mock.Mock()
mock_murano_scenario__create_environment.return_value = mock_env
def test_cleanup(self, mock_cleanup, mock_create_env):
murano_ctx = murano_environments.EnvironmentGenerator(
self._get_context())
murano_ctx.setup()

View File

@ -90,6 +90,12 @@ class FuncMockArgsDecoratorsChecker(ast.NodeVisitor):
def test_foobar(self, mock_class_abc):
# must match the python-styled class name + method name
"""
# NOTE(amaretskiy): Disable check if shortest variant is too long
# because long name is not convenient and could
# even be blocked by PEP8
SHORTEST_VARIANT_LEN_LIMIT = 25
def __init__(self):
self.errors = []
self.globals_ = {}
@ -252,12 +258,15 @@ class FuncMockArgsDecoratorsChecker(ast.NodeVisitor):
for arg, dec_vars in six.moves.zip_longest(mock_args, mock_decs):
if not self.check_name(arg, dec_vars):
if arg and dec_vars:
sorted_by_len = sorted(
dec_vars.variants, key=lambda i: len(i), reverse=True)
shortest_name = sorted_by_len.pop()
if len(shortest_name) <= self.SHORTEST_VARIANT_LEN_LIMIT:
error_msgs.append(
("Argument '%(arg)s' misnamed; should be either of "
"%(dec)s that is derived from the mock decorator "
"args.\n") % {
"arg": arg, "dec": dec_vars}
)
("Argument '%(arg)s' misnamed; should be either "
"of %(dec)s that is derived from the mock "
"decorator args.\n") % {"arg": arg,
"dec": dec_vars})
elif not arg:
error_msgs.append(
"Missing or malformed argument for %s decorator."