summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2018-09-28 18:57:12 +0500
committerTim Graham <timograham@gmail.com>2018-09-28 09:57:12 -0400
commit8ef8bc0f64c463684268a7c55f3d3da4de066c0d (patch)
tree9c3ab782c6382bdbc91363d0dd5513df83381903 /tests
parent4fc8fb7ddaad495d45d53df58b2d13115857b3c7 (diff)
Refs #28909 -- Simplifed code using unpacking generalizations.
Diffstat (limited to 'tests')
-rw-r--r--tests/file_storage/tests.py3
-rw-r--r--tests/forms_tests/tests/test_forms.py2
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py4
-rw-r--r--tests/gis_tests/geos_tests/test_mutable_list.py8
-rw-r--r--tests/model_fields/test_field_flags.py26
-rw-r--r--tests/template_tests/templatetags/custom.py4
-rw-r--r--tests/template_tests/templatetags/inclusion.py6
-rw-r--r--tests/utils_tests/test_baseconv.py2
8 files changed, 27 insertions, 28 deletions
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 6253036679..7957323299 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -544,8 +544,7 @@ class CustomStorage(FileSystemStorage):
"""
Append numbers to duplicate files rather than underscores, like Trac.
"""
- parts = name.split('.')
- basename, ext = parts[0], parts[1:]
+ basename, *ext = name.split('.')
number = 2
while self.exists(name):
name = '.'.join([basename, str(number)] + ext)
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 914f2b5345..ba233e72ff 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -1566,7 +1566,7 @@ value="Should escape &lt; &amp; &gt; and &lt;script&gt;alert(&#39;xss&#39;)&lt;/
p = TestForm()
self.assertEqual(list(p.fields), TestFormMissing.field_order)
p = TestFormInit()
- order = list(TestForm.field_order) + ['field1']
+ order = [*TestForm.field_order, 'field1']
self.assertEqual(list(p.fields), order)
TestForm.field_order = ['unknown']
p = TestForm()
diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py
index 62589eee9d..6818339a9b 100644
--- a/tests/gis_tests/geos_tests/test_geos.py
+++ b/tests/gis_tests/geos_tests/test_geos.py
@@ -476,8 +476,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
Polygon('foo')
# Polygon(shell, (hole1, ... holeN))
- rings = tuple(r for r in poly)
- self.assertEqual(poly, Polygon(rings[0], rings[1:]))
+ ext_ring, *int_rings = poly
+ self.assertEqual(poly, Polygon(ext_ring, int_rings))
# Polygon(shell_tuple, hole_tuple1, ... , hole_tupleN)
ring_tuples = tuple(r.tuple for r in poly)
diff --git a/tests/gis_tests/geos_tests/test_mutable_list.py b/tests/gis_tests/geos_tests/test_mutable_list.py
index 1e51a19985..bb085b2fb2 100644
--- a/tests/gis_tests/geos_tests/test_mutable_list.py
+++ b/tests/gis_tests/geos_tests/test_mutable_list.py
@@ -72,7 +72,7 @@ class ListMixinTest(unittest.TestCase):
return range(-self.limit - b, self.limit + b)
def step_range(self):
- return list(range(-1 - self.limit, 0)) + list(range(1, 1 + self.limit))
+ return [*range(-1 - self.limit, 0), *range(1, 1 + self.limit)]
def test01_getslice(self):
'Slice retrieval'
@@ -172,13 +172,13 @@ class ListMixinTest(unittest.TestCase):
del pl[i:j]
del ul[i:j]
self.assertEqual(pl[:], ul[:], 'del slice [%d:%d]' % (i, j))
- for k in list(range(-Len - 1, 0)) + list(range(1, Len)):
+ for k in [*range(-Len - 1, 0), *range(1, Len)]:
pl, ul = self.lists_of_len(Len)
del pl[i:j:k]
del ul[i:j:k]
self.assertEqual(pl[:], ul[:], 'del slice [%d:%d:%d]' % (i, j, k))
- for k in list(range(-Len - 1, 0)) + list(range(1, Len)):
+ for k in [*range(-Len - 1, 0), *range(1, Len)]:
pl, ul = self.lists_of_len(Len)
del pl[:i:k]
del ul[:i:k]
@@ -189,7 +189,7 @@ class ListMixinTest(unittest.TestCase):
del ul[i::k]
self.assertEqual(pl[:], ul[:], 'del slice [%d::%d]' % (i, k))
- for k in list(range(-Len - 1, 0)) + list(range(1, Len)):
+ for k in [*range(-Len - 1, 0), *range(1, Len)]:
pl, ul = self.lists_of_len(Len)
del pl[::k]
del ul[::k]
diff --git a/tests/model_fields/test_field_flags.py b/tests/model_fields/test_field_flags.py
index 26a345ea5c..0e9256207c 100644
--- a/tests/model_fields/test_field_flags.py
+++ b/tests/model_fields/test_field_flags.py
@@ -76,21 +76,21 @@ class FieldFlagsTests(test.SimpleTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
- cls.fields = (
- list(AllFieldsModel._meta.fields) +
- list(AllFieldsModel._meta.private_fields)
- )
+ cls.fields = [
+ *AllFieldsModel._meta.fields,
+ *AllFieldsModel._meta.private_fields,
+ ]
- cls.all_fields = (
- cls.fields +
- list(AllFieldsModel._meta.many_to_many) +
- list(AllFieldsModel._meta.private_fields)
- )
+ cls.all_fields = [
+ *cls.fields,
+ *AllFieldsModel._meta.many_to_many,
+ *AllFieldsModel._meta.private_fields,
+ ]
- cls.fields_and_reverse_objects = (
- cls.all_fields +
- list(AllFieldsModel._meta.related_objects)
- )
+ cls.fields_and_reverse_objects = [
+ *cls.all_fields,
+ *AllFieldsModel._meta.related_objects,
+ ]
def test_each_field_should_have_a_concrete_attribute(self):
self.assertTrue(all(f.concrete.__class__ == bool for f in self.fields))
diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py
index 45acd9655e..eaaff193ee 100644
--- a/tests/template_tests/templatetags/custom.py
+++ b/tests/template_tests/templatetags/custom.py
@@ -111,7 +111,7 @@ simple_one_default.anything = "Expected simple_one_default __dict__"
def simple_unlimited_args(one, two='hi', *args):
"""Expected simple_unlimited_args __doc__"""
return "simple_unlimited_args - Expected result: %s" % (
- ', '.join(str(arg) for arg in [one, two] + list(args))
+ ', '.join(str(arg) for arg in [one, two, *args])
)
@@ -133,7 +133,7 @@ def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
- ', '.join(str(arg) for arg in [one, two] + list(args)),
+ ', '.join(str(arg) for arg in [one, two, *args]),
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
)
diff --git a/tests/template_tests/templatetags/inclusion.py b/tests/template_tests/templatetags/inclusion.py
index 60f654ec00..242fbe80cb 100644
--- a/tests/template_tests/templatetags/inclusion.py
+++ b/tests/template_tests/templatetags/inclusion.py
@@ -151,7 +151,7 @@ def inclusion_unlimited_args(one, two='hi', *args):
return {
"result": (
"inclusion_unlimited_args - Expected result: %s" % (
- ', '.join(str(arg) for arg in [one, two] + list(args))
+ ', '.join(str(arg) for arg in [one, two, *args])
)
)
}
@@ -166,7 +166,7 @@ def inclusion_unlimited_args_from_template(one, two='hi', *args):
return {
"result": (
"inclusion_unlimited_args_from_template - Expected result: %s" % (
- ', '.join(str(arg) for arg in [one, two] + list(args))
+ ', '.join(str(arg) for arg in [one, two, *args])
)
)
}
@@ -216,7 +216,7 @@ def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
# Sort the dictionary by key to guarantee the order for testing.
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
- ', '.join(str(arg) for arg in [one, two] + list(args)),
+ ', '.join(str(arg) for arg in [one, two, *args]),
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
)}
diff --git a/tests/utils_tests/test_baseconv.py b/tests/utils_tests/test_baseconv.py
index 948b991ad3..b6bfc5ef20 100644
--- a/tests/utils_tests/test_baseconv.py
+++ b/tests/utils_tests/test_baseconv.py
@@ -8,7 +8,7 @@ from django.utils.baseconv import (
class TestBaseConv(TestCase):
def test_baseconv(self):
- nums = [-10 ** 10, 10 ** 10] + list(range(-100, 100))
+ nums = [-10 ** 10, 10 ** 10, *range(-100, 100)]
for converter in [base2, base16, base36, base56, base62, base64]:
for i in nums:
self.assertEqual(i, converter.decode(converter.encode(i)))