comments_begin_with_space = {'code': "\n # This is a good comment\n\n #This is a bad one\n\n # This is alright and can\n # be continued with extra indentation\n # if that's what the developer wants.\n ", 'expected_errors': [(3, 0, 'K002')]}¶
dict_constructor = {'code': "\n lower_res = {k.lower(): v for k, v in six.iteritems(res[1])}\n fool = dict(a='a', b='b')\n lower_res = dict((k.lower(), v) for k, v in six.iteritems(res[1]))\n attrs = dict([(k, _from_json(v))])\n dict([[i,i] for i in range(3)])\n dict(({1:2}))\n ", 'expected_errors': [(3, 0, 'K008'), (4, 0, 'K008'), (5, 0, 'K008')]}¶
mutable_default_args = {'code': '\n def f():\n pass\n\n def f(a, b=\'\', c=None):\n pass\n\n def f(bad=[]):\n pass\n\n def f(foo, bad=[], more_bad=[x for x in range(3)]):\n pass\n\n def f(foo, bad={}):\n pass\n\n def f(foo, bad={}, another_bad=[], fine=None):\n pass\n\n def f(bad=[]): # noqa\n pass\n\n def funcs(bad=dict(), more_bad=list(), even_more_bad=set()):\n "creating mutables through builtins"\n\n def funcs(bad=something(), more_bad=some_object.something()):\n "defaults from any functions"\n\n def f(bad=set(), more_bad={x for x in range(3)},\n even_more_bad={1, 2, 3}):\n "set and set comprehession"\n\n def f(bad={x: x for x in range(3)}):\n "dict comprehension"\n ', 'expected_errors': [(7, 10, 'K001'), (10, 15, 'K001'), (10, 29, 'K001'), (13, 15, 'K001'), (16, 15, 'K001'), (16, 31, 'K001'), (22, 14, 'K001'), (22, 31, 'K001'), (22, 53, 'K001'), (25, 14, 'K001'), (25, 36, 'K001'), (28, 10, 'K001'), (28, 27, 'K001'), (29, 21, 'K001'), (32, 11, 'K001')]}¶
oslo_namespace_imports = {'code': '\n import oslo.utils\n import oslo_utils\n import oslo.utils.encodeutils\n import oslo_utils.encodeutils\n from oslo import utils\n from oslo.utils import encodeutils\n from oslo_utils import encodeutils\n\n import oslo.serialization\n import oslo_serialization\n import oslo.serialization.jsonutils\n import oslo_serialization.jsonutils\n from oslo import serialization\n from oslo.serialization import jsonutils\n from oslo_serialization import jsonutils\n\n import oslo.messaging\n import oslo_messaging\n import oslo.messaging.conffixture\n import oslo_messaging.conffixture\n from oslo import messaging\n from oslo.messaging import conffixture\n from oslo_messaging import conffixture\n\n import oslo.db\n import oslo_db\n import oslo.db.api\n import oslo_db.api\n from oslo import db\n from oslo.db import api\n from oslo_db import api\n\n import oslo.config\n import oslo_config\n import oslo.config.cfg\n import oslo_config.cfg\n from oslo import config\n from oslo.config import cfg\n from oslo_config import cfg\n\n import oslo.i18n\n import oslo_i18n\n import oslo.i18n.log\n import oslo_i18n.log\n from oslo import i18n\n from oslo.i18n import log\n from oslo_i18n import log\n ', 'expected_errors': [(1, 0, 'K333'), (3, 0, 'K333'), (5, 0, 'K333'), (6, 0, 'K333'), (9, 0, 'K333'), (11, 0, 'K333'), (13, 0, 'K333'), (14, 0, 'K333'), (17, 0, 'K333'), (19, 0, 'K333'), (21, 0, 'K333'), (22, 0, 'K333'), (25, 0, 'K333'), (27, 0, 'K333'), (29, 0, 'K333'), (30, 0, 'K333'), (33, 0, 'K333'), (35, 0, 'K333'), (37, 0, 'K333'), (38, 0, 'K333'), (41, 0, 'K333'), (43, 0, 'K333'), (45, 0, 'K333'), (46, 0, 'K333')]}¶
class keystone.tests.unit.ksfixtures.hacking.HackingLogging[source]¶
Bases: fixtures.fixture.Fixture
examples = [{'code': "\n # stdlib logging\n LOG = logging.getLogger()\n LOG.info(_('text'))\n class C:\n def __init__(self):\n LOG.warn(oslo_i18n('text', {}))\n LOG.warn(_LW('text', {}))\n ", 'expected_errors': [(3, 9, 'K006'), (6, 17, 'K006')]}, {'code': "\n # stdlib logging w/ alias and specifying a logger\n class C:\n def __init__(self):\n self.L = logging.getLogger(__name__)\n def m(self):\n self.L.warning(\n _('text'), {}\n )\n self.L.warning(\n _LW('text'), {}\n )\n ", 'expected_errors': [(7, 12, 'K006')]}, {'code': "\n # oslo logging and specifying a logger\n L = log.getLogger(__name__)\n L.error(oslo_i18n('text'))\n L.error(error_hint('text'))\n ", 'expected_errors': [(3, 8, 'K006')]}, {'code': "\n # oslo logging w/ alias\n class C:\n def __init__(self):\n self.LOG = oslo_logging.getLogger()\n self.LOG.critical(_('text'))\n self.LOG.critical(_LC('text'))\n ", 'expected_errors': [(5, 26, 'K006')]}, {'code': "\n LOG = log.getLogger(__name__)\n # translation on a separate line\n msg = _('text')\n LOG.exception(msg)\n msg = _LE('text')\n LOG.exception(msg)\n ", 'expected_errors': [(4, 14, 'K006')]}, {'code': "\n LOG = logging.getLogger()\n\n # ensure the correct helper is being used\n LOG.warn(_LI('this should cause an error'))\n\n # debug should not allow any helpers either\n LOG.debug(_LI('this should cause an error'))\n ", 'expected_errors': [(4, 9, 'K006'), (7, 10, 'K005')]}, {'code': "\n # this should not be an error\n L = log.getLogger(__name__)\n msg = _('text')\n L.warn(msg)\n raise Exception(msg)\n ", 'expected_errors': []}, {'code': "\n L = log.getLogger(__name__)\n def f():\n msg = _('text')\n L2.warn(msg)\n something = True # add an extra statement here\n raise Exception(msg)\n ", 'expected_errors': []}, {'code': "\n LOG = log.getLogger(__name__)\n def func():\n msg = _('text')\n LOG.warn(msg)\n raise Exception('some other message')\n ", 'expected_errors': [(4, 13, 'K006')]}, {'code': "\n LOG = log.getLogger(__name__)\n if True:\n msg = _('text')\n else:\n msg = _('text')\n LOG.warn(msg)\n raise Exception(msg)\n ", 'expected_errors': []}, {'code': "\n LOG = log.getLogger(__name__)\n if True:\n msg = _('text')\n else:\n msg = _('text')\n LOG.warn(msg)\n ", 'expected_errors': [(6, 9, 'K006')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('text')\n LOG.warn(msg)\n raise Exception(msg)\n ", 'expected_errors': [(3, 9, 'K007')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('text')\n LOG.warn(msg)\n msg = _('something else')\n raise Exception(msg)\n ", 'expected_errors': []}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('hello %s') % 'world'\n LOG.warn(msg)\n raise Exception(msg)\n ", 'expected_errors': [(3, 9, 'K007')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('hello %s') % 'world'\n LOG.warn(msg)\n ", 'expected_errors': []}, {'code': '\n # this should not be an error\n LOG = log.getLogger(__name__)\n try:\n something = True\n except AssertionError as e:\n LOG.warning(six.text_type(e))\n raise exception.Unauthorized(e)\n ', 'expected_errors': []}]¶
shared_imports = '\n import logging\n import logging as stlib_logging\n from keystone.i18n import _\n from keystone.i18n import _ as oslo_i18n\n from keystone.i18n import _LC\n from keystone.i18n import _LE\n from keystone.i18n import _LE as error_hint\n from keystone.i18n import _LI\n from keystone.i18n import _LW\n from keystone.openstack.common import log\n from keystone.openstack.common import log as oslo_logging\n '¶