#24714: Tidy up usage of assertEqual in tests
-------------------------------------+-------------------------------------
     Reporter:  alasdairnicol        |                    Owner:
         Type:                       |  alasdairnicol
  Cleanup/optimization               |                   Status:  assigned
    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
-------------------------------------+-------------------------------------

Old description:

> There are a few places in the tests where we are using self.assertEqual
> that could be more idiomatic.
>
> {{{
> self.assertEqual(True, x)  # prefer self.assertTrue(x)
> self.assertEqual(False, x)  # prefer self.assertFalse(x)
> self.assertEqual(None, x)  # prefer self.assertIsNone(x)
> self.assertEqual(True, x in y) # prefer self.assertIn(x, y)
> self.assertEqual(True, x == y) # prefer self.assertEqual(x, y)
> self.assertEqual(False, x == y) # prefer self.assertNotEqual(x, y)
> }}}
>
> I found these using the following greps
>
> {{{
> grep -rI assertEqual.True
> grep -rI assertEqual.False
> grep -rI assertEqual.None
> }}}
>
> This is a similar tidy up to #23620

New description:

 There are a few places in the tests where we are using self.assertEqual
 that could be more idiomatic.

 {{{
 self.assertEqual(None, x)  # prefer self.assertIsNone(x)
 self.assertEqual(True, x in y) # prefer self.assertIn(x, y)


 self.assertEqual(True, x)  # self.assertTrue(x) may be appropriate, but
 care is needed because it will pass for truthy values
 self.assertEqual(False, x)  # prefer self.assertFalse(x) may be
 appropriate, but care is needed because it will pass for falsey values
 self.assertEqual(True, x == y) # prefer self.assertEqual(x, y)
 }}}

 I found these using the following greps

 {{{
 grep -rI assertEqual.True
 grep -rI assertEqual.False
 grep -rI assertEqual.None
 }}}

 This is a similar tidy up to #23620

--

Comment (by alasdairnicol):

 As mentioned by Tim on the pull request, it is not always appropriate to
 use `self.assertTrue` and `self.assertFalse`, as these will pass for
 truthy and falsey values. I have updated the ticket description and pull
 request.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.8611317b4005729ccbeb8239a81c4def%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to