Skip to content

Commit 97b9ad7

Browse files
committed
Refs django#2333 - Modified runtests script to use new testing framework. Migrated existing tests to use Django testing framework. All the 'othertests' have been migrated into 'regressiontests', and converted into doctests/unittests, as appropriate.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 77ab11b commit 97b9ad7

File tree

70 files changed

+949
-3791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+949
-3791
lines changed

tests/doctest.py

Lines changed: 0 additions & 2665 deletions
This file was deleted.

tests/modeltests/basic/models.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class Article(models.Model):
1313
def __str__(self):
1414
return self.headline
1515

16-
API_TESTS = """
17-
16+
__test__ = {'API_TESTS': """
1817
# No articles are in the system yet.
1918
>>> Article.objects.all()
2019
[]
@@ -314,14 +313,14 @@ def __str__(self):
314313
>>> Article.objects.all()
315314
[<Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Updated article 8>]
316315
317-
"""
316+
"""}
318317

319318
from django.conf import settings
320319

321320
building_docs = getattr(settings, 'BUILDING_DOCS', False)
322321

323322
if building_docs or settings.DATABASE_ENGINE == 'postgresql':
324-
API_TESTS += """
323+
__test__['API_TESTS'] += """
325324
# In PostgreSQL, microsecond-level precision is available.
326325
>>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180))
327326
>>> a9.save()
@@ -330,7 +329,7 @@ def __str__(self):
330329
"""
331330

332331
if building_docs or settings.DATABASE_ENGINE == 'mysql':
333-
API_TESTS += """
332+
__test__['API_TESTS'] += """
334333
# In MySQL, microsecond-level precision isn't available. You'll lose
335334
# microsecond-level precision once the data is saved.
336335
>>> a9 = Article(headline='Article 9', pub_date=datetime(2005, 7, 31, 12, 30, 45, 180))
@@ -339,7 +338,7 @@ def __str__(self):
339338
datetime.datetime(2005, 7, 31, 12, 30, 45)
340339
"""
341340

342-
API_TESTS += """
341+
__test__['API_TESTS'] += """
343342
344343
# You can manually specify the primary key when creating a new object.
345344
>>> a101 = Article(id=101, headline='Article 101', pub_date=datetime(2005, 7, 31, 12, 30, 45))

tests/modeltests/choices/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Person(models.Model):
2323
def __str__(self):
2424
return self.name
2525

26-
API_TESTS = """
26+
__test__ = {'API_TESTS':"""
2727
>>> a = Person(name='Adrian', gender='M')
2828
>>> a.save()
2929
>>> s = Person(name='Sara', gender='F')
@@ -36,4 +36,4 @@ def __str__(self):
3636
'Male'
3737
>>> s.get_gender_display()
3838
'Female'
39-
"""
39+
"""}

tests/modeltests/custom_columns/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Person(models.Model):
1515
def __str__(self):
1616
return '%s %s' % (self.first_name, self.last_name)
1717

18-
API_TESTS = """
18+
__test__ = {'API_TESTS':"""
1919
# Create a Person.
2020
>>> p = Person(first_name='John', last_name='Smith')
2121
>>> p.save()
@@ -50,4 +50,4 @@ def __str__(self):
5050
Traceback (most recent call last):
5151
...
5252
AttributeError: 'Person' object has no attribute 'last'
53-
"""
53+
"""}

tests/modeltests/custom_managers/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Car(models.Model):
5858
def __str__(self):
5959
return self.name
6060

61-
API_TESTS = """
61+
__test__ = {'API_TESTS':"""
6262
>>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True)
6363
>>> p1.save()
6464
>>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False)
@@ -104,4 +104,4 @@ def __str__(self):
104104
# to the first manager defined in the class. In this case, it's "cars".
105105
>>> Car._default_manager.order_by('name')
106106
[<Car: Corvette>, <Car: Neon>]
107-
"""
107+
"""}

tests/modeltests/custom_methods/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def articles_from_same_day_2(self):
3636
# positional arguments to Article().
3737
return [self.__class__(*row) for row in cursor.fetchall()]
3838

39-
API_TESTS = """
39+
__test__ = {'API_TESTS':"""
4040
# Create a couple of Articles.
4141
>>> from datetime import date
4242
>>> a = Article(id=None, headline='Area man programs in Python', pub_date=date(2005, 7, 27))
@@ -55,4 +55,4 @@ def articles_from_same_day_2(self):
5555
[<Article: Area man programs in Python>]
5656
>>> b.articles_from_same_day_2()
5757
[<Article: Area man programs in Python>]
58-
"""
58+
"""}

tests/modeltests/custom_pk/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Meta:
2727
def __str__(self):
2828
return self.name
2929

30-
API_TESTS = """
30+
__test__ = {'API_TESTS':"""
3131
>>> dan = Employee(employee_code='ABC123', first_name='Dan', last_name='Jones')
3232
>>> dan.save()
3333
>>> Employee.objects.all()
@@ -88,4 +88,4 @@ def __str__(self):
8888
>>> Business.objects.filter(employees__first_name__startswith='Fran')
8989
[<Business: Sears>]
9090
91-
"""
91+
"""}

tests/modeltests/empty/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Empty(models.Model):
1111
pass
1212

13-
API_TESTS = """
13+
__test__ = {'API_TESTS':"""
1414
>>> m = Empty()
1515
>>> m.id
1616
>>> m.save()
@@ -23,4 +23,4 @@ class Empty(models.Model):
2323
>>> existing = Empty(m.id)
2424
>>> existing.save()
2525
26-
"""
26+
"""}

tests/modeltests/field_defaults/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Article(models.Model):
1919
def __str__(self):
2020
return self.headline
2121

22-
API_TESTS = """
22+
__test__ = {'API_TESTS':"""
2323
>>> from datetime import datetime
2424
2525
# No articles are in the system yet.
@@ -48,4 +48,4 @@ def __str__(self):
4848
>>> d = now - a.pub_date
4949
>>> d.seconds < 5
5050
True
51-
"""
51+
"""}

tests/modeltests/generic_relations/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Mineral(models.Model):
5353
def __str__(self):
5454
return self.name
5555

56-
API_TESTS = """
56+
__test__ = {'API_TESTS':"""
5757
# Create the world in 7 lines of code...
5858
>>> lion = Animal(common_name="Lion", latin_name="Panthera leo")
5959
>>> platypus = Animal(common_name="Platypus", latin_name="Ornithorhynchus anatinus")
@@ -105,4 +105,4 @@ def __str__(self):
105105
[<TaggedItem: shiny>]
106106
>>> TaggedItem.objects.filter(content_type__pk=ctype.id, object_id=quartz.id)
107107
[<TaggedItem: clearish>]
108-
"""
108+
"""}

tests/modeltests/get_latest/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Person(models.Model):
2929
def __str__(self):
3030
return self.name
3131

32-
API_TESTS = """
32+
__test__ = {'API_TESTS':"""
3333
# Because no Articles exist yet, get_latest() raises ArticleDoesNotExist.
3434
>>> Article.objects.latest()
3535
Traceback (most recent call last):
@@ -76,4 +76,4 @@ def __str__(self):
7676
7777
>>> Person.objects.latest('birthday')
7878
<Person: Stephanie>
79-
"""
79+
"""}

tests/modeltests/get_or_create/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Person(models.Model):
1515
def __str__(self):
1616
return '%s %s' % (self.first_name, self.last_name)
1717

18-
API_TESTS = """
18+
__test__ = {'API_TESTS':"""
1919
# Acting as a divine being, create an Person.
2020
>>> from datetime import date
2121
>>> p = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9))
@@ -49,4 +49,4 @@ def __str__(self):
4949
False
5050
>>> Person.objects.count()
5151
2
52-
"""
52+
"""}

tests/modeltests/invalid_models/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SelfClashM2M(models.Model):
7878

7979

8080

81-
error_log = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute.
81+
model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute.
8282
invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute.
8383
invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute.
8484
invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.

tests/modeltests/lookup/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Meta:
1515
def __str__(self):
1616
return self.headline
1717

18-
API_TESTS = r"""
18+
__test__ = {'API_TESTS':r"""
1919
# Create a couple of Articles.
2020
>>> from datetime import datetime
2121
>>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26))
@@ -191,4 +191,4 @@ def __str__(self):
191191
>>> Article.objects.filter(headline__contains='\\')
192192
[<Article: Article with \ backslash>]
193193
194-
"""
194+
"""}

tests/modeltests/m2m_and_m2o/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Meta:
2121
ordering = ('num',)
2222

2323

24-
API_TESTS = """
24+
__test__ = {'API_TESTS':"""
2525
>>> Issue.objects.all()
2626
[]
2727
>>> r = User(username='russell')
@@ -62,4 +62,4 @@ class Meta:
6262
[<Issue: 1>, <Issue: 2>, <Issue: 3>]
6363
>>> Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id))
6464
[<Issue: 1>, <Issue: 2>, <Issue: 3>]
65-
"""
65+
"""}

tests/modeltests/m2m_intermediary/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Writer(models.Model):
3434
def __str__(self):
3535
return '%s (%s)' % (self.reporter, self.position)
3636

37-
API_TESTS = """
37+
__test__ = {'API_TESTS':"""
3838
# Create a few Reporters.
3939
>>> r1 = Reporter(first_name='John', last_name='Smith')
4040
>>> r1.save()
@@ -65,4 +65,4 @@ def __str__(self):
6565
<Article: This is a test>
6666
>>> r1.writer_set.all()
6767
[<Writer: John Smith (Main writer)>]
68-
"""
68+
"""}

tests/modeltests/m2m_multiple/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Meta:
2828
def __str__(self):
2929
return self.headline
3030

31-
API_TESTS = """
31+
__test__ = {'API_TESTS':"""
3232
>>> from datetime import datetime
3333
3434
>>> c1 = Category(name='Sports')
@@ -76,4 +76,4 @@ def __str__(self):
7676
[]
7777
>>> c4.secondary_article_set.all()
7878
[<Article: Area man steals>, <Article: Area man runs>]
79-
"""
79+
"""}

tests/modeltests/m2m_recursive/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Person(models.Model):
2222
def __str__(self):
2323
return self.name
2424

25-
API_TESTS = """
25+
__test__ = {'API_TESTS':"""
2626
>>> a = Person(name='Anne')
2727
>>> a.save()
2828
>>> b = Person(name='Bill')
@@ -189,4 +189,4 @@ def __str__(self):
189189
>>> d.stalkers.all()
190190
[<Person: Chuck>]
191191
192-
"""
192+
"""}

tests/modeltests/m2o_recursive/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Category(models.Model):
1919
def __str__(self):
2020
return self.name
2121

22-
API_TESTS = """
22+
__test__ = {'API_TESTS':"""
2323
# Create a few Category objects.
2424
>>> r = Category(id=None, name='Root category', parent=None)
2525
>>> r.save()
@@ -37,4 +37,4 @@ def __str__(self):
3737
[]
3838
>>> c.parent
3939
<Category: Root category>
40-
"""
40+
"""}

tests/modeltests/m2o_recursive2/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Person(models.Model):
1717
def __str__(self):
1818
return self.full_name
1919

20-
API_TESTS = """
20+
__test__ = {'API_TESTS':"""
2121
# Create two Person objects -- the mom and dad in our family.
2222
>>> dad = Person(full_name='John Smith Senior', mother=None, father=None)
2323
>>> dad.save()
@@ -40,4 +40,4 @@ def __str__(self):
4040
[]
4141
>>> kid.fathers_child_set.all()
4242
[]
43-
"""
43+
"""}

tests/modeltests/manipulators/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Album(models.Model):
2121
def __str__(self):
2222
return self.name
2323

24-
API_TESTS = """
24+
__test__ = {'API_TESTS':"""
2525
>>> from django.utils.datastructures import MultiValueDict
2626
2727
# Create a Musician object via the default AddManipulator.
@@ -88,4 +88,4 @@ def __str__(self):
8888
<Album: Ultimate Ella>
8989
>>> a2.release_date
9090
datetime.date(2005, 2, 13)
91-
"""
91+
"""}

tests/modeltests/many_to_many/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __str__(self):
2828
class Meta:
2929
ordering = ('headline',)
3030

31-
API_TESTS = """
31+
__test__ = {'API_TESTS':"""
3232
# Create a couple of Publications.
3333
>>> p1 = Publication(id=None, title='The Python Journal')
3434
>>> p1.save()
@@ -231,4 +231,4 @@ class Meta:
231231
>>> p1.article_set.all()
232232
[<Article: NASA uses Python>]
233233
234-
"""
234+
"""}

tests/modeltests/many_to_one/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __str__(self):
2525
class Meta:
2626
ordering = ('headline',)
2727

28-
API_TESTS = """
28+
__test__ = {'API_TESTS':"""
2929
# Create a few Reporters.
3030
>>> r = Reporter(first_name='John', last_name='Smith', email='[email protected]')
3131
>>> r.save()
@@ -263,4 +263,4 @@ class Meta:
263263
>>> Article.objects.all()
264264
[]
265265
266-
"""
266+
"""}

tests/modeltests/many_to_one_null/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Meta:
2323
def __str__(self):
2424
return self.headline
2525

26-
API_TESTS = """
26+
__test__ = {'API_TESTS':"""
2727
# Create a Reporter.
2828
>>> r = Reporter(name='John Smith')
2929
>>> r.save()
@@ -121,4 +121,4 @@ def __str__(self):
121121
>>> Article.objects.filter(reporter__isnull=True)
122122
[<Article: First>, <Article: Fourth>]
123123
124-
"""
124+
"""}

tests/modeltests/model_inheritance/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ItalianRestaurant(Restaurant):
2626
def __str__(self):
2727
return "%s the italian restaurant" % self.name
2828

29-
API_TESTS = """
29+
__test__ = {'API_TESTS':"""
3030
# Make sure Restaurant has the right fields in the right order.
3131
>>> [f.name for f in Restaurant._meta.fields]
3232
['id', 'name', 'address', 'serves_hot_dogs', 'serves_pizza']
@@ -50,4 +50,4 @@ def __str__(self):
5050
>>> ir.save()
5151
5252
53-
"""
53+
"""}

0 commit comments

Comments
 (0)