mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -8,31 +8,34 @@ from ..models import Author
|
||||
|
||||
class TrimTests(TestCase):
|
||||
def test_trim(self):
|
||||
Author.objects.create(name=' John ', alias='j')
|
||||
Author.objects.create(name='Rhonda', alias='r')
|
||||
Author.objects.create(name=" John ", alias="j")
|
||||
Author.objects.create(name="Rhonda", alias="r")
|
||||
authors = Author.objects.annotate(
|
||||
ltrim=LTrim('name'),
|
||||
rtrim=RTrim('name'),
|
||||
trim=Trim('name'),
|
||||
ltrim=LTrim("name"),
|
||||
rtrim=RTrim("name"),
|
||||
trim=Trim("name"),
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
authors.order_by('alias'), [
|
||||
('John ', ' John', 'John'),
|
||||
('Rhonda', 'Rhonda', 'Rhonda'),
|
||||
authors.order_by("alias"),
|
||||
[
|
||||
("John ", " John", "John"),
|
||||
("Rhonda", "Rhonda", "Rhonda"),
|
||||
],
|
||||
lambda a: (a.ltrim, a.rtrim, a.trim)
|
||||
lambda a: (a.ltrim, a.rtrim, a.trim),
|
||||
)
|
||||
|
||||
def test_trim_transform(self):
|
||||
Author.objects.create(name=' John ')
|
||||
Author.objects.create(name='Rhonda')
|
||||
Author.objects.create(name=" John ")
|
||||
Author.objects.create(name="Rhonda")
|
||||
tests = (
|
||||
(LTrim, 'John '),
|
||||
(RTrim, ' John'),
|
||||
(Trim, 'John'),
|
||||
(LTrim, "John "),
|
||||
(RTrim, " John"),
|
||||
(Trim, "John"),
|
||||
)
|
||||
for transform, trimmed_name in tests:
|
||||
with self.subTest(transform=transform):
|
||||
with register_lookup(CharField, transform):
|
||||
authors = Author.objects.filter(**{'name__%s' % transform.lookup_name: trimmed_name})
|
||||
self.assertQuerysetEqual(authors, [' John '], lambda a: a.name)
|
||||
authors = Author.objects.filter(
|
||||
**{"name__%s" % transform.lookup_name: trimmed_name}
|
||||
)
|
||||
self.assertQuerysetEqual(authors, [" John "], lambda a: a.name)
|
||||
|
||||
Reference in New Issue
Block a user