mirror of https://github.com/django/django.git
Fixed #26125 -- Fixed E731 flake warnings.
This commit is contained in:
parent
abc0777b63
commit
60586dd737
|
@ -1,12 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Default Django settings. Override these with settings in the module pointed to
|
||||
by the DJANGO_SETTINGS_MODULE environment variable.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Default Django settings. Override these with settings in the module
|
||||
# pointed-to by the DJANGO_SETTINGS_MODULE environment variable.
|
||||
|
||||
# This is defined here as a do-nothing function because we can't import
|
||||
# django.utils.translation -- that module depends on the settings.
|
||||
gettext_noop = lambda s: s
|
||||
def gettext_noop(s):
|
||||
return s
|
||||
|
||||
####################
|
||||
# CORE #
|
||||
|
|
|
@ -143,7 +143,9 @@ def result_headers(cl):
|
|||
o_list_primary = [] # URL for making this field the primary sort
|
||||
o_list_remove = [] # URL for removing this field from sort
|
||||
o_list_toggle = [] # URL for toggling order type for this field
|
||||
make_qs_param = lambda t, n: ('-' if t == 'desc' else '') + str(n)
|
||||
|
||||
def make_qs_param(t, n):
|
||||
return ('-' if t == 'desc' else '') + str(n)
|
||||
|
||||
for j, ot in ordering_field_columns.items():
|
||||
if j == i: # Same column
|
||||
|
@ -341,7 +343,8 @@ def date_hierarchy(cl):
|
|||
month_lookup = cl.params.get(month_field)
|
||||
day_lookup = cl.params.get(day_field)
|
||||
|
||||
link = lambda filters: cl.get_query_string(filters, [field_generic])
|
||||
def link(filters):
|
||||
return cl.get_query_string(filters, [field_generic])
|
||||
|
||||
if not (year_lookup or month_lookup or day_lookup):
|
||||
# select appropriate start level
|
||||
|
|
|
@ -69,10 +69,12 @@ class KeysValidator(object):
|
|||
|
||||
|
||||
class RangeMaxValueValidator(MaxValueValidator):
|
||||
compare = lambda self, a, b: a.upper > b
|
||||
def compare(self, a, b):
|
||||
return a.upper > b
|
||||
message = _('Ensure that this range is completely less than or equal to %(limit_value)s.')
|
||||
|
||||
|
||||
class RangeMinValueValidator(MinValueValidator):
|
||||
compare = lambda self, a, b: a.lower < b
|
||||
def compare(self, a, b):
|
||||
return a.lower < b
|
||||
message = _('Ensure that this range is completely greater than or equal to %(limit_value)s.')
|
||||
|
|
|
@ -217,11 +217,15 @@ class HashedFilesMixin(object):
|
|||
hashed_files = OrderedDict()
|
||||
|
||||
# build a list of adjustable files
|
||||
matches = lambda path: matches_patterns(path, self._patterns.keys())
|
||||
adjustable_paths = [path for path in paths if matches(path)]
|
||||
adjustable_paths = [
|
||||
path for path in paths
|
||||
if matches_patterns(path, self._patterns.keys())
|
||||
]
|
||||
|
||||
# then sort the files by the directory level
|
||||
path_level = lambda name: len(name.split(os.sep))
|
||||
def path_level(name):
|
||||
return len(name.split(os.sep))
|
||||
|
||||
for name in sorted(paths.keys(), key=path_level, reverse=True):
|
||||
|
||||
# use the original, local file, not the copied-but-unprocessed
|
||||
|
|
|
@ -146,8 +146,7 @@ class BaseMemcachedCache(BaseCache):
|
|||
self._cache.set_multi(safe_data, self.get_backend_timeout(timeout))
|
||||
|
||||
def delete_many(self, keys, version=None):
|
||||
l = lambda x: self.make_key(x, version=version)
|
||||
self._cache.delete_multi(map(l, keys))
|
||||
self._cache.delete_multi(self.make_key(key, version=version) for key in keys)
|
||||
|
||||
def clear(self):
|
||||
self._cache.flush_all()
|
||||
|
|
|
@ -46,7 +46,8 @@ def make_style(config_string=''):
|
|||
format = color_settings.get(role, {})
|
||||
style_func = termcolors.make_style(**format)
|
||||
else:
|
||||
style_func = lambda x: x
|
||||
def style_func(x):
|
||||
return x
|
||||
setattr(style, role, style_func)
|
||||
|
||||
# For backwards compatibility,
|
||||
|
|
|
@ -32,8 +32,11 @@ class Command(BaseCommand):
|
|||
# 'table_name_filter' is a stealth option
|
||||
table_name_filter = options.get('table_name_filter')
|
||||
|
||||
table2model = lambda table_name: re.sub(r'[^a-zA-Z0-9]', '', table_name.title())
|
||||
strip_prefix = lambda s: s[1:] if s.startswith("u'") else s
|
||||
def table2model(table_name):
|
||||
return re.sub(r'[^a-zA-Z0-9]', '', table_name.title())
|
||||
|
||||
def strip_prefix(s):
|
||||
return s[1:] if s.startswith("u'") else s
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
yield "# This is an auto-generated Django model module."
|
||||
|
|
|
@ -365,8 +365,10 @@ class Command(BaseCommand):
|
|||
Check if the given path should be ignored or not.
|
||||
"""
|
||||
filename = os.path.basename(path)
|
||||
ignore = lambda pattern: (fnmatch.fnmatchcase(filename, pattern) or
|
||||
fnmatch.fnmatchcase(path, pattern))
|
||||
|
||||
def ignore(pattern):
|
||||
return fnmatch.fnmatchcase(filename, pattern) or fnmatch.fnmatchcase(path, pattern)
|
||||
|
||||
return any(ignore(pattern) for pattern in ignore_patterns)
|
||||
|
||||
ignore_patterns = [os.path.normcase(p) for p in self.ignore_patterns]
|
||||
|
|
|
@ -224,7 +224,10 @@ class Command(BaseCommand):
|
|||
if mig[0] == migration.app_label
|
||||
]
|
||||
merge_migrations.append(migration)
|
||||
all_items_equal = lambda seq: all(item == seq[0] for item in seq[1:])
|
||||
|
||||
def all_items_equal(seq):
|
||||
return all(item == seq[0] for item in seq[1:])
|
||||
|
||||
merge_migrations_generations = zip(*[m.ancestry for m in merge_migrations])
|
||||
common_ancestor_count = sum(1 for common_ancestor_generation
|
||||
in takewhile(all_items_equal, merge_migrations_generations))
|
||||
|
|
|
@ -70,9 +70,11 @@ class Serializer(base.Serializer):
|
|||
def handle_m2m_field(self, obj, field):
|
||||
if field.remote_field.through._meta.auto_created:
|
||||
if self.use_natural_foreign_keys and hasattr(field.remote_field.model, 'natural_key'):
|
||||
m2m_value = lambda value: value.natural_key()
|
||||
def m2m_value(value):
|
||||
return value.natural_key()
|
||||
else:
|
||||
m2m_value = lambda value: force_text(value._get_pk_val(), strings_only=True)
|
||||
def m2m_value(value):
|
||||
return force_text(value._get_pk_val(), strings_only=True)
|
||||
self._current[field.name] = [m2m_value(related)
|
||||
for related in getattr(obj, field.name).iterator()]
|
||||
|
||||
|
@ -136,7 +138,8 @@ def Deserializer(object_list, **options):
|
|||
else:
|
||||
return force_text(model._meta.pk.to_python(value), strings_only=True)
|
||||
else:
|
||||
m2m_convert = lambda v: force_text(model._meta.pk.to_python(v), strings_only=True)
|
||||
def m2m_convert(v):
|
||||
return force_text(model._meta.pk.to_python(v), strings_only=True)
|
||||
|
||||
try:
|
||||
m2m_data[field.name] = []
|
||||
|
|
|
@ -275,7 +275,8 @@ class Deserializer(base.Deserializer):
|
|||
obj_pk = model._meta.pk.to_python(n.getAttribute('pk'))
|
||||
return obj_pk
|
||||
else:
|
||||
m2m_convert = lambda n: model._meta.pk.to_python(n.getAttribute('pk'))
|
||||
def m2m_convert(n):
|
||||
return model._meta.pk.to_python(n.getAttribute('pk'))
|
||||
return [m2m_convert(c) for c in node.getElementsByTagName("object")]
|
||||
|
||||
def _get_model_from_node(self, node, attr):
|
||||
|
|
|
@ -295,8 +295,6 @@ validate_comma_separated_integer_list = int_list_validator(
|
|||
|
||||
@deconstructible
|
||||
class BaseValidator(object):
|
||||
compare = lambda self, a, b: a is not b
|
||||
clean = lambda self, x: x
|
||||
message = _('Ensure this value is %(limit_value)s (it is %(show_value)s).')
|
||||
code = 'limit_value'
|
||||
|
||||
|
@ -319,42 +317,60 @@ class BaseValidator(object):
|
|||
and (self.code == other.code)
|
||||
)
|
||||
|
||||
def compare(self, a, b):
|
||||
return a is not b
|
||||
|
||||
def clean(self, x):
|
||||
return x
|
||||
|
||||
|
||||
@deconstructible
|
||||
class MaxValueValidator(BaseValidator):
|
||||
compare = lambda self, a, b: a > b
|
||||
message = _('Ensure this value is less than or equal to %(limit_value)s.')
|
||||
code = 'max_value'
|
||||
|
||||
def compare(self, a, b):
|
||||
return a > b
|
||||
|
||||
|
||||
@deconstructible
|
||||
class MinValueValidator(BaseValidator):
|
||||
compare = lambda self, a, b: a < b
|
||||
message = _('Ensure this value is greater than or equal to %(limit_value)s.')
|
||||
code = 'min_value'
|
||||
|
||||
def compare(self, a, b):
|
||||
return a < b
|
||||
|
||||
|
||||
@deconstructible
|
||||
class MinLengthValidator(BaseValidator):
|
||||
compare = lambda self, a, b: a < b
|
||||
clean = lambda self, x: len(x)
|
||||
message = ungettext_lazy(
|
||||
'Ensure this value has at least %(limit_value)d character (it has %(show_value)d).',
|
||||
'Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).',
|
||||
'limit_value')
|
||||
code = 'min_length'
|
||||
|
||||
def compare(self, a, b):
|
||||
return a < b
|
||||
|
||||
def clean(self, x):
|
||||
return len(x)
|
||||
|
||||
|
||||
@deconstructible
|
||||
class MaxLengthValidator(BaseValidator):
|
||||
compare = lambda self, a, b: a > b
|
||||
clean = lambda self, x: len(x)
|
||||
message = ungettext_lazy(
|
||||
'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).',
|
||||
'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).',
|
||||
'limit_value')
|
||||
code = 'max_length'
|
||||
|
||||
def compare(self, a, b):
|
||||
return a > b
|
||||
|
||||
def clean(self, x):
|
||||
return len(x)
|
||||
|
||||
|
||||
@deconstructible
|
||||
class DecimalValidator(object):
|
||||
|
|
|
@ -204,7 +204,8 @@ class BaseDatabaseOperations(object):
|
|||
according to their own quoting schemes.
|
||||
"""
|
||||
# Convert params to contain Unicode values.
|
||||
to_unicode = lambda s: force_text(s, strings_only=True, errors='replace')
|
||||
def to_unicode(s):
|
||||
return force_text(s, strings_only=True, errors='replace')
|
||||
if isinstance(params, (list, tuple)):
|
||||
u_params = tuple(to_unicode(val) for val in params)
|
||||
elif params is None:
|
||||
|
|
|
@ -71,7 +71,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
|||
field_info = {line[0]: InfoLine(*line) for line in cursor.fetchall()}
|
||||
|
||||
cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
|
||||
to_int = lambda i: int(i) if i is not None else i
|
||||
|
||||
def to_int(i):
|
||||
return int(i) if i is not None else i
|
||||
|
||||
fields = []
|
||||
for line in cursor.description:
|
||||
col_name = force_text(line[0])
|
||||
|
|
|
@ -85,7 +85,10 @@ def add_lazy_relation(cls, field, relation, operation):
|
|||
"and related methods on the Apps class.",
|
||||
RemovedInDjango20Warning, stacklevel=2)
|
||||
# Rearrange args for new Apps.lazy_model_operation
|
||||
function = lambda local, related, field: operation(field, related, local)
|
||||
|
||||
def function(local, related, field):
|
||||
return operation(field, related, local)
|
||||
|
||||
lazy_related_operation(function, cls, relation, field=field)
|
||||
|
||||
|
||||
|
|
|
@ -300,7 +300,10 @@ class ReverseOneToOneDescriptor(object):
|
|||
queryset._add_hints(instance=instances[0])
|
||||
|
||||
rel_obj_attr = attrgetter(self.related.field.attname)
|
||||
instance_attr = lambda obj: obj._get_pk_val()
|
||||
|
||||
def instance_attr(obj):
|
||||
return obj._get_pk_val()
|
||||
|
||||
instances_dict = {instance_attr(inst): inst for inst in instances}
|
||||
query = {'%s__in' % self.related.field.name: instances}
|
||||
queryset = queryset.filter(**query)
|
||||
|
|
|
@ -371,11 +371,17 @@ class Options(object):
|
|||
# use that property directly because related_model is a cached property,
|
||||
# and all the models may not have been loaded yet; we don't want to cache
|
||||
# the string reference to the related_model.
|
||||
is_not_an_m2m_field = lambda f: not (f.is_relation and f.many_to_many)
|
||||
is_not_a_generic_relation = lambda f: not (f.is_relation and f.one_to_many)
|
||||
is_not_a_generic_foreign_key = lambda f: not (
|
||||
f.is_relation and f.many_to_one and not (hasattr(f.remote_field, 'model') and f.remote_field.model)
|
||||
)
|
||||
def is_not_an_m2m_field(f):
|
||||
return not (f.is_relation and f.many_to_many)
|
||||
|
||||
def is_not_a_generic_relation(f):
|
||||
return not (f.is_relation and f.one_to_many)
|
||||
|
||||
def is_not_a_generic_foreign_key(f):
|
||||
return not (
|
||||
f.is_relation and f.many_to_one and not (hasattr(f.remote_field, 'model') and f.remote_field.model)
|
||||
)
|
||||
|
||||
return make_immutable_fields_list(
|
||||
"fields",
|
||||
(f for f in self._get_fields(reverse=False) if
|
||||
|
|
|
@ -481,9 +481,12 @@ class QueryDict(MultiValueDict):
|
|||
output = []
|
||||
if safe:
|
||||
safe = force_bytes(safe, self.encoding)
|
||||
encode = lambda k, v: '%s=%s' % ((quote(k, safe), quote(v, safe)))
|
||||
|
||||
def encode(k, v):
|
||||
return '%s=%s' % ((quote(k, safe), quote(v, safe)))
|
||||
else:
|
||||
encode = lambda k, v: urlencode({k: v})
|
||||
def encode(k, v):
|
||||
return urlencode({k: v})
|
||||
for k, list_ in self.lists():
|
||||
k = force_bytes(k, self.encoding)
|
||||
output.extend(encode(k, force_bytes(v, self.encoding))
|
||||
|
|
|
@ -639,7 +639,8 @@ def unordered_list(value, autoescape=True):
|
|||
if autoescape:
|
||||
escaper = conditional_escape
|
||||
else:
|
||||
escaper = lambda x: x
|
||||
def escaper(x):
|
||||
return x
|
||||
|
||||
def walk_items(item_list):
|
||||
item_iterator = iter(item_list)
|
||||
|
@ -850,7 +851,8 @@ def filesizeformat(bytes_):
|
|||
value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
|
||||
return avoid_wrapping(value)
|
||||
|
||||
filesize_number_format = lambda value: formats.number_format(round(value, 1), 1)
|
||||
def filesize_number_format(value):
|
||||
return formats.number_format(round(value, 1), 1)
|
||||
|
||||
KB = 1 << 10
|
||||
MB = 1 << 20
|
||||
|
|
|
@ -160,10 +160,13 @@ def encode_multipart(boundary, data):
|
|||
as an application/octet-stream; otherwise, str(value) will be sent.
|
||||
"""
|
||||
lines = []
|
||||
to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET)
|
||||
|
||||
def to_bytes(s):
|
||||
return force_bytes(s, settings.DEFAULT_CHARSET)
|
||||
|
||||
# Not by any means perfect, but good enough for our purposes.
|
||||
is_file = lambda thing: hasattr(thing, "read") and callable(thing.read)
|
||||
def is_file(thing):
|
||||
return hasattr(thing, "read") and callable(thing.read)
|
||||
|
||||
# Each bit of the multipart form data could be either a form value or a
|
||||
# file, or a *list* of form values and/or files. Remember that HTTP field
|
||||
|
@ -198,7 +201,8 @@ def encode_multipart(boundary, data):
|
|||
|
||||
|
||||
def encode_file(boundary, key, file):
|
||||
to_bytes = lambda s: force_bytes(s, settings.DEFAULT_CHARSET)
|
||||
def to_bytes(s):
|
||||
return force_bytes(s, settings.DEFAULT_CHARSET)
|
||||
filename = os.path.basename(file.name) if hasattr(file, 'name') else ''
|
||||
if hasattr(file, 'content_type'):
|
||||
content_type = file.content_type
|
||||
|
|
|
@ -159,7 +159,8 @@ def make_middleware_decorator(middleware_class):
|
|||
# Defer running of process_response until after the template
|
||||
# has been rendered:
|
||||
if hasattr(middleware, 'process_response'):
|
||||
callback = lambda response: middleware.process_response(request, response)
|
||||
def callback(response):
|
||||
return middleware.process_response(request, response)
|
||||
response.add_post_render_callback(callback)
|
||||
else:
|
||||
if hasattr(middleware, 'process_response'):
|
||||
|
|
|
@ -91,7 +91,8 @@ class SyndicationFeed(object):
|
|||
def __init__(self, title, link, description, language=None, author_email=None,
|
||||
author_name=None, author_link=None, subtitle=None, categories=None,
|
||||
feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
|
||||
to_unicode = lambda s: force_text(s, strings_only=True)
|
||||
def to_unicode(s):
|
||||
return force_text(s, strings_only=True)
|
||||
if categories:
|
||||
categories = [force_text(c) for c in categories]
|
||||
if ttl is not None:
|
||||
|
@ -126,7 +127,8 @@ class SyndicationFeed(object):
|
|||
objects, and enclosures, which is an iterable of instances of the
|
||||
Enclosure class.
|
||||
"""
|
||||
to_unicode = lambda s: force_text(s, strings_only=True)
|
||||
def to_unicode(s):
|
||||
return force_text(s, strings_only=True)
|
||||
if categories:
|
||||
categories = [to_unicode(c) for c in categories]
|
||||
if ttl is not None:
|
||||
|
|
|
@ -19,7 +19,8 @@ if six.PY2:
|
|||
|
||||
|
||||
# Capitalizes the first letter of a string.
|
||||
capfirst = lambda x: x and force_text(x)[0].upper() + force_text(x)[1:]
|
||||
def capfirst(x):
|
||||
return x and force_text(x)[0].upper() + force_text(x)[1:]
|
||||
capfirst = keep_lazy_text(capfirst)
|
||||
|
||||
# Set up regular expressions
|
||||
|
|
|
@ -24,11 +24,28 @@ def pgettext(context, message):
|
|||
def npgettext(context, singular, plural, number):
|
||||
return ungettext(singular, plural, number)
|
||||
|
||||
activate = lambda x: None
|
||||
deactivate = deactivate_all = lambda: None
|
||||
get_language = lambda: settings.LANGUAGE_CODE
|
||||
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
||||
check_for_language = lambda x: True
|
||||
|
||||
def activate(x):
|
||||
return None
|
||||
|
||||
|
||||
def deactivate():
|
||||
return None
|
||||
|
||||
|
||||
deactivate_all = deactivate
|
||||
|
||||
|
||||
def get_language():
|
||||
return settings.LANGUAGE_CODE
|
||||
|
||||
|
||||
def get_language_bidi():
|
||||
return settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
||||
|
||||
|
||||
def check_for_language(x):
|
||||
return True
|
||||
|
||||
|
||||
def gettext(message):
|
||||
|
|
|
@ -186,7 +186,10 @@ js_catalog_template = r"""
|
|||
|
||||
def render_javascript_catalog(catalog=None, plural=None):
|
||||
template = Engine().from_string(js_catalog_template)
|
||||
indent = lambda s: s.replace('\n', '\n ')
|
||||
|
||||
def indent(s):
|
||||
return s.replace('\n', '\n ')
|
||||
|
||||
context = Context({
|
||||
'catalog_str': indent(json.dumps(
|
||||
catalog, sort_keys=True, indent=2)) if catalog else None,
|
||||
|
|
|
@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
|
|||
|
||||
[flake8]
|
||||
exclude = build,.git,./django/utils/lru_cache.py,./django/utils/six.py,./django/conf/app_template/*,./django/dispatch/weakref_backports.py,./tests/.env,./xmlrunner,tests/view_tests/tests/py3_test_debug.py,tests/template_tests/annotated_tag_function.py
|
||||
ignore = E123,E128,E402,W503,E731,W601
|
||||
ignore = E123,E128,E402,W503,W601
|
||||
max-line-length = 119
|
||||
|
||||
[isort]
|
||||
|
|
|
@ -10,7 +10,8 @@ class AbsoluteUrlOverrideTests(SimpleTestCase):
|
|||
"""
|
||||
get_absolute_url() functions as a normal method.
|
||||
"""
|
||||
get_absolute_url = lambda o: '/test-a/%s/' % o.pk
|
||||
def get_absolute_url(o):
|
||||
return '/test-a/%s/' % o.pk
|
||||
TestA = self._create_model_class('TestA', get_absolute_url)
|
||||
|
||||
self.assertTrue(hasattr(TestA, 'get_absolute_url'))
|
||||
|
@ -21,7 +22,8 @@ class AbsoluteUrlOverrideTests(SimpleTestCase):
|
|||
"""
|
||||
ABSOLUTE_URL_OVERRIDES should override get_absolute_url().
|
||||
"""
|
||||
get_absolute_url = lambda o: '/test-b/%s/' % o.pk
|
||||
def get_absolute_url(o):
|
||||
return '/test-b/%s/' % o.pk
|
||||
with self.settings(
|
||||
ABSOLUTE_URL_OVERRIDES={
|
||||
'absolute_url_overrides.testb': lambda o: '/overridden-test-b/%s/' % o.pk,
|
||||
|
|
|
@ -729,8 +729,9 @@ class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
|
|||
reverse('admin:admin_inlines_holder4_add')))
|
||||
|
||||
inline_id = '#inner4stacked_set-group'
|
||||
rows_length = lambda: len(self.selenium.find_elements_by_css_selector(
|
||||
'%s .dynamic-inner4stacked_set' % inline_id))
|
||||
|
||||
def rows_length():
|
||||
return len(self.selenium.find_elements_by_css_selector('%s .dynamic-inner4stacked_set' % inline_id))
|
||||
self.assertEqual(rows_length(), 3)
|
||||
|
||||
add_button = self.selenium.find_element_by_link_text(
|
||||
|
@ -745,8 +746,9 @@ class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
|
|||
reverse('admin:admin_inlines_holder4_add')))
|
||||
|
||||
inline_id = '#inner4stacked_set-group'
|
||||
rows_length = lambda: len(self.selenium.find_elements_by_css_selector(
|
||||
'%s .dynamic-inner4stacked_set' % inline_id))
|
||||
|
||||
def rows_length():
|
||||
return len(self.selenium.find_elements_by_css_selector('%s .dynamic-inner4stacked_set' % inline_id))
|
||||
self.assertEqual(rows_length(), 3)
|
||||
|
||||
add_button = self.selenium.find_element_by_link_text(
|
||||
|
|
|
@ -111,7 +111,8 @@ class UtilsTests(SimpleTestCase):
|
|||
def get_admin_value(self, obj):
|
||||
return ADMIN_METHOD
|
||||
|
||||
simple_function = lambda obj: SIMPLE_FUNCTION
|
||||
def simple_function(obj):
|
||||
return SIMPLE_FUNCTION
|
||||
|
||||
site_obj = Site(domain=SITE_NAME)
|
||||
article = Article(
|
||||
|
|
|
@ -141,7 +141,8 @@ class FlatpageTemplateTagTests(TestCase):
|
|||
|
||||
def test_parsing_errors(self):
|
||||
"There are various ways that the flatpages template tag won't parse"
|
||||
render = lambda t: Template(t).render(Context())
|
||||
def render(t):
|
||||
return Template(t).render(Context())
|
||||
|
||||
self.assertRaises(TemplateSyntaxError, render,
|
||||
"{% load flatpages %}{% get_flatpages %}")
|
||||
|
|
|
@ -1173,7 +1173,8 @@ class FieldsTests(SimpleTestCase):
|
|||
)
|
||||
|
||||
def test_choicefield_callable(self):
|
||||
choices = lambda: [('J', 'John'), ('P', 'Paul')]
|
||||
def choices():
|
||||
return [('J', 'John'), ('P', 'Paul')]
|
||||
f = ChoiceField(choices=choices)
|
||||
self.assertEqual('J', f.clean('J'))
|
||||
|
||||
|
|
|
@ -141,7 +141,8 @@ class LookupTests(TestCase):
|
|||
def test_values(self):
|
||||
# values() returns a list of dictionaries instead of object instances --
|
||||
# and you can specify which fields you want to retrieve.
|
||||
identity = lambda x: x
|
||||
def identity(x):
|
||||
return x
|
||||
self.assertQuerysetEqual(Article.objects.values('headline'),
|
||||
[
|
||||
{'headline': 'Article 5'},
|
||||
|
@ -276,7 +277,8 @@ class LookupTests(TestCase):
|
|||
# returned as a list of tuples, rather than a list of dictionaries.
|
||||
# Within each tuple, the order of the elements is the same as the order
|
||||
# of fields in the values_list() call.
|
||||
identity = lambda x: x
|
||||
def identity(x):
|
||||
return x
|
||||
self.assertQuerysetEqual(Article.objects.values_list('headline'),
|
||||
[
|
||||
('Article 5',),
|
||||
|
|
|
@ -707,12 +707,11 @@ class GZipMiddlewareTest(SimpleTestCase):
|
|||
"""
|
||||
Compression is performed on FileResponse.
|
||||
"""
|
||||
open_file = lambda: open(__file__, 'rb')
|
||||
with open_file() as file1:
|
||||
with open(__file__, 'rb') as file1:
|
||||
file_resp = FileResponse(file1)
|
||||
file_resp['Content-Type'] = 'text/html; charset=UTF-8'
|
||||
r = GZipMiddleware().process_response(self.req, file_resp)
|
||||
with open_file() as file2:
|
||||
with open(__file__, 'rb') as file2:
|
||||
self.assertEqual(self.decompress(b''.join(r)), file2.read())
|
||||
self.assertEqual(r.get('Content-Encoding'), 'gzip')
|
||||
self.assertIsNot(r.file_to_stream, file1)
|
||||
|
|
|
@ -68,7 +68,8 @@ class DataTests(OptionsBaseTests):
|
|||
self.assertEqual([f.attname for f in fields], expected_result)
|
||||
|
||||
def test_local_fields(self):
|
||||
is_data_field = lambda f: isinstance(f, Field) and not isinstance(f, related.ManyToManyField)
|
||||
def is_data_field(f):
|
||||
return isinstance(f, Field) and not isinstance(f, related.ManyToManyField)
|
||||
|
||||
for model, expected_result in TEST_RESULTS['local_fields'].items():
|
||||
fields = model._meta.local_fields
|
||||
|
@ -101,7 +102,8 @@ class M2MTests(OptionsBaseTests):
|
|||
|
||||
|
||||
class RelatedObjectsTests(OptionsBaseTests):
|
||||
key_name = lambda self, r: r[0]
|
||||
def key_name(self, r):
|
||||
return r[0]
|
||||
|
||||
def test_related_objects(self):
|
||||
result_key = 'get_all_related_objects_with_model'
|
||||
|
|
|
@ -690,7 +690,8 @@ class CustomTestClientTest(SimpleTestCase):
|
|||
self.assertEqual(hasattr(self.client, "i_am_customized"), True)
|
||||
|
||||
|
||||
_generic_view = lambda request: HttpResponse(status=200)
|
||||
def _generic_view(request):
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='test_client.urls')
|
||||
|
|
|
@ -126,7 +126,8 @@ class ImmutableListTests(SimpleTestCase):
|
|||
class DictWrapperTests(SimpleTestCase):
|
||||
|
||||
def test_dictwrapper(self):
|
||||
f = lambda x: "*%s" % x
|
||||
def f(x):
|
||||
return "*%s" % x
|
||||
d = DictWrapper({'a': 'a'}, f, 'xx_')
|
||||
self.assertEqual(
|
||||
"Normal: %(a)s. Modified: %(xx_a)s" % d,
|
||||
|
|
Loading…
Reference in New Issue