summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes@5monkeys.se>2019-11-08 21:20:13 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-11 13:30:14 +0100
commit8d3f43f7a9dc0b83dd9ac82ac0270bfee88ed51f (patch)
tree260a9028269781d49966f9fe6ffe393c282bbd47
parent2c2afbe104d4cc40ddea2ea4b2a697c8e1697eb7 (diff)
downloaddjango-8d3f43f7a9dc0b83dd9ac82ac0270bfee88ed51f.tar.gz
[3.0.x] Fixed #30967 -- Fixed TrigramTest failures on PostgreSQL 12+.
Backport of 6e2f05b2e33a6c80c7a411ce76af7b5a08acb835 from master
-rw-r--r--tests/postgres_tests/test_trigram.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/postgres_tests/test_trigram.py b/tests/postgres_tests/test_trigram.py
index b340b41869..2a123faa5e 100644
--- a/tests/postgres_tests/test_trigram.py
+++ b/tests/postgres_tests/test_trigram.py
@@ -26,22 +26,26 @@ class TrigramTest(PostgreSQLTestCase):
def test_trigram_similarity(self):
search = 'Bat sat on cat.'
+ # Round result of similarity because PostgreSQL 12+ uses greater
+ # precision.
self.assertQuerysetEqual(
self.Model.objects.filter(
field__trigram_similar=search,
).annotate(similarity=TrigramSimilarity('field', search)).order_by('-similarity'),
[('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,
)
def test_trigram_similarity_alternate(self):
+ # Round result of distance because PostgreSQL 12+ uses greater
+ # precision.
self.assertQuerysetEqual(
self.Model.objects.annotate(
distance=TrigramDistance('field', 'Bat sat on cat.'),
).filter(distance__lte=0.7).order_by('distance'),
[('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,
)