summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/db_functions/text/test_concat.py14
-rw-r--r--tests/expressions/tests.py23
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/db_functions/text/test_concat.py b/tests/db_functions/text/test_concat.py
index 6e4cb91d3a..ffcd19fad6 100644
--- a/tests/db_functions/text/test_concat.py
+++ b/tests/db_functions/text/test_concat.py
@@ -107,3 +107,17 @@ class ConcatTests(TestCase):
ctx.captured_queries[0]["sql"].count("::text"),
1 if connection.vendor == "postgresql" else 0,
)
+
+ def test_equal(self):
+ self.assertEqual(
+ Concat("foo", "bar", output_field=TextField()),
+ Concat("foo", "bar", output_field=TextField()),
+ )
+ self.assertNotEqual(
+ Concat("foo", "bar", output_field=TextField()),
+ Concat("foo", "bar", output_field=CharField()),
+ )
+ self.assertNotEqual(
+ Concat("foo", "bar", output_field=TextField()),
+ Concat("bar", "foo", output_field=TextField()),
+ )
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index cfa33b6f45..89601de85b 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -1433,6 +1433,29 @@ class SimpleExpressionTests(SimpleTestCase):
Expression(TestModel._meta.get_field("other_field")),
)
+ class InitCaptureExpression(Expression):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ # The identity of expressions that obscure their __init__() signature
+ # with *args and **kwargs cannot be determined when bound with
+ # different combinations or *args and **kwargs.
+ self.assertNotEqual(
+ InitCaptureExpression(IntegerField()),
+ InitCaptureExpression(output_field=IntegerField()),
+ )
+
+ # However, they should be considered equal when their bindings are
+ # equal.
+ self.assertEqual(
+ InitCaptureExpression(IntegerField()),
+ InitCaptureExpression(IntegerField()),
+ )
+ self.assertEqual(
+ InitCaptureExpression(output_field=IntegerField()),
+ InitCaptureExpression(output_field=IntegerField()),
+ )
+
def test_hash(self):
self.assertEqual(hash(Expression()), hash(Expression()))
self.assertEqual(