Python's unittest framework assertTrue and assertFalse methods don't
check that the provided value is False or True, like the documentation
says:
Note that this is equivalent to bool(expr) is True and not to expr is
True (use assertIs(expr, True) for the latter).
According to the documentation we should try to avoid using it as much
as possible:
This method should also be avoided when more specific methods are
available (e.g. assertEqual(a, b) instead of assertTrue(a == b)),
because they provide a better error message in case of failure.
But in our current code we keep abusing its use in many ways, among
which we can easily find the following:
- Thinking it only matches False/True
- assertTrue(expected, actual) --> This will always be true as long as
bool(expected) is True, because actual is interpreted as the message to
return on failure.
- Incorrectly testing values, like checking for a tuple of the form
(True, {...}) instead of testing for True in the first position.
This patch fixes incorrect some of the incorrect uses of the methods and
overwrites default methods so that they behave the way many people think
they do:
- assertTrue(x) == assertIs(True,x)
- assertFalse(x) == assertIs(False,x)
This will hopefully help us prevent incorrect usage of the methods.
Change-Id: I1e8c82702932e6b6d940bd83d0a2d4494576a81b