From 3a892122f2347cc2999857bda1139d084a8e7dce Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 1 Jul 2007 04:47:46 +0000 Subject: [PATCH] Made the reg-exp lookup tests more robust. they now pass for all database backends and are not dependent on locale sorting order. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5579 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/lookup/models.py | 55 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index 60ed6f76854..9d3e8ca4b49 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -5,6 +5,7 @@ This demonstrates features of the database API. """ from django.db import models +from django.conf import settings class Article(models.Model): headline = models.CharField(maxlength=100) @@ -263,14 +264,14 @@ TypeError: Cannot resolve keyword 'headline__starts' into field. Choices are: id >>> a3.save() >>> a4 = Article(pub_date=now, headline='fooo') >>> a4.save() ->>> a5 = Article(pub_date=now, headline='Foo') +>>> a5 = Article(pub_date=now, headline='hey-Foo') >>> a5.save() # zero-or-more >>> Article.objects.filter(headline__regex=r'fo*') [, , , ] >>> Article.objects.filter(headline__iregex=r'fo*') -[, , , , ] +[, , , , ] # one-or-more >>> Article.objects.filter(headline__regex=r'fo+') @@ -283,39 +284,39 @@ TypeError: Cannot resolve keyword 'headline__starts' into field. Choices are: id # and some more: >>> a6 = Article(pub_date=now, headline='bar') >>> a6.save() ->>> a7 = Article(pub_date=now, headline='Bar') +>>> a7 = Article(pub_date=now, headline='AbBa') >>> a7.save() >>> a8 = Article(pub_date=now, headline='baz') >>> a8.save() ->>> a9 = Article(pub_date=now, headline='baZ') +>>> a9 = Article(pub_date=now, headline='baxZ') >>> a9.save() # leading anchor >>> Article.objects.filter(headline__regex=r'^b') -[, , ] ->>> Article.objects.filter(headline__iregex=r'^b') -[, , , ] +[, , ] +>>> Article.objects.filter(headline__iregex=r'^a') +[] # trailing anchor >>> Article.objects.filter(headline__regex=r'z$') [] >>> Article.objects.filter(headline__iregex=r'z$') -[, ] +[, ] # character sets >>> Article.objects.filter(headline__regex=r'ba[rz]') [, ] ->>> Article.objects.filter(headline__regex=r'ba[RZ]') -[] ->>> Article.objects.filter(headline__iregex=r'ba[RZ]') -[, , , ] +>>> Article.objects.filter(headline__regex=r'ba.[RxZ]') +[] +>>> Article.objects.filter(headline__iregex=r'ba[RxZ]') +[, , ] # and yet more: >>> a10 = Article(pub_date=now, headline='foobar') >>> a10.save() >>> a11 = Article(pub_date=now, headline='foobaz') >>> a11.save() ->>> a12 = Article(pub_date=now, headline='FooBarBaz') +>>> a12 = Article(pub_date=now, headline='ooF') >>> a12.save() >>> a13 = Article(pub_date=now, headline='foobarbaz') >>> a13.save() @@ -323,26 +324,28 @@ TypeError: Cannot resolve keyword 'headline__starts' into field. Choices are: id >>> a14.save() >>> a15 = Article(pub_date=now, headline='barfoobaz') >>> a15.save() ->>> a16 = Article(pub_date=now, headline='BAZBARFOO') +>>> a16 = Article(pub_date=now, headline='bazbaRFOO') >>> a16.save() # alternation ->>> Article.objects.filter(headline__regex=r'foo(bar|baz)') +>>> Article.objects.filter(headline__regex=r'oo(f|b)') [, , , ] ->>> Article.objects.filter(headline__iregex=r'foo(bar|baz)') -[, , , , ] ->>> Article.objects.filter(headline__regex=r'^foo(bar|baz)') +>>> Article.objects.filter(headline__iregex=r'oo(f|b)') +[, , , , ] +>>> Article.objects.filter(headline__regex=r'^foo(f|b)') [, , ] # greedy matching ->>> Article.objects.filter(headline__regex=r'f.*z') -[, , , ] ->>> Article.objects.filter(headline__iregex=r'f.*z') -[, , , , ] +>>> Article.objects.filter(headline__regex=r'b.*az') +[, , , , ] +>>> Article.objects.filter(headline__iregex=r'b.*ar') +[, , , , ] +"""} + +if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old'): + __test__['API_TESTS'] += r""" # grouping and backreferences >>> Article.objects.filter(headline__regex=r'b(.).*b\1') -[, ] ->>> Article.objects.filter(headline__iregex=r'b(.).*b\1') -[, , , ] -"""} +[, , ] +"""