keystone.tests.unit.ksfixtures package¶
Submodules¶
keystone.tests.unit.ksfixtures.auth_plugins module¶
keystone.tests.unit.ksfixtures.backendloader module¶
keystone.tests.unit.ksfixtures.cache module¶
keystone.tests.unit.ksfixtures.database module¶
keystone.tests.unit.ksfixtures.hacking module¶
-
class
keystone.tests.unit.ksfixtures.hacking.
HackingCode
[source]¶ Bases:
fixtures.fixture.Fixture
A fixture to house the various code examples for the keystone hacking style checks.
-
asserting_none_equality
= {'code': "\n class Test(object):\n\n def test(self):\n self.assertEqual('', '')\n self.assertEqual('', None)\n self.assertEqual(None, '')\n self.assertNotEqual('', None)\n self.assertNotEqual(None, '')\n self.assertNotEqual('', None) # noqa\n self.assertNotEqual(None, '') # noqa\n ", 'expected_errors': [(5, 8, 'K003'), (6, 8, 'K003'), (7, 8, 'K004'), (8, 8, 'K004')]}¶
-
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 res[1].items()}\n fool = dict(a='a', b='b')\n lower_res = dict((k.lower(), v) for k, v in res[1].items())\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')]}¶
-
-
class
keystone.tests.unit.ksfixtures.hacking.
HackingLogging
[source]¶ Bases:
fixtures.fixture.Fixture
-
assert_no_translations_for_debug_logging
= {'code': "\n # stdlib logging\n L0 = logging.getLogger()\n L0.debug(_('text'))\n class C:\n def __init__(self):\n L0.debug(oslo_i18n('text', {}))\n\n # stdlib logging w/ alias and specifying a logger\n class C:\n def __init__(self):\n self.L1 = logging.getLogger(__name__)\n def m(self):\n self.L1.debug(\n _('text'), {}\n )\n\n # oslo logging and specifying a logger\n L2 = logging.getLogger(__name__)\n L2.debug(oslo_i18n('text'))\n\n # oslo logging w/ alias\n class C:\n def __init__(self):\n self.L3 = oslo_logging.getLogger()\n self.L3.debug(_('text'))\n\n # translation on a separate line\n msg = _('text')\n L2.debug(msg)\n\n # this should not fail\n if True:\n msg = _('message %s') % X\n L2.error(msg)\n raise TypeError(msg)\n if True:\n msg = 'message'\n L2.debug(msg)\n\n # this should not fail\n if True:\n if True:\n msg = _('message')\n else:\n msg = _('message')\n L2.debug(msg)\n raise Exception(msg)\n ", 'expected_errors': [(3, 9, 'K005'), (6, 17, 'K005'), (14, 12, 'K005'), (19, 9, 'K005'), (25, 22, 'K005'), (29, 9, 'K005')]}¶
-
assert_not_using_deprecated_warn
= {'code': "\n # Logger.warn has been deprecated in Python3 in favor of\n # Logger.warning\n LOG = log.getLogger(__name__)\n LOG.warn(_LW('text'))\n ", 'expected_errors': [(4, 9, 'K009')]}¶
-
examples
= [{'code': "\n # stdlib logging\n LOG = logging.getLogger()\n LOG.info(_('text'))\n class C:\n def __init__(self):\n LOG.warning(oslo_i18n('text', {}))\n LOG.warning(_LW('text', {}))\n ", 'expected_errors': [(3, 9, 'K006'), (6, 20, '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.warning(_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, 12, 'K006'), (7, 10, 'K005')]}, {'code': "\n # this should not be an error\n L = log.getLogger(__name__)\n msg = _('text')\n L.warning(msg)\n raise Exception(msg)\n ", 'expected_errors': []}, {'code': "\n L = log.getLogger(__name__)\n def f():\n msg = _('text')\n L2.warning(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.warning(msg)\n raise Exception('some other message')\n ", 'expected_errors': [(4, 16, 'K006')]}, {'code': "\n LOG = log.getLogger(__name__)\n if True:\n msg = _('text')\n else:\n msg = _('text')\n LOG.warning(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.warning(msg)\n ", 'expected_errors': [(6, 12, 'K006')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('text')\n LOG.warning(msg)\n raise Exception(msg)\n ", 'expected_errors': [(3, 12, 'K007')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('text')\n LOG.warning(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.warning(msg)\n raise Exception(msg)\n ", 'expected_errors': [(3, 12, 'K007')]}, {'code': "\n LOG = log.getLogger(__name__)\n msg = _LW('hello %s') % 'world'\n LOG.warning(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': []}, {'code': "\n # this should not be an error\n LOG = log.getLogger(__name__)\n try:\n pass\n except AssertionError as e:\n msg = _('some message')\n LOG.warning(msg)\n raise exception.Unauthorized(message=msg)\n ", 'expected_errors': []}, {'code': "\n # this should error since we are using _LW instead of _\n LOG = log.getLogger(__name__)\n try:\n pass\n except AssertionError as e:\n msg = _LW('some message')\n LOG.warning(msg)\n raise exception.Unauthorized(message=msg)\n ", 'expected_errors': [(7, 16, 'K007')]}]¶
-