mirror of https://github.com/django/django.git
[3.0.x] Fixed #30967 -- Fixed TrigramTest failures on PostgreSQL 12+.
Backport of 6e2f05b2e3
from master
This commit is contained in:
parent
2c2afbe104
commit
8d3f43f7a9
|
@ -26,22 +26,26 @@ class TrigramTest(PostgreSQLTestCase):
|
||||||
|
|
||||||
def test_trigram_similarity(self):
|
def test_trigram_similarity(self):
|
||||||
search = 'Bat sat on cat.'
|
search = 'Bat sat on cat.'
|
||||||
|
# Round result of similarity because PostgreSQL 12+ uses greater
|
||||||
|
# precision.
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
self.Model.objects.filter(
|
self.Model.objects.filter(
|
||||||
field__trigram_similar=search,
|
field__trigram_similar=search,
|
||||||
).annotate(similarity=TrigramSimilarity('field', search)).order_by('-similarity'),
|
).annotate(similarity=TrigramSimilarity('field', search)).order_by('-similarity'),
|
||||||
[('Cat sat on mat.', 0.625), ('Dog sat on rug.', 0.333333)],
|
[('Cat sat on mat.', 0.625), ('Dog sat on rug.', 0.333333)],
|
||||||
transform=lambda instance: (instance.field, instance.similarity),
|
transform=lambda instance: (instance.field, round(instance.similarity, 6)),
|
||||||
ordered=True,
|
ordered=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_trigram_similarity_alternate(self):
|
def test_trigram_similarity_alternate(self):
|
||||||
|
# Round result of distance because PostgreSQL 12+ uses greater
|
||||||
|
# precision.
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
self.Model.objects.annotate(
|
self.Model.objects.annotate(
|
||||||
distance=TrigramDistance('field', 'Bat sat on cat.'),
|
distance=TrigramDistance('field', 'Bat sat on cat.'),
|
||||||
).filter(distance__lte=0.7).order_by('distance'),
|
).filter(distance__lte=0.7).order_by('distance'),
|
||||||
[('Cat sat on mat.', 0.375), ('Dog sat on rug.', 0.666667)],
|
[('Cat sat on mat.', 0.375), ('Dog sat on rug.', 0.666667)],
|
||||||
transform=lambda instance: (instance.field, instance.distance),
|
transform=lambda instance: (instance.field, round(instance.distance, 6)),
|
||||||
ordered=True,
|
ordered=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue