[Django] #26747: Use more specific assertions in tests

4 views
Skip to first unread message

Django

unread,
Jun 11, 2016, 4:37:47 PM6/11/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+--------------------
Reporter: jdufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Like #23620. I found more patterns that could use more specific
assertions.

Example patterns:

{{{
#!python
self.assertEqual(expression, False)
self.assertEqual(expression, True)
self.assertEqual(expression, None)
self.assertNotEqual(expression, None)
}}}

Will change these to:

{{{
#!python
self.assertFalse(expression)
self.assertTrue(expression)
self.assertIsNone(expression)
self.assertIsNotNone(expression)
}}}

Python docs on assertions: https://docs.python.org/3/library/unittest.html
#assert-methods

--
Ticket URL: <https://code.djangoproject.com/ticket/26747>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 11, 2016, 4:40:05 PM6/11/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
-------------------------------------+-------------------------------------
Reporter: jdufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Uncategorized | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jdufresne):

* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0


Comment:

https://github.com/django/django/pull/6760

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:1>

Django

unread,
Jun 11, 2016, 9:11:59 PM6/11/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+------------------------------------

Reporter: jdufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* component: Uncategorized => Core (Other)
* stage: Unreviewed => Accepted


Comment:

As noted on the PR, I'm not convinced about the merits of
`assertTrue`/`False` rather than `assertEqual(val, True)` since such the
former pass if bool(val) is `True`/`False` which might be too loose.

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:2>

Django

unread,
Jun 12, 2016, 3:37:24 PM6/12/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+------------------------------------

Reporter: jdufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by jdufresne):

* needs_better_patch: 1 => 0


Comment:

Incorporated suggestion. Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:3>

Django

unread,
Jun 16, 2016, 2:19:40 PM6/16/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+------------------------------------
Reporter: jdufresne | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"4f336f66523001b009ab038b10848508fd208b3b" 4f336f6]:
{{{
#!CommitTicketReference repository=""
revision="4f336f66523001b009ab038b10848508fd208b3b"
Fixed #26747 -- Used more specific assertions in the Django test suite.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:4>

Django

unread,
Jun 16, 2016, 2:22:05 PM6/16/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+------------------------------------
Reporter: jdufresne | Owner: nobody

Type: Cleanup/optimization | Status: closed
Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"13d60298ea2a07242dc3952a9dfcd9c8857bf1f9" 13d60298]:
{{{
#!CommitTicketReference repository=""
revision="13d60298ea2a07242dc3952a9dfcd9c8857bf1f9"
[1.10.x] Fixed #26747 -- Used more specific assertions in the Django test
suite.

Backport of 4f336f66523001b009ab038b10848508fd208b3b from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:5>

Django

unread,
Aug 19, 2016, 11:10:45 AM8/19/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+------------------------------------
Reporter: jdufresne | Owner: nobody

Type: Cleanup/optimization | Status: closed
Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7b08e01c1358aedbd46fa26c91d4613d642ff609" 7b08e01c]:
{{{
#!CommitTicketReference repository=""
revision="7b08e01c1358aedbd46fa26c91d4613d642ff609"
Refs #26747 -- Corrected a method name in tutorial05.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:6>

Django

unread,
Aug 19, 2016, 11:10:59 AM8/19/16
to django-...@googlegroups.com
#26747: Use more specific assertions in tests
--------------------------------------+------------------------------------
Reporter: jdufresne | Owner: nobody

Type: Cleanup/optimization | Status: closed
Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"e5103de2d1a461544b73542df3ed0ad71a73dc21" e5103de]:
{{{
#!CommitTicketReference repository=""
revision="e5103de2d1a461544b73542df3ed0ad71a73dc21"
[1.10.x] Refs #26747 -- Corrected a method name in tutorial05.

Backport of 7b08e01c1358aedbd46fa26c91d4613d642ff609 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26747#comment:7>

Reply all
Reply to author
Forward
0 new messages