1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Refs #24121 -- Added __repr__() to Lookup.

This commit is contained in:
saeedblanchette 2021-05-11 04:02:25 +00:00 committed by Mariusz Felisiak
parent f0a9413bd2
commit d3d95d645f
2 changed files with 20 additions and 0 deletions

View File

@ -40,6 +40,9 @@ class Lookup:
value = transform(value) value = transform(value)
return value return value
def __repr__(self):
return f'{self.__class__.__name__}({self.lhs!r}, {self.rhs!r})'
def batch_process_rhs(self, compiler, connection, rhs=None): def batch_process_rhs(self, compiler, connection, rhs=None):
if rhs is None: if rhs is None:
rhs = self.rhs rhs = self.rhs

View File

@ -20,6 +20,23 @@ class LookupTests(SimpleTestCase):
self.assertNotEqual(lookup, Lookup(Value(3), lookup.rhs)) self.assertNotEqual(lookup, Lookup(Value(3), lookup.rhs))
self.assertNotEqual(lookup, CustomLookup(lookup.lhs, lookup.rhs)) self.assertNotEqual(lookup, CustomLookup(lookup.lhs, lookup.rhs))
def test_repr(self):
tests = [
(Lookup(Value(1), Value('a')), "Lookup(Value(1), Value('a'))"),
(
YearLookup(
Value(datetime(2010, 1, 1, 0, 0, 0)),
Value(datetime(2010, 1, 1, 23, 59, 59)),
),
'YearLookup('
'Value(datetime.datetime(2010, 1, 1, 0, 0)), '
'Value(datetime.datetime(2010, 1, 1, 23, 59, 59)))'
),
]
for lookup, expected in tests:
with self.subTest(lookup=lookup):
self.assertEqual(repr(lookup), expected)
def test_hash(self): def test_hash(self):
lookup = Lookup(Value(1), Value(2)) lookup = Lookup(Value(1), Value(2))
self.assertEqual(hash(lookup), hash(lookup)) self.assertEqual(hash(lookup), hash(lookup))