what are booleans?
Imagine we divide the universe in two and the options are things that are the True group and the False group. These are the booleans: True and False.
I used assertIs and assertIsNot in test_assertion_error_w_false and test_assertion_error_w_true in the assertion_error project, where I saw that
I want to test what groups Python places the objects seen so far (None, integers, floats, strings, tuples, lists, sets and dictionaries). Which do you think will be in the False group or the True group?
preview
I have these tests by the end of the chapter
1import unittest
2
3
4class TestBooleans(unittest.TestCase):
5
6 def test_what_is_false(self):
7 self.assertIsInstance(False, (bool, int))
8 self.assertNotIsInstance(
9 False,
10 (
11 float, tuple, str,
12 list, set, dict,
13 )
14 )
15 self.assertIs(False, False)
16 self.assertIs(bool(False), False)
17 self.assertFalse(bool(False))
18 self.assertFalse(False)
20 def test_what_is_true(self):
21 self.assertIsInstance(True, (bool, int))
22 self.assertNotIsInstance(
23 True,
24 (
25 float, tuple, str,
26 list, set, dict,
27 )
28 )
29 self.assertIs(True, True)
30 self.assertIs(bool(True), True)
31 self.assertTrue(bool(True))
32 self.assertTrue(True)
34 def assert_is_not_the_same_as_false_or_true(self, an_object):
35 self.assertNotEqual(an_object, False)
36 self.assertIsNot(an_object, False)
37 self.assertNotEqual(an_object, True)
38 self.assertIsNot(an_object, True)
39
40 def assert_is_falsy(self, an_object):
41 self.assert_is_not_the_same_as_false_or_true(an_object)
42 self.assertFalse(bool(an_object))
43 self.assertFalse(an_object)
45 def assert_is_truthy(self, an_object):
46 self.assert_is_not_the_same_as_false_or_true(an_object)
47 self.assertTrue(bool(an_object))
48 self.assertTrue(an_object)
49
50 def test_is_none_falsy_or_truthy(self):
51 self.assert_is_falsy(None)
53 def test_is_an_integer_falsy_or_truthy(self):
54 self.assert_is_truthy(-1)
55
56 self.assertEqual(0, False)
57 self.assertIsNot(0, False)
58 self.assertNotEqual(0, True)
59 self.assertIsNot(0, True)
60 self.assertFalse(bool(0))
61 self.assertFalse(0)
62
63 a_positive_integer = 1
64 self.assertNotEqual(a_positive_integer, False)
65 self.assertIsNot(a_positive_integer, False)
66 self.assertEqual(1, True)
67 self.assertIsNot(a_positive_integer, True)
68 self.assertTrue(bool(a_positive_integer))
69 self.assertTrue(a_positive_integer)
71 def test_is_a_float_falsy_or_truthy(self):
72 self.assert_is_truthy(-0.1)
73
74 self.assertEqual(0.0, False)
75 self.assertIsNot(0.0, False)
76 self.assertNotEqual(0.0, True)
77 self.assertIsNot(0.0, True)
78 self.assertFalse(bool(0.0))
79 self.assertFalse(0.0)
80
81 self.assert_is_truthy(0.1)
83 def test_is_a_string_falsy_or_truthy(self):
84 self.assert_is_falsy(str())
85 self.assert_is_truthy('string with things')
86
87 def test_is_a_tuple_falsy_or_truthy(self):
88 self.assert_is_falsy(tuple())
89 self.assert_is_truthy((0, 1, 2, 'n'))
91 def test_is_a_list_falsy_or_truthy(self):
92 self.assert_is_falsy(list())
93 self.assert_is_truthy([0, 1, 2, 'n'])
94
95 def test_is_a_set_falsy_or_truthy(self):
96 self.assert_is_falsy(set())
97 self.assert_is_truthy({0, 1, 2, 'n'})
98
99 def test_is_a_dictionary_falsy_or_truthy(self):
100 self.assert_is_falsy(dict())
101 self.assert_is_truthy({'key': 'value'})
104# NOTES
105# the value of True is 1
106# bool(a dictionary with things) is True
107# bool(a set with things) is True
108# bool(a list with things) is True
109# bool(a tuple with things) is True
110# bool(a string with things) is True
111# bool(a positive number) is True
112# bool(a negative number) is True
113# True is True
114# True is an integer
115# True is a boolean
116# True is NOT False
117# the value of False is 0
118# bool(the empty dictionary) is False
119# bool(the empty set) is False
120# bool(the empty list) is False
121# bool(the empty tuple) is False
122# bool(the empty string) is False
123# bool(zero) is False
124# bool(None) is False
125# False is False
126# False is an integer
127# False is a boolean
128# False is NOT True
129
130
131# Exceptions seen
132# AssertionError
questions about Booleans
Questions to think about as we divide Python’s basic objects into False and True
start the project
I name this project
booleansI open a terminal
I use uv to make a directory for the project and initialize it
uv init booleansI change directory to the project
cd booleansI make a directory for the tests
mkdir testsI make the
testsdirectory a Python packageDanger
use 2 underscores (__) before and after
initfor__init__.pynot_init_.pytouch tests/__init__.pyNew-Item tests/__init__.pyI make an empty file for the tests in the
testsfoldertouch tests/test_booleans.pyNew-Item tests/test_booleans.pyI open
test_booleans.pyI add the first failing test to
test_booleans.py1import unittest 2 3 4class TestBooleans(unittest.TestCase): 5 6 def test_failure(self): 7 self.assertEqual(False, True)I go back to the terminal
I use echo to add pytest to
requirements.txtecho "pytest" > requirements.txtI add pytest-watcher to the requirements file
echo "pytest-watcher" >> requirements.txtthe terminal goes back to the command line.
I use Out-File to add pytest to
requirements.txt"pytest" | Out-File requirements.txt -Encoding UTF8I add pytest-watcher to the requirements file
"pytest-watcher" >> requirements.txt
I use uv to install pytest-watcher with the requirements file
uv add --requirement requirements.txtI add the new files and folder to git for tracking
git add .I add a git commit message
git commit --all --message \ 'setup project'I use pytest-watcher to run the tests automatically
uv run pytest-watcher . --nowthe terminal is my friend, and shows AssertionError
======================== FAILURES ======================== _______________ TestBooleans.test_failure ________________ self = <tests.test_booleans.TestBooleans testMethod=test_failure> def test_failure(self): > self.assertEqual(False, True) E AssertionError: False != True tests/test_booleans.py:7: AssertionError ================ short test summary info ================= FAILED tests/test_booleans.py::TestBooleans::test_failure - AssertionError: False != True =================== 1 failed in X.YZs ====================if the terminal does not show the same error, then check if
your
tests/__init__.pyhas two underscores (__) before and afterinitfor__init__.pynot_init_.pyyou ran
echo "pytest-watcher" >> requirements.txt, to addpytest-watcherto the requirements file
and try
uv run pytest-watcher . --nowagainI add AssertionError to the list of Exceptions seen, in
test_booleans.py4class TestBooleans(unittest.TestCase): 5 6 def test_failure(self): 7 self.assertEqual(False, True) 8 9 10# Exceptions seen 11# AssertionErrorI change True to False in the assertion
6 def test_failure(self): 7 # self.assertEqual(False, True) 8 self.assertEqual(False, False) 9 10 11# Exceptions seenthe test passes.
test_what_is_false
RED: make it fail
I remove test_failure
I add test_what_is_false with assertNotIsInstance
4class TestBooleans(unittest.TestCase):
5
6 def test_what_is_false(self):
7 self.assertNotIsInstance(False, bool)
8
9
10# Exceptions seen
11# AssertionError
the terminal is my friend, and shows AssertionError
AssertionError: False is an instance
of <class 'bool'>
this was also in test_is_none_a_boolean.
GREEN: make it pass
I change assertNotIsInstance to the assertIsInstance method
6 def test_what_is_false(self):
7 # self.assertNotIsInstance(False, bool)
8 self.assertIsInstance(False, bool)
9
10
11# Exceptions seen
the test passes.
REFACTOR: make it better
I add a comment
6 def test_what_is_false(self): 7 # self.assertNotIsInstance(False, bool) 8 self.assertIsInstance(False, bool) 9 10 11# NOTES 12# False is a boolean 13 14 15# Exceptions seen 16# AssertionErroralso from test_is_none_a_boolean.
test_when_year_of_birth_is_not_an_integer showed me that False is an integer. I add an assertion for it
6 def test_what_is_false(self): 7 # self.assertNotIsInstance(False, bool) 8 self.assertIsInstance(False, bool) 9 self.assertNotIsInstance(False, int) 10 11 12# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is an instance of <class 'int'>I add a comment
12# NOTES 13# False is an integer 14# False is a boolean 15 16 17# Exceptions seen 18# AssertionErrorI change assertNotIsInstance to assertIsInstance
6 def test_what_is_false(self): 7 # self.assertNotIsInstance(False, bool) 8 self.assertIsInstance(False, bool) 9 # self.assertNotIsInstance(False, int) 10 self.assertIsInstance(False, int) 11 12 13# NOTESthe test passes.
how to test if something is an instance of more than one object
The instance methods can take a tuple of objects.
-
6 def test_what_is_false(self): 7 # self.assertNotIsInstance(False, bool) 8 self.assertIsInstance(False, bool) 9 # self.assertNotIsInstance(False, int) 10 self.assertIsInstance(False, int) 11 self.assertNotIsInstance(False, (bool, int)) 12 13 14# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is an instance of <class 'bool'> I change assertNotIsInstance to assertIsInstance for
(False, (bool, int))6 def test_what_is_false(self): 7 # self.assertNotIsInstance(False, bool) 8 self.assertIsInstance(False, bool) 9 # self.assertNotIsInstance(False, int) 10 self.assertIsInstance(False, int) 11 # self.assertNotIsInstance(False, (bool, int)) 12 self.assertIsInstance(False, (bool, int)) 13 14 15# NOTESthe test passes.
I comment out the first assertions since they are covered by the new one
6 def test_what_is_false(self): 7 # self.assertNotIsInstance(False, bool) 8 # self.assertIsInstance(False, bool) 9 # self.assertNotIsInstance(False, int) 10 # self.assertIsInstance(False, int) 11 # self.assertNotIsInstance(False, (bool, int)) 12 self.assertIsInstance(False, (bool, int)) 13 14 15# NOTESI add an assertion to test if False is a float
11 # self.assertNotIsInstance(False, (bool, int)) 12 self.assertIsInstance(False, (bool, int)) 13 self.assertIsInstance(False, float) 14 15 16# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of <class 'float'>I change assertIsInstance to assertNotIsInstance for
(False, float)11 # self.assertNotIsInstance(False, (bool, int)) 12 self.assertIsInstance(False, (bool, int)) 13 # self.assertIsInstance(False, float) 14 self.assertNotIsInstance(False, float) 15 16 17# NOTESthe test passes.
I add an assertion to test if False is a string
13 # self.assertIsInstance(False, float) 14 self.assertNotIsInstance(False, float) 15 self.assertIsInstance(False, str) 16 17 18# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of <class 'str'>I change assertIsInstance to assertNotIsInstance for
(False, str)13 # self.assertIsInstance(False, float) 14 self.assertNotIsInstance(False, float) 15 # self.assertIsInstance(False, str) 16 self.assertNotIsInstance(False, str) 17 18 19# NOTESthe test passes.
I add an assertion to test if False is a tuple
15 # self.assertIsInstance(False, str) 16 self.assertNotIsInstance(False, str) 17 self.assertIsInstance(False, tuple) 18 19 20# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of <class 'tuple'>I change assertIsInstance to assertNotIsInstance for
(False, tuple)15 # self.assertIsInstance(False, str) 16 self.assertNotIsInstance(False, str) 17 # self.assertIsInstance(False, tuple) 18 self.assertNotIsInstance(False, tuple) 19 20 21# NOTESthe test passes.
I add an assertion to test if False is a list
17 # self.assertIsInstance(False, tuple) 18 self.assertNotIsInstance(False, tuple) 19 self.assertIsInstance(False, list) 20 21 22# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of <class 'list'>I change assertIsInstance to assertNotIsInstance for
(False, list)17 # self.assertIsInstance(False, tuple) 18 self.assertNotIsInstance(False, tuple) 19 # self.assertIsInstance(False, list) 20 self.assertNotIsInstance(False, list) 21 22 23# NOTESthe test passes.
I add an assertion to test if False is a set
19 # self.assertIsInstance(False, list) 20 self.assertNotIsInstance(False, list) 21 self.assertIsInstance(False, set) 22 23 24# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of <class 'set'>I change assertIsInstance to assertNotIsInstance for
(False, set)19 # self.assertIsInstance(False, list) 20 self.assertNotIsInstance(False, list) 21 # self.assertIsInstance(False, set) 22 self.assertNotIsInstance(False, set) 23 24 25# NOTESthe test passes.
I add an assertion to test if False is a dictionary
21 # self.assertIsInstance(False, set) 22 self.assertNotIsInstance(False, set) 23 self.assertIsInstance(False, dict) 24 25 26# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of <class 'dict'>I change assertIsInstance to assertNotIsInstance for
(False, dict)21 # self.assertIsInstance(False, set) 22 self.assertNotIsInstance(False, set) 23 # self.assertIsInstance(False, dict) 24 self.assertNotIsInstance(False, dict) 25 26 27# NOTESthe test passes.
I use a tuple with float, str, tuple, list, set and dict with a call to assertIsInstance
24 self.assertNotIsInstance(False, dict) 25 self.assertIsInstance( 26 False, 27 ( 28 float, tuple, str, 29 list, set, dict, 30 ) 31 ) 32 33 34# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not an instance of any of ( <class 'float'>, <class 'tuple'>, <class 'str'>, <class 'list'>, <class 'set'>, <class 'dict'> )I change assertIsInstance to assertNotIsInstance
24 self.assertNotIsInstance(False, dict) 25 # self.assertIsInstance( 26 self.assertNotIsInstance( 27 False, 28 ( 29 float, tuple, str, 30 list, set, dict, 31 ) 32 ) 33 34 35# NOTESthe test passes.
I use the assertIsNot method like I did in test_assertion_error_w_false
26 self.assertNotIsInstance( 27 False, 28 ( 29 float, tuple, str, 30 list, set, dict, 31 ) 32 ) 33 self.assertIsNot(False, False) 34 35 36# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: unexpectedly identical: Falsebecause False is False.
I change assertIsNot to assertIs for
(False, False)26 self.assertNotIsInstance( 27 False, 28 ( 29 float, tuple, str, 30 list, set, dict, 31 ) 32 ) 33 # self.assertIsNot(False, False) 34 self.assertIs(False, False) 35 36 37# NOTESthe test passes. I know this from test_assertion_error_w_false.
how to test if something is grouped as False
I can test if Python groups an object as False with the bool built-in function from The Python Standard Library. It returns False or True for the object given in parentheses.
RED: make it fail
I add an assertion with a call to bool
33 # self.assertIsNot(False, False) 34 self.assertIs(False, False) 35 self.assertIsNot(bool(False), False) 36 37 38# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: unexpectedly identical: Falsebecause this happens when
assertIsNot(bool(False), False)runsassertIsNot(bool(False), False) assertIsNot(False , False)which raises AssertionError since False, which is the result of
bool(False)is False.bool(anything)returns False or True for the thing in parentheses.
I add a comment
38# NOTES 39# False is False 40# False is an integer 41# False is a boolean 42 43 44# Exceptions seen 45# AssertionError
GREEN: make it pass
I change the assertIsNot to assertIs to make the statement True
33 # self.assertIsNot(False, False)
34 self.assertIs(False, False)
35 # self.assertIsNot(bool(False), False)
36 self.assertIs(bool(False), False)
37
38
39# NOTES
the test passes because bool(False) is equal to False.
another way to test if something is grouped as False
The unittest.TestCase class has a method I can use to test if the result of calling the bool built-in function with an object is False - assertFalse.
assertFalse(an_object)
which is like
assertIs(bool(an_object), False)
it raises AssertionError if the object in parentheses is grouped as True.
RED: make it fail
I add assertFalse to the test
35 # self.assertIsNot(bool(False), False) 36 self.assertIs(bool(False), False) 37 self.assertFalse(bool(True)) 38 39 40# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause this happens when
assertFalse(bool(True))runsassertFalse(bool(True)) assertFalse(True)which raises AssertionError since the result of
bool(True)is True, not False.I add a comment
40# NOTES 41# True is NOT False 42# False is False 43# False is an integer 44# False is a boolean
GREEN: make it pass
I change True to False in the parentheses
35 # self.assertIsNot(bool(False), False)
36 self.assertIs(bool(False), False)
37 # self.assertFalse(bool(True))
38 self.assertFalse(bool(False))
39
40
41# NOTES
the test passes because bool(False) is False.
REFACTOR: make it better
I can skip bool and get the same result. I add another call to the assertFalse method
37 # self.assertFalse(bool(True)) 38 self.assertFalse(bool(False)) 39 self.assertFalse(True) 40 41 42# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause
bool(True)is True.I change True to False in the parentheses
37 # self.assertFalse(bool(True)) 38 self.assertFalse(bool(False)) 39 # self.assertFalse(True) 40 self.assertFalse(False) 41 42 43# NOTESthe test passes because
bool(False)is False.The assertFalse method raises AssertionError if the result of a call to the bool built-in function with an object is True.
I remove the commented lines and single instance tests for float, str, tuple, list, set and dict
4class TestBooleans(unittest.TestCase): 5 6 def test_what_is_false(self): 7 self.assertIsInstance(False, (bool, int)) 8 self.assertNotIsInstance( 9 False, 10 ( 11 float, tuple, str, 12 list, set, dict, 13 ) 14 ) 15 self.assertIs(False, False) 16 self.assertIs(bool(False), False) 17 self.assertFalse(bool(False)) 18 self.assertFalse(False) 19 20 21# NOTESI open a new terminal then make sure I am in the
booleansfoldercd booleansI add a git commit message in the new terminal
git commit --all --message \ 'add test_what_is_false'assertFalse(an_object)is likeassertIs(bool(an_object), False), with less words.
test_what_is_true
RED: make it fail
I add test_what_is_true with assertNotIsInstance
17 self.assertFalse(bool(False))
18 self.assertFalse(False)
19
20 def test_what_is_true(self):
21 self.assertNotIsInstance(True, (bool, int))
22
23
24# NOTES
the terminal is my friend, and shows AssertionError
AssertionError: True is an instance
of <class 'bool'>
this was also in test_is_none_a_boolean, without the tuple of objects.
GREEN: make it pass
I change assertNotIsInstance to the assertIsInstance method
18 self.assertFalse(False)
19
20 def test_what_is_true(self):
21 # self.assertNotIsInstance(True, (bool, int))
22 self.assertIsInstance(True, (bool, int))
23
24
25 # NOTES
the test passes.
REFACTOR: make it better
I add comments
25# NOTES 26# True is an integer 27# True is a boolean 28# True is NOT False 29# False is False 30# False is an integer 31# False is a boolean 32 33 34# Exceptions seen 35# AssertionErrorI add a call to assertIsInstance with a tuple that has float, str, tuple, list, set and dict
22 self.assertIsInstance(True, (bool, int)) 23 self.assertIsInstance( 24 True, 25 ( 26 float, tuple, str, 27 list, set, dict, 28 ) 29 ) 30 31 32# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not an instance of any of ( <class 'float'>, <class 'tuple'>, <class 'str'>, <class 'list'>, <class 'set'>, <class 'dict'> )I change assertIsInstance to the assertNotIsInstance method
22 self.assertIsInstance(True, (bool, int)) 23 # self.assertIsInstance( 24 self.assertNotIsInstance( 25 True, 26 ( 27 float, tuple, str, 28 list, set, dict, 29 ) 30 ) 31 32 33# NOTESthe test passes.
I use the assertIsNot method like I did in test_assertion_error_w_true
24 self.assertNotIsInstance( 25 True, 26 ( 27 float, tuple, str, 28 list, set, dict, 29 ) 30 ) 31 self.assertIsNot(True, True) 32 33 34# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: unexpectedly identical: Truebecause True is True.
I change assertIsNot to assertIs for
(True, True)24 self.assertNotIsInstance( 25 True, 26 ( 27 float, tuple, str, 28 list, set, dict, 29 ) 30 ) 31 # self.assertIsNot(True, True) 32 self.assertIs(True, True) 33 34 35# NOTESthe test passes. I know this from test_assertion_error_w_true.
how to test if something is grouped as True
I can test if Python groups an object as True with the bool built-in function since it returns False or True for the object given in parentheses.
RED: make it fail
I add an assertion with a call to bool
31 # self.assertIsNot(True, True) 32 self.assertIs(True, True) 33 self.assertIsNot(bool(True), True) 34 35 36# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: unexpectedly identical: Truebecause this happens when
assertIsNot(bool(True), True)runsassertIsNot(bool(True), True) assertIsNot(True , True)which raises AssertionError since True, which is the result of
bool(True)is True.bool(anything)returns False or True for the thing in parentheses.
I add a comment
36# NOTES 37# True is True 38# True is an integer 39# True is a boolean 40# True is NOT False 41# False is False 42# False is an integer 43# False is a boolean
GREEN: make it pass
I change assertIsNot to assertIs
31 # self.assertIsNot(True, True)
32 self.assertIs(True, True)
33 # self.assertIsNot(bool(True), True)
34 self.assertIs(bool(True), True)
35
36
37# NOTES
the test passes because bool(True) is True.
another way to test if something is grouped as True
The unittest.TestCase class has a method I can use to test if the result of calling the bool built-in function with an object is True - assertTrue.
assertTrue(an_object)
which is like
assertIs(bool(an_object), True)
it raises AssertionError if the object in parentheses is grouped as False.
RED: make it fail
I add assertTrue to the test
33 # self.assertIsNot(bool(True), True) 34 self.assertIs(bool(True), True) 35 self.assertTrue(bool(False)) 36 37 38# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause this happens when
assertTrue(bool(False))runsassertTrue(bool(False)) assertTrue(False)which raises AssertionError since the result of
bool(False)is False not True.I add a comment
38# NOTES 39# True is True 40# True is an integer 41# True is a boolean 42# True is NOT False 43# False is False 44# False is an integer 45# False is a boolean 46# False is NOT True 47 48 49# Exceptions seen 50# AssertionError
GREEN: make it pass
I change False to True in the parentheses
33 # self.assertIsNot(bool(True), True)
34 self.assertIs(bool(True), True)
35 # self.assertTrue(bool(False))
36 self.assertTrue(bool(True))
37
38
39# NOTES
the test passes because bool(True) is True.
REFACTOR: make it better
I add another call to the assertTrue method without bool to show that I can skip it
35 # self.assertTrue(bool(False)) 36 self.assertTrue(bool(True)) 37 self.assertTrue(False) 38 39 40# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause
bool(False)is False.I change False to True in the parentheses
35 # self.assertTrue(bool(False)) 36 self.assertTrue(bool(True)) 37 # self.assertTrue(False) 38 self.assertTrue(True) 39 40 41# NOTESthe test passes because
bool(True)is True.The assertTrue method raises AssertionError if the result of a call to the bool built-in function with an object is False.
I remove the commented lines from test_what_is_true
20 def test_what_is_true(self): 21 self.assertIsInstance(True, (bool, int)) 22 self.assertNotIsInstance( 23 True, 24 ( 25 float, tuple, str, 26 list, set, dict, 27 ) 28 ) 29 self.assertIs(True, True) 30 self.assertIs(bool(True), True) 31 self.assertTrue(bool(True)) 32 self.assertTrue(True) 33 34 35# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_what_is_true'
test_is_none_falsy_or_truthy
Is None grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test to see if None is grouped as False or True
32 self.assertTrue(True) 33 34 def test_is_none_falsy_or_truthy(self): 35 self.assertEqual(None, False) 36 37 38# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: None != False
GREEN: make it pass
I change assertEqual to assertNotEqual for None, False
34 def test_is_none_falsy_or_truthy(self):
35 # self.assertEqual(None, False)
36 self.assertNotEqual(None, False)
37
38
39# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if None is the same object as False
34 def test_is_none_falsy_or_truthy(self): 35 # self.assertEqual(None, False) 36 self.assertNotEqual(None, False) 37 self.assertIs(None, False) 38 39 40# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: None is not FalseI change assertIs to assertIsNot for
None, False34 def test_is_none_falsy_or_truthy(self): 35 # self.assertEqual(None, False) 36 self.assertNotEqual(None, False) 37 # self.assertIs(None, False) 38 self.assertIsNot(None, False) 39 40 41# NOTESthe test passes because None is not the same object as False.
I add an assertion for if None is equal to True
37 # self.assertIs(None, False) 38 self.assertIsNot(None, False) 39 self.assertEqual(None, True) 40 41 42# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: None != TrueI change assertEqual to assertNotEqual for
None, True37 # self.assertIs(None, False) 38 self.assertIsNot(None, False) 39 # self.assertEqual(None, True) 40 self.assertNotEqual(None, True) 41 42 43# NOTESthe test passes.
I add an assertion for if None is the same object as True
39 # self.assertEqual(None, True) 40 self.assertNotEqual(None, True) 41 self.assertIs(None, True) 42 43 44# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: None is not TrueI change assertIs to assertIsNot for
None, True39 # self.assertEqual(None, True) 40 self.assertNotEqual(None, True) 41 # self.assertIs(None, True) 42 self.assertIsNot(None, True) 43 44 45# NOTESthe test passes because None is not the same object as True.
I add an assertion for
bool(None)41 # self.assertIs(None, True) 42 self.assertIsNot(None, True) 43 self.assertTrue(bool(None)) 44 45 46# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(None)is False.I change assertTrue to assertFalse for
bool(None)41 # self.assertIs(None, True) 42 self.assertIsNot(None, True) 43 # self.assertTrue(bool(None)) 44 self.assertFalse(bool(None)) 45 46 47# NOTESthe test passes.
I add a comment
47# NOTES 48# True is True 49# True is an integer 50# True is a boolean 51# True is NOT False 52# bool(None) is False 53# False is FalseI add an assertion for None without bool
43 # self.assertTrue(bool(None)) 44 self.assertFalse(bool(None)) 45 self.assertTrue(None) 46 47 48# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: None is not trueA reminder of test_assertion_error_w_true.
I change assertTrue to assertFalse for None
43 # self.assertTrue(bool(None)) 44 self.assertFalse(bool(None)) 45 # self.assertTrue(None) 46 self.assertFalse(None) 47 48 49# NOTESthe test passes because the result of
bool(None)is False.I remove the commented lines from test_is_none_falsy_or_truthy
34 def test_is_none_falsy_or_truthy(self): 35 self.assertNotEqual(None, False) 36 self.assertIsNot(None, False) 37 self.assertNotEqual(None, True) 38 self.assertIsNot(None, True) 39 self.assertFalse(bool(None)) 40 self.assertFalse(None) 41 42 43# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_none_falsy_or_truthy'
test_is_an_integer_falsy_or_truthy
Is an integer grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if an integer (a whole number without decimals) is grouped as False or True
40 self.assertFalse(None) 41 42 def test_is_an_integer_falsy_or_truthy(self): 43 self.assertEqual(-1, False) 44 45 46# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -1 != False
GREEN: make it pass
I change assertEqual to assertNotEqual for -1, False
42 def test_is_an_integer_falsy_or_truthy(self):
43 # self.assertEqual(-1, False)
44 self.assertNotEqual(-1, False)
45
46
47# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if a negative integer is the same object as False
42 def test_is_an_integer_falsy_or_truthy(self): 43 # self.assertEqual(-1, False) 44 self.assertNotEqual(-1, False) 45 self.assertIs(-1, False) 46 47 48# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -1 is not FalseI change assertIs to assertIsNot for
-1, False42 def test_is_an_integer_falsy_or_truthy(self): 43 # self.assertEqual(-1, False) 44 self.assertNotEqual(-1, False) 45 # self.assertIs(-1, False) 46 self.assertIsNot(-1, False) 47 48 49# NOTESthe test passes because an integer is not the same object as False.
I add an assertion for if a negative integer is equal to True
45 # self.assertIs(-1, False) 46 self.assertIsNot(-1, False) 47 self.assertEqual(-1, True) 48 49 50# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -1 != TrueI change assertEqual to assertNotEqual for
-1, True45 # self.assertIs(-1, False) 46 self.assertIsNot(-1, False) 47 # self.assertEqual(-1, True) 48 self.assertNotEqual(-1, True) 49 50 51# NOTESthe test passes.
I add an assertion for if a negative integer is the same object as True
47 # self.assertEqual(-1, True) 48 self.assertNotEqual(-1, True) 49 self.assertIs(-1, True) 50 51 52# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -1 is not TrueI change assertIs to assertIsNot for
-1, True47 # self.assertEqual(-1, True) 48 self.assertNotEqual(-1, True) 49 # self.assertIs(-1, True) 50 self.assertIsNot(-1, True) 51 52 53# NOTESthe test passes because an integer is not the same object as True.
I add an assertion for
bool(-1)49 # self.assertIs(-1, True) 50 self.assertIsNot(-1, True) 51 self.assertFalse(bool(-1)) 52 53 54# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsethis means the result of
bool(-1)is True.I change assertFalse to assertTrue for
bool(-1)49 # self.assertIs(-1, True) 50 self.assertIsNot(-1, True) 51 # self.assertFalse(bool(-1)) 52 self.assertTrue(bool(-1)) 53 54 55# NOTESthe test passes.
I use
-1for all the integers (whole numbers without decimals) that are smaller than0.
I add a comment
55# NOTES 56# bool(-1) is True 57# True is True 58# True is an integerI add an assertion for
-1without bool51 # self.assertFalse(bool(-1)) 52 self.assertTrue(bool(-1)) 53 self.assertFalse(-1) 54 55 56# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -1 is not falsebecause the result of
bool(-1)is True.I change assertFalse to assertTrue for
-151 # self.assertFalse(bool(-1)) 52 self.assertTrue(bool(-1)) 53 # self.assertFalse(-1) 54 self.assertTrue(-1) 55 56 57# NOTESI add a variable for
-142 def test_is_an_integer_falsy_or_truthy(self): 43 a_negative_integer = -1 44 # self.assertEqual(-1, False)I use the variable to remove repetition of
-142 def test_is_an_integer_falsy_or_truthy(self): 43 a_negative_integer = -1 44 # self.assertEqual(-1, False) 45 # self.assertNotEqual(-1, False) 46 self.assertNotEqual(a_negative_integer, False) 47 # self.assertIs(-1, False) 48 # self.assertIsNot(-1, False) 49 self.assertIsNot(a_negative_integer, False)50 # self.assertEqual(-1, True) 51 # self.assertNotEqual(-1, True) 52 self.assertNotEqual(a_negative_integer, True) 53 # self.assertIs(-1, True) 54 # self.assertIsNot(-1, True) 55 self.assertIsNot(a_negative_integer, True)57 # self.assertFalse(bool(-1)) 58 # self.assertTrue(bool(-1)) 59 self.assertTrue(bool(a_negative_integer)) 60 # self.assertFalse(-1) 61 # self.assertTrue(-1) 62 self.assertTrue(a_negative_integer) 63 64 65# NOTESthe test is still green.
I remove the commented lines from test_is_an_integer_falsy_or_truthy
42 def test_is_an_integer_falsy_or_truthy(self): 43 a_negative_integer = -1 44 self.assertNotEqual(a_negative_integer, False) 45 self.assertIsNot(a_negative_integer, False) 46 self.assertNotEqual(a_negative_integer, True) 47 self.assertIsNot(a_negative_integer, True) 48 self.assertTrue(bool(a_negative_integer)) 49 self.assertTrue(a_negative_integer) 50 51 52# NOTESI add an assertion to test if
0is grouped as False or True49 self.assertTrue(a_negative_integer) 50 51 self.assertNotEqual(0, False) 52 53 54# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0 == Falsea reminder that False is an integer, the test also shows that the value of False is
0.I change assertNotEqual to assertEqual for
0, False49 self.assertTrue(a_negative_integer) 50 51 # self.assertNotEqual(0, False) 52 self.assertEqual(0, False) 53 54 55# NOTESthe test passes.
I add an assertion to test if
0is the same object as False51 # self.assertNotEqual(0, False) 52 self.assertEqual(0, False) 53 self.assertIs(0, False) 54 55 56# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0 is not FalseI change assertIs to assertIsNot for
0, False51 # self.assertNotEqual(0, False) 52 self.assertEqual(0, False) 53 # self.assertIs(0, False) 54 self.assertIsNot(0, False) 55 56 57# NOTESthe test passes because an integer is not the same object as False. This is another example of how is and equal are different
I add an assertion to see if
0is equal to True53 # self.assertIs(0, False) 54 self.assertIsNot(0, False) 55 self.assertEqual(0, True) 56 57 58# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0 != TrueI change assertEqual to assertNotEqual for
0, True53 # self.assertIs(0, False) 54 self.assertIsNot(0, False) 55 # self.assertEqual(0, True) 56 self.assertNotEqual(0, True) 57 58 59# NOTESthe test passes.
I add an assertion for if
0is the same object as True55 # self.assertEqual(0, True) 56 self.assertNotEqual(0, True) 57 self.assertIs(0, True) 58 59 60# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0 is not TrueI change assertIs to assertIsNot for
0, True55 # self.assertEqual(0, True) 56 self.assertNotEqual(0, True) 57 # self.assertIs(0, True) 58 self.assertIsNot(0, True) 59 60 61# NOTESthe test passes because an integer is not the same object as True.
-
57 # self.assertIs(0, True) 58 self.assertIsNot(0, True) 59 self.assertTrue(bool(0)) 60 61 62# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(0)is False. I change assertTrue to assertFalse for
bool(0)57 # self.assertIs(0, True) 58 self.assertIsNot(0, True) 59 # self.assertTrue(bool(0)) 60 self.assertFalse(bool(0)) 61 62 63# NOTESthe test passes.
I add a comment
63# NOTES 64# bool(-1) is True 65# True is True 66# True is an integer 67# True is a boolean 68# True is NOT False 69# bool(0) is False 70# bool(None) is False 71# False is False 72# False is an integer 73# False is a boolean 74# False is NOT TrueI add an assertion for
0without bool59 # self.assertTrue(bool(0)) 60 self.assertFalse(bool(0)) 61 self.assertTrue(0) 62 63 64# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0 is not truebecause the result of
bool(0)is False.I change assertTrue to assertFalse for
059 # self.assertTrue(bool(0)) 60 self.assertFalse(bool(0)) 61 # self.assertTrue(0) 62 self.assertFalse(0) 63 64 65# NOTESthe test passes because the result of
bool(0)is False.I remove the commented lines from test_is_an_integer_falsy_or_truthy
49 self.assertTrue(a_negative_integer) 50 51 self.assertEqual(0, False) 52 self.assertIsNot(0, False) 53 self.assertNotEqual(0, True) 54 self.assertIsNot(0, True) 55 self.assertFalse(bool(0)) 56 self.assertFalse(0) 57 58 59# NOTESI add an assertion to test if
1is grouped as False or True56 self.assertFalse(0) 57 58 self.assertEqual(1, False) 59 60 61# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 1 != FalseI change assertEqual to assertNotEqual for
1, False56 self.assertFalse(0) 57 58 # self.assertEqual(1, False) 59 self.assertNotEqual(1, False) 60 61 62# NOTESthe test passes.
I add an assertion to see if
1is the same object as False58 # self.assertEqual(1, False) 59 self.assertNotEqual(1, False) 60 self.assertIs(1, False) 61 62 63# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 1 is not FalseI change assertIs to assertIsNot for
1, False58 # self.assertEqual(1, False) 59 self.assertNotEqual(1, False) 60 # self.assertIs(1, False) 61 self.assertIsNot(1, False) 62 63 64# NOTESthe test passes.
I add an assertion to see if
1is equal to True60 # self.assertIs(1, False) 61 self.assertIsNot(1, False) 62 self.assertNotEqual(1, True) 63 64 65# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 1 == Truea reminder that True is an integer and its value is
1.I change assertNotEqual to assertEqual for
1, True60 # self.assertIs(1, False) 61 self.assertIsNot(1, False) 62 # self.assertNotEqual(1, True) 63 self.assertEqual(1, True) 64 65 66# NOTESthe test passes.
I add an assertion for if
1is the same object as True62 # self.assertNotEqual(1, True) 63 self.assertEqual(1, True) 64 self.assertIs(1, True) 65 66 67# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 1 is not TrueI change assertIs to assertIsNot for
1, True62 # self.assertNotEqual(1, True) 63 self.assertEqual(1, True) 64 # self.assertIs(1, True) 65 self.assertIsNot(1, True) 66 67 68# NOTES-
64 # self.assertIs(1, True) 65 self.assertIsNot(1, True) 66 self.assertFalse(bool(1)) 67 68 69# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not false I change assertFalse to assertTrue for
bool(1)64 # self.assertIs(1, True) 65 self.assertIsNot(1, True) 66 # self.assertFalse(bool(1)) 67 self.assertTrue(bool(1)) 68 69 70# NOTESthe test passes.
I add a comment
70# NOTES 71# bool(1) is True 72# bool(-1) is True 73# True is True 74# True is an integer 75# True is a boolean 76# True is NOT False 77# bool(0) is FalseI add an assertion for
1without bool66 # self.assertFalse(bool(1)) 67 self.assertTrue(bool(1)) 68 self.assertFalse(1) 69 70 71# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 1 is not falsebecause the result of
bool(1)is True.I change assertFalse to assertTrue for
166 # self.assertFalse(bool(1)) 67 self.assertTrue(bool(1)) 68 # self.assertFalse(1) 69 self.assertTrue(1) 70 71 72# NOTESI add a variable for
156 self.assertFalse(0) 57 58 a_positive_integer = 1 59 # self.assertEqual(1, False)I use the variable to remove repetition of
1for the other statements and keepself.assertEqual(1, True)since it shows the exact value of True58 a_positive_integer = 1 59 # self.assertEqual(1, False) 60 # self.assertNotEqual(1, False) 61 self.assertNotEqual(a_positive_integer, False) 62 # self.assertIs(1, False) 63 # self.assertIsNot(1, False) 64 self.assertIsNot(a_positive_integer, False)65 # self.assertNotEqual(1, True) 66 self.assertEqual(1, True) 67 # self.assertIs(1, True) 68 # self.assertIsNot(1, True) 69 self.assertIsNot(a_positive_integer, True)70 # self.assertFalse(bool(1)) 71 # self.assertTrue(bool(1)) 72 self.assertTrue(bool(a_positive_integer)) 73 # self.assertFalse(1) 74 # self.assertTrue(1) 75 self.assertTrue(a_positive_integer) 76 77 78# NOTESthe test is still green.
I remove the commented lines from test_is_an_integer_falsy_or_truthy
58 a_positive_integer = 1 59 self.assertNotEqual(a_positive_integer, False) 60 self.assertIsNot(a_positive_integer, False) 61 self.assertEqual(1, True) 62 self.assertIsNot(a_positive_integer, True) 63 self.assertTrue(bool(a_positive_integer)) 64 self.assertTrue(a_positive_integer) 65 66 67# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_an_integer_falsy_or_truthy'0 is grouped as False. Positive and Negative Integers are grouped as True.
test_is_a_float_falsy_or_truthy
Is a float grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if a float (a binary floating point decimal number) is grouped as False or True
64 self.assertTrue(a_positive_integer) 65 66 def test_is_a_float_falsy_or_truthy(self): 67 a_negative_float = -0.1 68 self.assertEqual(a_negative_float, False) 69 70 71# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -0.1 != False
GREEN: make it pass
I change assertEqual to assertNotEqual for a_negative_float, False
66 def test_is_a_float_falsy_or_truthy(self):
67 a_negative_float = -0.1
68 # self.assertEqual(a_negative_float, False)
69 self.assertNotEqual(a_negative_float, False)
70
71
72# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if a negative float is the same object as False
68 # self.assertEqual(a_negative_float, False) 69 self.assertNotEqual(a_negative_float, False) 70 self.assertIs(a_negative_float, False) 71 72 73# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -0.1 is not FalseI change assertIs to assertIsNot for
a_negative_float, False68 # self.assertEqual(a_negative_float, False) 69 self.assertNotEqual(a_negative_float, False) 70 # self.assertIs(a_negative_float, False) 71 self.assertIsNot(a_negative_float, False) 72 73 74# NOTESthe test passes because a float is not the same object as False.
I add an assertion for if a negative float is equal to True
70 # self.assertIs(a_negative_float, False) 71 self.assertIsNot(a_negative_float, False) 72 self.assertEqual(a_negative_float, True) 73 74 75# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -0.1 != TrueI change assertEqual to assertNotEqual for
a_negative_float, True70 # self.assertIs(a_negative_float, False) 71 self.assertIsNot(a_negative_float, False) 72 # self.assertEqual(a_negative_float, True) 73 self.assertNotEqual(a_negative_float, True) 74 75 76# NOTESthe test passes.
I add an assertion for if a negative float is the same object as True
72 # self.assertEqual(a_negative_float, True) 73 self.assertNotEqual(a_negative_float, True) 74 self.assertIs(a_negative_float, True) 75 76 77# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -0.1 is not TrueI change assertIs to assertIsNot for
a_negative_float, True72 # self.assertEqual(a_negative_float, True) 73 self.assertNotEqual(a_negative_float, True) 74 # self.assertIs(a_negative_float, True) 75 self.assertIsNot(a_negative_float, True) 76 77 78# NOTESthe test passes because a float is not the same object as True.
I add an assertion for
bool(a_negative_float)74 # self.assertIs(a_negative_float, True) 75 self.assertIsNot(a_negative_float, True) 76 self.assertFalse(bool(a_negative_float)) 77 78 79# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsethis means the result of
bool(-0.1)is True.I change assertFalse to assertTrue for
bool(a_negative_float)74 # self.assertIs(a_negative_float, True) 75 self.assertIsNot(a_negative_float, True) 76 # self.assertFalse(bool(a_negative_float)) 77 self.assertTrue(bool(a_negative_float)) 78 79 80# NOTESthe test passes.
I use
-0.1for all the floats (binary floating point decimal numbers) that are smaller than0.0.
I add a comment
80# NOTES 81# bool(-0.1) is True 82# bool(1) is True 83# bool(-1) is TrueI add an assertion for
a_negative_floatwithout bool76 # self.assertFalse(bool(a_negative_float)) 77 self.assertTrue(bool(a_negative_float)) 78 self.assertFalse(a_negative_float) 79 80 81# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: -0.1 is not falsebecause the result of
bool(-0.1)is True.I change assertFalse to assertTrue for
a_negative_float76 # self.assertFalse(bool(a_negative_float)) 77 self.assertTrue(bool(a_negative_float)) 78 # self.assertFalse(a_negative_float) 79 self.assertTrue(a_negative_float) 80 81 82# NOTESI remove the commented lines from test_is_a_float_falsy_or_truthy
66 def test_is_a_float_falsy_or_truthy(self): 67 a_negative_float = -0.1 68 self.assertNotEqual(a_negative_float, False) 69 self.assertIsNot(a_negative_float, False) 70 self.assertNotEqual(a_negative_float, True) 71 self.assertIsNot(a_negative_float, True) 72 self.assertTrue(bool(a_negative_float)) 73 self.assertTrue(a_negative_float) 74 75 76# NOTESI add an assertion to test if
0.0is grouped as False or True73 self.assertTrue(a_negative_float) 74 75 self.assertNotEqual(0.0, False) 76 77 78# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.0 == Falsethe test also shows that
0.0is equal to False, whose value is0.I change assertNotEqual to assertEqual for
0.0, False73 self.assertTrue(a_negative_float) 74 75 # self.assertNotEqual(0.0, False) 76 self.assertEqual(0.0, False) 77 78 79# NOTESthe test passes.
I add an assertion to test if
0.0is the same object as False75 # self.assertNotEqual(0.0, False) 76 self.assertEqual(0.0, False) 77 self.assertIs(0.0, False) 78 79 80# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.0 is not FalseI change assertIs to assertIsNot for
0.0, False75 # self.assertNotEqual(0.0, False) 76 self.assertEqual(0.0, False) 77 # self.assertIs(0.0, False) 78 self.assertIsNot(0.0, False) 79 80 81# NOTESthe test passes because a float is not the same object as False. This is another example of how is and equal are different
I add an assertion to see if
0.0is equal to True77 # self.assertIs(0.0, False) 78 self.assertIsNot(0.0, False) 79 self.assertEqual(0.0, True) 80 81 82# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.0 != TrueI change assertEqual to assertNotEqual for
0.0, True77 # self.assertIs(0.0, False) 78 self.assertIsNot(0.0, False) 79 # self.assertEqual(0.0, True) 80 self.assertNotEqual(0.0, True) 81 82 83# NOTESthe test passes.
I add an assertion for if
0.0is the same object as True79 # self.assertEqual(0.0, True) 80 self.assertNotEqual(0.0, True) 81 self.assertIs(0.0, True) 82 83 84# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.0 is not TrueI change assertIs to assertIsNot for
0.0, True79 # self.assertEqual(0.0, True) 80 self.assertNotEqual(0.0, True) 81 # self.assertIs(0.0, True) 82 self.assertIsNot(0.0, True) 83 84 85# NOTESthe test passes because a float is not the same object as True.
I add an assertion for
bool(0.0)81 # self.assertIs(0.0, True) 82 self.assertIsNot(0.0, True) 83 self.assertTrue(bool(0.0)) 84 85 86# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(0.0)is False.I change assertTrue to assertFalse for
bool(0.0)81 # self.assertIs(0.0, True) 82 self.assertIsNot(0.0, True) 83 # self.assertTrue(bool(0.0)) 84 self.assertFalse(bool(0.0)) 85 86 87# NOTESthe test passes.
I add a comment
94# True is NOT False 95# bool(0.0) is False 96# bool(0) is False 97# bool(None) is False 98# False is False 99# False is an integer 100# False is a boolean 101# False is NOT TrueI add an assertion for
0.0without bool83 # self.assertTrue(bool(0.0)) 84 self.assertFalse(bool(0.0)) 85 self.assertTrue(0.0) 86 87 88# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.0 is not truebecause the result of
bool(0.0)is False.I change assertTrue to assertFalse for
0.083 # self.assertTrue(bool(0.0)) 84 self.assertFalse(bool(0.0)) 85 # self.assertTrue(0.0) 86 self.assertFalse(0.0) 87 88 89# NOTESthe test passes because the result of
bool(0.0)is False.I remove the commented lines from test_is_a_float_falsy_or_truthy
73 self.assertTrue(a_negative_float) 74 75 self.assertEqual(0.0, False) 76 self.assertIsNot(0.0, False) 77 self.assertNotEqual(0.0, True) 78 self.assertIsNot(0.0, True) 79 self.assertFalse(bool(0.0)) 80 self.assertFalse(0.0) 81 82 83# NOTESI add an assertion to test if a float bigger than
0.0is grouped as False or True80 self.assertFalse(0.0) 81 82 a_positive_float = 0.1 83 self.assertEqual(a_positive_float, False) 84 85 86# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.1 != FalseI change assertEqual to assertNotEqual for
a_positive_float, False80 self.assertFalse(0.0) 81 82 a_positive_float = 0.1 83 # self.assertEqual(a_positive_float, False) 84 self.assertNotEqual(a_positive_float, False) 85 86 87# NOTESthe test passes.
I add an assertion to see if
a_positive_floatis the same object as False82 a_positive_float = 0.1 83 # self.assertEqual(a_positive_float, False) 84 self.assertNotEqual(a_positive_float, False) 85 self.assertIs(a_positive_float, False) 86 87 88# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.1 is not FalseI change assertIs to assertIsNot for
a_positive_float, False82 a_positive_float = 0.1 83 # self.assertEqual(a_positive_float, False) 84 self.assertNotEqual(a_positive_float, False) 85 # self.assertIs(a_positive_float, False) 86 self.assertIsNot(a_positive_float, False) 87 88 89# NOTESthe test passes.
I add an assertion to see if
0.1is equal to True85 # self.assertIs(a_positive_float, False) 86 self.assertIsNot(a_positive_float, False) 87 self.assertEqual(a_positive_float, True) 88 89 90# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.1 != TrueI change assertEqual to assertNotEqual for
a_positive_float, True85 # self.assertIs(a_positive_float, False) 86 self.assertIsNot(a_positive_float, False) 87 # self.assertEqual(a_positive_float, True) 88 self.assertNotEqual(a_positive_float, True) 89 90 91# NOTESthe test passes.
I add an assertion for if
a_positive_floatis the same object as True87 # self.assertEqual(a_positive_float, True) 88 self.assertNotEqual(a_positive_float, True) 89 self.assertIs(a_positive_float, True) 90 91 92# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.1 is not TrueI change assertIs to assertIsNot for
a_positive_float, True87 # self.assertEqual(a_positive_float, True) 88 self.assertNotEqual(a_positive_float, True) 89 # self.assertIs(a_positive_float, True) 90 self.assertIsNot(a_positive_float, True) 91 92 93# NOTESI add an assertion for
bool(a_positive_float)89 # self.assertIs(a_positive_float, True) 90 self.assertIsNot(a_positive_float, True) 91 self.assertFalse(bool(a_positive_float)) 92 93 94# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falseI change assertFalse to assertTrue for
bool(a_positive_float)89 # self.assertIs(a_positive_float, True) 90 self.assertIsNot(a_positive_float, True) 91 # self.assertFalse(bool(a_positive_float)) 92 self.assertTrue(bool(a_positive_float)) 93 94 95# NOTESthe test passes.
I add a comment
95# NOTES 96# bool(0.1) is True 97# bool(-0.1) is True 98# bool(1) is TrueI add an assertion for
a_positive_floatwithout bool91 # self.assertFalse(bool(a_positive_float)) 92 self.assertTrue(bool(a_positive_float)) 93 self.assertFalse(a_positive_float) 94 95 96# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 0.1 is not falsebecause the result of
bool(0.1)is True.I change assertFalse to assertTrue for
0.191 # self.assertFalse(bool(a_positive_float)) 92 self.assertTrue(bool(a_positive_float)) 93 # self.assertFalse(a_positive_float) 94 self.assertTrue(a_positive_float) 95 96 97# NOTESI remove the commented lines from test_is_a_float_falsy_or_truthy
82 a_positive_float = 0.1 83 self.assertNotEqual(a_positive_float, False) 84 self.assertIsNot(a_positive_float, False) 85 self.assertNotEqual(a_positive_float, True) 86 self.assertIsNot(a_positive_float, True) 87 self.assertTrue(bool(a_positive_float)) 88 self.assertTrue(a_positive_float) 89 90 91# NOTESI make the comments for
# bool(0.1) is True,# bool(-0.1) is True,# bool(1) is True,# bool(-1) is True,# bool(0.0) is Falseand# bool(0) is Falsesimpler because floats and integers are numbers and 0.0 is equal to 091# NOTES 92# bool(a positive number) is True 93# bool(a negative number) is True 94# True is True 95# True is an integer 96# True is a boolean97# True is NOT False 98# bool(zero) is False 99# bool(None) is False 100# False is False 101# False is an integer 102# False is a boolean 103# False is NOT TrueI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_float_falsy_or_truthy'0.0 is grouped as False. Positive and Negative floats are grouped as True.
I add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_float_falsy_or_truthy'
‘0.0’ is grouped as False. Positive and Negative floats are grouped as True.
test_is_a_string_falsy_or_truthy
Is a string grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if a string (anything in quotes) is grouped as False or True
88 self.assertTrue(a_positive_float) 89 90 def test_is_a_string_falsy_or_truthy(self): 91 self.assertEqual(str(), False) 92 93 94# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: '' != False
GREEN: make it pass
I change assertEqual to assertNotEqual for str(), False
88 self.assertTrue(a_positive_float)
89
90 def test_is_a_string_falsy_or_truthy(self):
91 # self.assertEqual(str(), False)
92 self.assertNotEqual(str(), False)
93
94
95# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if
str()is the same object as False90 def test_is_a_string_falsy_or_truthy(self): 91 # self.assertEqual(str(), False) 92 self.assertNotEqual(str(), False) 93 self.assertIs(str(), False) 94 95 96# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: '' is not FalseI change assertIs to assertIsNot for
str(), False90 def test_is_a_string_falsy_or_truthy(self): 91 # self.assertEqual(str(), False) 92 self.assertNotEqual(str(), False) 93 # self.assertIs(str(), False) 94 self.assertIsNot(str(), False) 95 96 97# NOTESthe test passes.
I add an assertion for if the empty string is equal to True
93 # self.assertIs(str(), False) 94 self.assertIsNot(str(), False) 95 self.assertEqual(str(), True) 96 97 98# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: '' != TrueI change assertEqual to assertNotEqual for
str(), True93 # self.assertIs(str(), False) 94 self.assertIsNot(str(), False) 95 # self.assertEqual(str(), True) 96 self.assertNotEqual(str(), True) 97 98 99# NOTESthe test passes.
I add an assertion for if the empty string is the same object as True
95 # self.assertEqual(str(), True) 96 self.assertNotEqual(str(), True) 97 self.assertIs(str(), True) 98 99 100# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: '' is not TrueI change assertIs to assertIsNot for
str(), True95 # self.assertEqual(str(), True) 96 self.assertNotEqual(str(), True) 97 # self.assertIs(str(), True) 98 self.assertIsNot(str(), True) 99 100 101# NOTESI add an assertion for
bool(str())97 # self.assertIs(str(), True) 98 self.assertIsNot(str(), True) 99 self.assertTrue(bool(str())) 100 101 102# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(str())is False.I change assertTrue to assertFalse for
bool(str())97 # self.assertIs(str(), True) 98 self.assertIsNot(str(), True) 99 # self.assertTrue(bool(str())) 100 self.assertFalse(bool(str())) 101 102 103# NOTESthe test passes.
I add a comment
109# True is NOT False 110# bool(str()) is False 111# bool(zero) is False 112# bool(None) is False 113# False is FalseI add an assertion for
str()without bool99 # self.assertTrue(bool(str())) 100 self.assertFalse(bool(str())) 101 self.assertTrue(str()) 102 103 104# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: '' is not trueI change assertTrue to assertFalse for
str()99 # self.assertTrue(bool(str())) 100 self.assertFalse(bool(str())) 101 # self.assertTrue(str()) 102 self.assertFalse(str()) 103 104 105# NOTESI remove the commented lines from test_is_a_string_falsy_or_truthy
90 def test_is_a_string_falsy_or_truthy(self): 91 self.assertNotEqual(str(), False) 92 self.assertIsNot(str(), False) 93 self.assertNotEqual(str(), True) 94 self.assertIsNot(str(), True) 95 self.assertFalse(bool(str())) 96 self.assertFalse(str()) 97 98 99# NOTESI add an assertion to test if a string with things is grouped as False or True
96 self.assertFalse(str()) 97 98 a_string = "string with things" 99 self.assertEqual(a_string, False) 100 101 102# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 'string with things' != FalseI change assertEqual to assertNotEqual for
a_string, False96 self.assertFalse(str()) 97 98 a_string = "string with things" 99 # self.assertEqual(a_string, False) 100 self.assertNotEqual(a_string, False) 101 102 103# NOTESthe test passes.
add an assertion for if
a_stringis the same object as False98 a_string = "string with things" 99 # self.assertEqual(a_string, False) 100 self.assertNotEqual(a_string, False) 101 self.assertIs(a_string, False) 102 103 104# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 'string with things' is not FalseI change assertIs to assertIsNot for
a_string, False98 a_string = "string with things" 99 # self.assertEqual(a_string, False) 100 self.assertNotEqual(a_string, False) 101 # self.assertIs(a_string, False) 102 self.assertIsNot(a_string, False) 103 104 105# NOTESthe test passes.
I add an assertion for if
a_stringis equal to True101 # self.assertIs(a_string, False) 102 self.assertIsNot(a_string, False) 103 self.assertEqual(a_string, True) 104 105 106# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 'string with things' != TrueI change assertEqual to assertNotEqual for
a_string, True101 # self.assertIs(a_string, False) 102 self.assertIsNot(a_string, False) 103 # self.assertEqual(a_string, True) 104 self.assertNotEqual(a_string, True) 105 106 107# NOTESthe test passes.
I add an assertion to see if
a_stringis the same object as True103 # self.assertEqual(a_string, True) 104 self.assertNotEqual(a_string, True) 105 self.assertIs(a_string, True) 106 107 108# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 'string with things' is not TrueI change assertIs to assertIsNot for
a_string, True103 # self.assertEqual(a_string, True) 104 self.assertNotEqual(a_string, True) 105 # self.assertIs(a_string, True) 106 self.assertIsNot(a_string, True) 107 108 109# NOTESthe test passes.
I add an assertion for
bool(a_string)105 # self.assertIs(a_string, True) 106 self.assertIsNot(a_string, True) 107 self.assertFalse(bool(a_string)) 108 109 110# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the result of
bool("string with things")is True.I change assertFalse to assertTrue for
bool(a_string)77 # self.assertIs(a_string, True) 78 self.assertIsNot(a_string, True) 79 # self.assertFalse(bool(a_string)) 80 self.assertTrue(bool(a_string)) 81 82 83# NOTESthe test passes.
I add a comment
111# NOTES 112# bool("string with things") is True 113# bool(a positive number) is True 114# bool(a negative number) is True 115# True is TrueI add an assertion for
a_stringwithout bool107 # self.assertFalse(bool(a_string)) 108 self.assertTrue(bool(a_string)) 109 self.assertFalse(a_string) 110 111 112# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: 'string with things' is not falsebecause the result of
bool("string with things")is True.I change assertFalse to assertTrue
107 # self.assertFalse(bool(a_string)) 108 self.assertTrue(bool(a_string)) 109 # self.assertFalse(a_string) 110 self.assertTrue(a_string) 111 112 113# NOTESI remove the commented lines from test_is_a_string_falsy_or_truthy
98 a_string = "string with things" 99 self.assertNotEqual(a_string, False) 100 self.assertIsNot(a_string, False) 101 self.assertNotEqual(a_string, True) 102 self.assertIsNot(a_string, True) 103 self.assertTrue(bool(a_string)) 104 self.assertTrue(a_string) 105 106 107# NOTESI change the new comments to make them clearer
107# NOTES 108# bool(a string with things) is True 109# bool(a positive number) is True 110# bool(a negative number) is True 111# True is True 112# True is an integer 113# True is a boolean114# True is NOT False 115# bool(the empty string) is False 116# bool(zero) is False 117# bool(None) is False 118# False is False 119# False is an integer 120# False is a boolean 121# False is NOT TrueI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_string_falsy_or_truthy'
The empty string is grouped as False. A string with things is grouped as True.
test_is_a_tuple_falsy_or_truthy
Is a tuple grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if a tuple (anything in parentheses
( )separated by a comma) is grouped as False or True104 self.assertTrue(a_string) 105 106 def test_is_a_tuple_falsy_or_truthy(self): 107 self.assertEqual(tuple(), False) 108 109 110# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: () != False
GREEN: make it pass
I change assertEqual to assertNotEqual for tuple(), False
104 self.assertTrue(a_string)
105
106 def test_is_a_tuple_falsy_or_truthy(self):
107 # self.assertEqual(tuple(), False)
108 self.assertNotEqual(tuple(), False)
109
110
111# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if the empty tuple is the same object as False
106 def test_is_a_tuple_falsy_or_truthy(self): 107 # self.assertEqual(tuple(), False) 108 self.assertNotEqual(tuple(), False) 109 self.assertIs(tuple(), False) 110 111 112# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: () is not FalseI change assertIs to assertIsNot for
tuple(), False106 def test_is_a_tuple_falsy_or_truthy(self): 107 # self.assertEqual(tuple(), False) 108 self.assertNotEqual(tuple(), False) 109 # self.assertIs(tuple(), False) 110 self.assertIsNot(tuple(), False) 111 112 113# NOTESthe test passes.
I add an assertion for if the empty tuple is equal to True
109 # self.assertIs(tuple(), False) 110 self.assertIsNot(tuple(), False) 111 self.assertEqual(tuple(), True) 112 113 114# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: () != TrueI change assertEqual to assertNotEqual for
tuple(), True109 # self.assertIs(tuple(), False) 110 self.assertIsNot(tuple(), False) 111 # self.assertEqual(tuple(), True) 112 self.assertNotEqual(tuple(), True) 113 114 115# NOTESthe test passes.
I add an assertion for if the empty tuple is the same object as True
111 # self.assertEqual(tuple(), True) 112 self.assertNotEqual(tuple(), True) 113 self.assertIs(tuple(), True) 114 115 116# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: () is not TrueI change assertIs to assertIsNot for
tuple(), True111 # self.assertEqual(tuple(), True) 112 self.assertNotEqual(tuple(), True) 113 # self.assertIs(tuple(), True) 114 self.assertIsNot(tuple(), True) 115 116 117# NOTESthe test passes.
I add an assertion for
bool(tuple())113 # self.assertIs(tuple(), True) 114 self.assertIsNot(tuple(), True) 115 self.assertTrue(bool(tuple())) 116 117 118# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(tuple())is False.I change assertTrue to assertFalse for
bool(tuple())113 # self.assertIs(tuple(), True) 114 self.assertIsNot(tuple(), True) 115 # self.assertTrue(bool(tuple())) 116 self.assertFalse(bool(tuple())) 117 118 119# NOTESthe test passes.
I add a comment
126# True is NOT False 127# bool(the empty tuple) is False 128# bool(the empty string) is False 129# bool(zero) is FalseI add an assertion for
tuple()without bool115 # self.assertTrue(bool(tuple())) 116 self.assertFalse(bool(tuple())) 117 self.assertTrue(tuple()) 118 119 120# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: () is not trueI change assertTrue to assertFalse
115 # self.assertTrue(bool(tuple())) 116 self.assertFalse(bool(tuple())) 117 # self.assertTrue(tuple()) 118 self.assertFalse(tuple()) 119 120 121# NOTESI remove the commented lines from test_is_a_tuple_falsy_or_truthy
106 def test_is_a_tuple_falsy_or_truthy(self): 107 self.assertNotEqual(tuple(), False) 108 self.assertIsNot(tuple(), False) 109 self.assertNotEqual(tuple(), True) 110 self.assertIsNot(tuple(), True) 111 self.assertFalse(bool(tuple())) 112 self.assertFalse(tuple()) 113 114 115# NOTESI add an assertion to test if a tuple with things is grouped as False or True
112 self.assertFalse(tuple()) 113 114 a_tuple = (0, 1, 2, 'n') 115 self.assertEqual(a_tuple, False) 116 117 118# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: (0, 1, 2, 'n') != FalseI change assertEqual to assertNotEqual for
a_tuple, False112 self.assertFalse(tuple()) 113 114 a_tuple = (0, 1, 2, 'n') 115 # self.assertEqual(a_tuple, False) 116 self.assertNotEqual(a_tuple, False) 117 118 119# NOTESthe test passes.
I add an assertion to test if a tuple with things is the same object as False
114 a_tuple = (0, 1, 2, 'n') 115 # self.assertEqual(a_tuple, False) 116 self.assertNotEqual(a_tuple, False) 117 self.assertIs(a_tuple, False) 118 119 120# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: (0, 1, 2, 'n') is not FalseI change assertIs to assertIsNot for
a_tuple, False114 a_tuple = (0, 1, 2, 'n') 115 # self.assertEqual(a_tuple, False) 116 self.assertNotEqual(a_tuple, False) 117 # self.assertIs(a_tuple, False) 118 self.assertIsNot(a_tuple, False) 119 120 121# NOTESthe test passes.
I add an assertion for if a tuple with things is equal to True
117 # self.assertIs(a_tuple, False) 118 self.assertIsNot(a_tuple, False) 119 self.assertEqual(a_tuple, True) 120 121 122# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: (0, 1, 2, 'n') != TrueI change assertEqual to assertNotEqual for
a_tuple, True117 # self.assertIs(a_tuple, False) 118 self.assertIsNot(a_tuple, False) 119 # self.assertEqual(a_tuple, True) 120 self.assertNotEqual(a_tuple, True) 121 122 123# NOTESthe test passes.
I add an assertion to test if a tuple with things is the same object as True
119 # self.assertEqual(a_tuple, True) 120 self.assertNotEqual(a_tuple, True) 121 self.assertIs(a_tuple, True) 122 123 124# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: (0, 1, 2, 'n') is not TrueI change assertIs to assertIsNot for
a_tuple, True119 # self.assertEqual(a_tuple, True) 120 self.assertNotEqual(a_tuple, True) 121 # self.assertIs(a_tuple, True) 122 self.assertIsNot(a_tuple, True) 123 124 125# NOTESthe test passes.
I add an assertion for
bool(a_tuple)121 # self.assertIs(a_tuple, True) 122 self.assertIsNot(a_tuple, True) 123 self.assertFalse(bool(a_tuple)) 124 125 126# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the result of
bool((0, 1, 2, 'n'))is True.I change assertFalse to assertTrue for
bool(a_tuple)121 # self.assertIs(a_tuple, True) 122 self.assertIsNot(a_tuple, True) 123 # self.assertFalse(bool(a_tuple)) 124 self.assertTrue(bool(a_tuple)) 125 126 127# NOTESthe test passes.
I add a comment
127# NOTES 128# bool(a tuple with things) is True 129# bool(a string with things) is True 130# bool(a positive number) is TrueI add an assertion for a tuple with things without bool
123 # self.assertFalse(bool(a_tuple)) 124 self.assertTrue(bool(a_tuple)) 125 self.assertFalse(a_tuple) 126 127 128# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: (0, 1, 2, 'n') is not falsebecause the result of
bool((0, 1, 2, 'n'))is True.I change assertFalse to assertTrue for
a_tuple123 # self.assertFalse(bool(a_tuple)) 124 self.assertTrue(bool(a_tuple)) 125 # self.assertFalse(a_tuple) 126 self.assertTrue(a_tuple) 127 128 129# NOTESI remove the commented lines from test_is_a_tuple_falsy_or_truthy
114 a_tuple = (0, 1, 2, 'n') 115 self.assertNotEqual(a_tuple, False) 116 self.assertIsNot(a_tuple, False) 117 self.assertNotEqual(a_tuple, True) 118 self.assertIsNot(a_tuple, True) 119 self.assertTrue(bool(a_tuple)) 120 self.assertTrue(a_tuple) 121 122 123# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_tuple_falsy_or_truthy'
The empty tuple is grouped as False. A tuple with things is grouped as True.
test_is_a_list_falsy_or_truthy
Is a list grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if a list (anything in square brackets
[ ]) is grouped as False or True120 self.assertTrue(a_tuple) 121 122 def test_is_a_list_falsy_or_truthy(self): 123 self.assertEqual(list(), False) 124 125 126# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [] != False
GREEN: make it pass
I change assertEqual to assertNotEqual for list(), False
120 self.assertTrue(a_tuple)
121
122 def test_is_a_list_falsy_or_truthy(self):
123 # self.assertEqual(list(), False)
124 self.assertNotEqual(list(), False)
125
126
127# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if the empty list is the same object as False
122 def test_is_a_list_falsy_or_truthy(self): 123 # self.assertEqual(list(), False) 124 self.assertNotEqual(list(), False) 125 self.assertIs(list(), False) 126 127 128# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [] is not FalseI change assertIs to assertIsNot for
list(), False122 def test_is_a_list_falsy_or_truthy(self): 123 # self.assertEqual(list(), False) 124 self.assertNotEqual(list(), False) 125 # self.assertIs(list(), False) 126 self.assertIsNot(list(), False) 127 128 129# NOTESthe test passes because a list is not the same object as False.
I add an assertion for if the empty list is equal to True
125 # self.assertIs(list(), False) 126 self.assertIsNot(list(), False) 127 self.assertEqual(list(), True) 128 129 130# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [] != TrueI change assertEqual to assertNotEqual for
list(), True125 # self.assertIs(list(), False) 126 self.assertIsNot(list(), False) 127 # self.assertEqual(list(), True) 128 self.assertNotEqual(list(), True) 129 130 131# NOTESthe test passes.
I add an assertion for if the empty list is the same object as True
127 # self.assertEqual(list(), True) 128 self.assertNotEqual(list(), True) 129 self.assertIs(list(), True) 130 131 132# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [] is not TrueI change assertIs to assertIsNot for
list(), True127 # self.assertEqual(list(), True) 128 self.assertNotEqual(list(), True) 129 # self.assertIs(list(), True) 130 self.assertIsNot(list(), True) 131 132 133# NOTESthe test passes because a list is not the same object as True.
I add an assertion for
bool(list())129 # self.assertIs(list(), True) 130 self.assertIsNot(list(), True) 131 self.assertTrue(bool(list())) 132 133 134# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(list())is False.I change assertTrue to assertFalse for
bool(list())129 # self.assertIs(list(), True) 130 self.assertIsNot(list(), True) 131 # self.assertTrue(bool(list())) 132 self.assertFalse(bool(list())) 133 134 135# NOTESthe test passes.
I add a comment
143# True is NOT False 144# bool(the empty list) is False 145# bool(the empty tuple) is False 146# bool(the empty string) is FalseI add an assertion for
list()without bool131 # self.assertTrue(bool(list())) 132 self.assertFalse(bool(list())) 133 self.assertTrue(list()) 134 135 136# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [] is not trueI change assertTrue to assertFalse for
list()131 # self.assertTrue(bool(list())) 132 self.assertFalse(bool(list())) 133 # self.assertTrue(list()) 134 self.assertFalse(list()) 135 136 137# NOTESI remove the commented lines from test_is_a_list_falsy_or_truthy
122 def test_is_a_list_falsy_or_truthy(self): 123 self.assertNotEqual(list(), False) 124 self.assertIsNot(list(), False) 125 self.assertNotEqual(list(), True) 126 self.assertIsNot(list(), True) 127 self.assertFalse(bool(list())) 128 self.assertFalse(list()) 129 130 131# NOTESI add an assertion to test if a list with things is grouped as False or True
128 self.assertFalse(list()) 129 130 a_list = [0, 1, 2, 'n'] 131 self.assertEqual(a_list, False) 132 133 134# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [0, 1, 2, 'n'] != FalseI change assertEqual to assertNotEqual for
a_list, False128 self.assertFalse(list()) 129 130 a_list = [0, 1, 2, 'n'] 131 # self.assertEqual(a_list, False) 132 self.assertNotEqual(a_list, False) 133 134 135# NOTESthe test passes.
I add an assertion for if a list with things is the same object as False
130 a_list = [0, 1, 2, 'n'] 131 # self.assertEqual(a_list, False) 132 self.assertNotEqual(a_list, False) 133 self.assertIs(a_list, False) 134 135 136# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [0, 1, 2, 'n'] is not FalseI change assertIs to assertIsNot for
a_list, False130 a_list = [0, 1, 2, 'n'] 131 # self.assertEqual(a_list, False) 132 self.assertNotEqual(a_list, False) 133 # self.assertIs(a_list, False) 134 self.assertIsNot(a_list, False) 135 136 137# NOTESthe test passes because a list is not the same object as False.
I add an assertion to test if a list with things is equal to True
133 # self.assertIs(a_list, False) 134 self.assertIsNot(a_list, False) 135 self.assertEqual(a_list, True) 136 137 138# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [0, 1, 2, 'n'] != TrueI change assertEqual to assertNotEqual for
a_list, True133 # self.assertIs(a_list, False) 134 self.assertIsNot(a_list, False) 135 # self.assertEqual(a_list, True) 136 self.assertNotEqual(a_list, True) 137 138 139# NOTESthe test passes.
I add an assertion for if a list with things is the same object as True
135 # self.assertEqual(a_list, True) 136 self.assertNotEqual(a_list, True) 137 self.assertIs(a_list, True) 138 139 140# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [0, 1, 2, 'n'] is not TrueI change assertIs to assertIsNot for
a_list, True135 # self.assertEqual(a_list, True) 136 self.assertNotEqual(a_list, True) 137 # self.assertIs(a_list, True) 138 self.assertIsNot(a_list, True) 139 140 141# NOTESthe test passes because a list is not the same object as True.
I add an assertion for
bool(a_list)137 # self.assertIs(a_list, True) 138 self.assertIsNot(a_list, True) 139 self.assertFalse(bool(a_list)) 140 141 142# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the result of
bool([0, 1, 2, 'n'])is True.I change assertFalse to assertTrue for
(bool(a_list))137 # self.assertIs(a_list, True) 138 self.assertIsNot(a_list, True) 139 # self.assertFalse(bool(a_list)) 140 self.assertTrue(bool(a_list)) 141 142 143# NOTESthe test passes.
I add a comment
143# NOTES 144# bool(a list with things) is True 145# bool(a tuple with things) is True 146# bool(a string with things) is TrueI add an assertion for
a_listwithout bool139 # self.assertFalse(bool(a_list)) 140 self.assertTrue(bool(a_list)) 141 self.assertFalse(a_list) 142 143 144# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: [0, 1, 2, 'n'] is not falsebecause the result of
bool([0, 1, 2, 'n'])is True.I change assertFalse to assertTrue for
a_list139 # self.assertFalse(bool(a_list)) 140 self.assertTrue(bool(a_list)) 141 # self.assertFalse(a_list) 142 self.assertTrue(a_list) 143 144 145# NOTESI remove the commented lines from test_is_a_list_falsy_or_truthy
130 a_list = [0, 1, 2, 'n'] 131 self.assertNotEqual(a_list, False) 132 self.assertIsNot(a_list, False) 133 self.assertNotEqual(a_list, True) 134 self.assertIsNot(a_list, True) 135 self.assertTrue(bool(a_list)) 136 self.assertTrue(a_list) 137 138 139# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_list_falsy_or_truthy'
The empty list is grouped as False. A list with things is grouped as True.
test_is_a_set_falsy_or_truthy
Is a set grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if a set (anything in curly braces that is not key-value pairs
{ }) is grouped as False or True136 self.assertTrue(a_list) 137 138 def test_is_a_set_falsy_or_truthy(self): 139 self.assertEqual(set(), False) 140 141 142# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: set() != False
GREEN: make it pass
I change assertEqual to assertNotEqual for set(), False
136 self.assertTrue(a_list)
137
138 def test_is_a_set_falsy_or_truthy(self):
139 # self.assertEqual(set(), False)
140 self.assertNotEqual(set(), False)
141
142
143# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if the empty set is the same object as False
138 def test_is_a_set_falsy_or_truthy(self): 139 # self.assertEqual(set(), False) 140 self.assertNotEqual(set(), False) 141 self.assertIs(set(), False) 142 143 144# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: set() is not FalseI change assertIs to assertIsNot for
set(), False138 def test_is_a_set_falsy_or_truthy(self): 139 # self.assertEqual(set(), False) 140 self.assertNotEqual(set(), False) 141 # self.assertIs(set(), False) 142 self.assertIsNot(set(), False) 143 144 145# NOTESthe test passes because a set is not the same object as False.
I add an assertion for if the empty set is equal to True
141 # self.assertIs(set(), False) 142 self.assertIsNot(set(), False) 143 self.assertEqual(set(), True) 144 145 146# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: set() != TrueI change assertEqual to assertNotEqual for
set(), True141 # self.assertIs(set(), False) 142 self.assertIsNot(set(), False) 143 # self.assertEqual(set(), True) 144 self.assertNotEqual(set(), True) 145 146 147# NOTESthe test passes.
I add an assertion for if the empty set is the same object as True
143 # self.assertEqual(set(), True) 144 self.assertNotEqual(set(), True) 145 self.assertIs(set(), True) 146 147 148# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: set() is not TrueI change assertIs to assertIsNot for
set(), True143 # self.assertEqual(set(), True) 144 self.assertNotEqual(set(), True) 145 # self.assertIs(set(), True) 146 self.assertIsNot(set(), True) 147 148 149# NOTESthe test passes because a set is not the same object as True.
I add an assertion for
bool(set())145 # self.assertIs(set(), True) 146 self.assertIsNot(set(), True) 147 self.assertTrue(bool(set())) 148 149 150# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(set())is False.I change assertTrue to assertFalse for
bool(set())145 # self.assertIs(set(), True) 146 self.assertIsNot(set(), True) 147 # self.assertTrue(bool(set())) 148 self.assertFalse(bool(set())) 149 150 151# NOTESthe test passes.
I add a comment
160# True is NOT False 161# bool(the empty set) is False 162# bool(the empty list) is False 163# bool(the empty tuple) is FalseI add an assertion for
set()without bool147 # self.assertTrue(bool(set())) 148 self.assertFalse(bool(set())) 149 self.assertTrue(set()) 150 151 152# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: set() is not truebecause the result of
bool(set())is False.I change assertTrue to assertFalse for
set()147 # self.assertTrue(bool(set())) 148 self.assertFalse(bool(set())) 149 # self.assertTrue(set()) 150 self.assertFalse(set()) 151 152 153# NOTESI remove the commented lines from test_is_a_set_falsy_or_truthy
138 def test_is_a_set_falsy_or_truthy(self): 139 self.assertNotEqual(set(), False) 140 self.assertIsNot(set(), False) 141 self.assertNotEqual(set(), True) 142 self.assertIsNot(set(), True) 143 self.assertFalse(bool(set())) 144 self.assertFalse(set()) 145 146 147# NOTESI add an assertion to test if a set with things is grouped as False or True
144 self.assertFalse(set()) 145 146 a_set = {0, 1, 2, 'n'} 147 self.assertEqual(a_set, False) 148 149 150# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {0, 1, 2, 'n'} != FalseI change assertEqual to assertNotEqual for
a_set, False144 self.assertFalse(set()) 145 146 a_set = {0, 1, 2, 'n'} 147 # self.assertEqual(a_set, False) 148 self.assertNotEqual(a_set, False) 149 150 151# NOTESthe test passes.
I add an assertion for if a set with things is the same object as False
146 a_set = {0, 1, 2, 'n'} 147 # self.assertEqual(a_set, False) 148 self.assertNotEqual(a_set, False) 149 self.assertIs(a_set, False) 150 151 152# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {0, 1, 2, 'n'} is not FalseI change assertIs to assertIsNot for
a_set, False146 a_set = {0, 1, 2, 'n'} 147 # self.assertEqual(a_set, False) 148 self.assertNotEqual(a_set, False) 149 # self.assertIs(a_set, False) 150 self.assertIsNot(a_set, False) 151 152 153# NOTESthe test passes because a set is not the same object as False.
I add an assertion to test if a set with things is equal to True
149 # self.assertIs(a_set, False) 150 self.assertIsNot(a_set, False) 151 self.assertEqual(a_set, True) 152 153 154# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {0, 1, 2, 'n'} != TrueI change assertEqual to assertNotEqual for
a_set, True149 # self.assertIs(a_set, False) 150 self.assertIsNot(a_set, False) 151 # self.assertEqual(a_set, True) 152 self.assertNotEqual(a_set, True) 153 154 155# NOTESthe test passes.
I add an assertion for if a set with things is the same object as True
151 # self.assertEqual(a_set, True) 152 self.assertNotEqual(a_set, True) 153 self.assertIs(a_set, True) 154 155 156# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {0, 1, 2, 'n'} is not TrueI change assertIs to assertIsNot for
a_set, True151 # self.assertEqual(a_set, True) 152 self.assertNotEqual(a_set, True) 153 # self.assertIs(a_set, True) 154 self.assertIsNot(a_set, True) 155 156 157# NOTESthe test passes because a set is not the same object as True.
I add an assertion for
bool(a_set)153 # self.assertIs(a_set, True) 154 self.assertIsNot(a_set, True) 155 self.assertFalse(bool(a_set)) 156 157 158# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the result of
bool({0, 1, 2, 'n'})is True.I change assertFalse to assertTrue for
(bool(a_set))153 # self.assertIs(a_set, True) 154 self.assertIsNot(a_set, True) 155 # self.assertFalse(bool(a_set)) 156 self.assertTrue(bool(a_set)) 157 158 159# NOTESthe test passes.
I add a comment
159# NOTES 160# bool(a set with things) is True 161# bool(a list with things) is True 162# bool(a tuple with things) is TrueI add an assertion for
a_setwithout bool155 # self.assertFalse(bool(a_set)) 156 self.assertTrue(bool(a_set)) 157 self.assertFalse(a_set) 158 159 160# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {0, 1, 2, 'n'} is not falsebecause the result of
bool({0, 1, 2, 'n'})is True.I change assertFalse to assertTrue for
a_set155 # self.assertFalse(bool(a_set)) 156 self.assertTrue(bool(a_set)) 157 # self.assertFalse(a_set) 158 self.assertTrue(a_set) 159 160 161# NOTESI remove the commented lines from test_is_a_set_falsy_or_truthy
146 a_set = {0, 1, 2, 'n'} 147 self.assertNotEqual(a_set, False) 148 self.assertIsNot(a_set, False) 149 self.assertNotEqual(a_set, True) 150 self.assertIsNot(a_set, True) 151 self.assertTrue(bool(a_set)) 152 self.assertTrue(a_set) 153 154 155# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_set_falsy_or_truthy'
The empty set is grouped as False. A set with things is grouped as True.
test_is_a_dictionary_falsy_or_truthy
Is a dictionary grouped as False or True?
RED: make it fail
I go back to the terminal where the tests are running
I add a test for if a dictionary (key-value pairs separated by commas in curly braces
{ }) is grouped as False or True152 self.assertTrue(a_set) 153 154 def test_is_a_dictionary_falsy_or_truthy(self): 155 self.assertEqual(dict(), False) 156 157 158# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {} != Falsethe empty dictionary is not equal to False
GREEN: make it pass
I change assertEqual to assertNotEqual for dict(), False
152 self.assertTrue(a_set)
153
154 def test_is_a_dictionary_falsy_or_truthy(self):
155 # self.assertEqual(dict(), False)
156 self.assertNotEqual(dict(), False)
157
158
159# NOTES
the test passes.
REFACTOR: make it better
I add an assertion for if the empty dictionary is the same object as False
154 def test_is_a_dictionary_falsy_or_truthy(self): 155 # self.assertEqual(dict(), False) 156 self.assertNotEqual(dict(), False) 157 self.assertIs(dict(), False) 158 159 160# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {} is not Falsethe empty dictionary is not the same object as False
I change assertIs to assertIsNot for
dict(), False154 def test_is_a_dictionary_falsy_or_truthy(self): 155 # self.assertEqual(dict(), False) 156 self.assertNotEqual(dict(), False) 157 # self.assertIs(dict(), False) 158 self.assertIsNot(dict(), False) 159 160 161# NOTESthe test passes because a dictionary is not the same object as False.
I add an assertion for if the empty dictionary is equal to True
157 # self.assertIs(dict(), False) 158 self.assertIsNot(dict(), False) 159 self.assertEqual(dict(), True) 160 161 162# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {} != Truethe empty dictionary is not equal to True.
I change assertEqual to assertNotEqual for
dict(), True157 # self.assertIs(dict(), False) 158 self.assertIsNot(dict(), False) 159 # self.assertEqual(dict(), True) 160 self.assertNotEqual(dict(), True) 161 162 163# NOTESthe test passes.
I add an assertion for if the empty dictionary is the same object as True
159 # self.assertEqual(dict(), True) 160 self.assertNotEqual(dict(), True) 161 self.assertIs(dict(), True) 162 163 164# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {} is not Truethe empty dictionary is not the same object as True
I change assertIs to assertIsNot for
dict(), True159 # self.assertEqual(dict(), True) 160 self.assertNotEqual(dict(), True) 161 # self.assertIs(dict(), True) 162 self.assertIsNot(dict(), True) 163 164 165# NOTESthe test passes because a dictionary is not the same object as True.
I add an assertion for
bool(dict())161 # self.assertIs(dict(), True) 162 self.assertIsNot(dict(), True) 163 self.assertTrue(bool(dict())) 164 165 166# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the result of
bool(dict())is False.I change assertTrue to assertFalse for
bool(dict())161 # self.assertIs(dict(), True) 162 self.assertIsNot(dict(), True) 163 # self.assertTrue(bool(dict())) 164 self.assertFalse(bool(dict())) 165 166 167# NOTESthe test passes.
I add a comment
177# True is NOT False 178# bool(the empty dictionary) is False 179# bool(the empty set) is False 180# bool(the empty list) is False 181# bool(the empty tuple) is False 182# bool(the empty string) is False 183# bool(zero) is False 184# bool(None) is False 185# False is False 186# False is an integer 187# False is a boolean 188# False is NOT TrueI add an assertion for
dict()without bool163 # self.assertTrue(bool(dict())) 164 self.assertFalse(bool(dict())) 165 self.assertTrue(dict()) 166 167 168# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {} is not truebecause the result of
bool(dict())which isbool({})is False.dict()is another way to write{}(the empty dictionary).
I change assertTrue to assertFalse for
dict()163 # self.assertTrue(bool(dict())) 164 self.assertFalse(bool(dict())) 165 # self.assertTrue(dict()) 166 self.assertFalse(dict()) 167 168 169# NOTESThe test passes because the result of
bool(dict())is False.The empty dictionary is grouped as False.
I remove the commented lines from test_is_a_dictionary_falsy_or_truthy
154 def test_is_a_dictionary_falsy_or_truthy(self): 155 self.assertNotEqual(dict(), False) 156 self.assertIsNot(dict(), False) 157 self.assertNotEqual(dict(), True) 158 self.assertIsNot(dict(), True) 159 self.assertFalse(bool(dict())) 160 self.assertFalse(dict()) 161 162 163# NOTESI add an assertion to test if a dictionary with things is grouped as False or True
160 self.assertFalse(dict()) 161 162 a_dictionary = {'key': 'value'} 163 self.assertEqual(a_dictionary, False) 164 165 166# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {'key': 'value'} != FalseI change assertEqual to assertNotEqual for
a_dictionary, False160 self.assertFalse(dict()) 161 162 a_dictionary = {'key': 'value'} 163 # self.assertEqual(a_dictionary, False) 164 self.assertNotEqual(a_dictionary, False) 165 166 167# NOTESthe test passes.
I add an assertion for if a dictionary with things is the same object as False
162 a_dictionary = {'key': 'value'} 163 # self.assertEqual(a_dictionary, False) 164 self.assertNotEqual(a_dictionary, False) 165 self.assertIs(a_dictionary, False) 166 167 168# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {'key': 'value'} is not FalseI change assertIs to assertIsNot for
a_dictionary, False162 a_dictionary = {'key': 'value'} 163 # self.assertEqual(a_dictionary, False) 164 self.assertNotEqual(a_dictionary, False) 165 # self.assertIs(a_dictionary, False) 166 self.assertIsNot(a_dictionary, False) 167 168 169# NOTESthe test passes because a dictionary is not the same object as False.
I add an assertion to test if a dictionary with things is equal to True
165 # self.assertIs(a_dictionary, False) 166 self.assertIsNot(a_dictionary, False) 167 self.assertEqual(a_dictionary, True) 168 169 170# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {'key': 'value'} != TrueI change assertEqual to assertNotEqual for
a_dictionary, True165 # self.assertIs(a_dictionary, False) 166 self.assertIsNot(a_dictionary, False) 167 # self.assertEqual(a_dictionary, True) 168 self.assertNotEqual(a_dictionary, True) 169 170 171# NOTESthe test passes.
I add an assertion for if a dictionary with things is the same object as True
167 # self.assertEqual(a_dictionary, True) 168 self.assertNotEqual(a_dictionary, True) 169 self.assertIs(a_dictionary, True) 170 171 172# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {'key': 'value'} is not TrueI change assertIs to assertIsNot for
a_dictionary, True167 # self.assertEqual(a_dictionary, True) 168 self.assertNotEqual(a_dictionary, True) 169 # self.assertIs(a_dictionary, True) 170 self.assertIsNot(a_dictionary, True) 171 172 173# NOTESthe test passes because a dictionary is not the same object as True.
I add an assertion for
bool(a_dictionary)169 # self.assertIs(a_dictionary, True) 170 self.assertIsNot(a_dictionary, True) 171 self.assertFalse(bool(a_dictionary)) 172 173 174# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the result of
bool({'key': 'value'})is True.I change assertFalse to assertTrue for
(bool(a_dictionary))169 # self.assertIs(a_dictionary, True) 170 self.assertIsNot(a_dictionary, True) 171 # self.assertFalse(bool(a_dictionary)) 172 self.assertTrue(bool(a_dictionary)) 173 174 175# NOTESthe test passes.
I add a comment
175# NOTES 176# bool(a dictionary with things) is True 177# bool(a set with things) is True 178# bool(a list with things) is True 179# bool(a tuple with things) is True 180# bool(a string with things) is True 181# bool(a positive number) is True 182# bool(a negative number) is True 183# True is True 184# True is an integer 185# True is a boolean 186# True is NOT FalseI add an assertion for
a_dictionarywithout bool171 # self.assertFalse(bool(a_dictionary)) 172 self.assertTrue(bool(a_dictionary)) 173 self.assertFalse(a_dictionary) 174 175 176# NOTESthe terminal is my friend, and shows AssertionError
AssertionError: {'key': 'value'} is not falsebecause the result of
bool({'key': 'value'})is True.I change assertFalse to assertTrue for
a_dictionary171 # self.assertFalse(bool(a_dictionary)) 172 self.assertTrue(bool(a_dictionary)) 173 # self.assertFalse(a_dictionary) 174 self.assertTrue(a_dictionary) 175 176 177# NOTESThe test passes because the result of
bool({'key': 'value'})is True.A dictionary with things is grouped as True.
I remove the commented lines from test_is_a_dictionary_falsy_or_truthy
162 a_dictionary = {'key': 'value'} 163 self.assertNotEqual(a_dictionary, False) 164 self.assertIsNot(a_dictionary, False) 165 self.assertNotEqual(a_dictionary, True) 166 self.assertIsNot(a_dictionary, True) 167 self.assertTrue(bool(a_dictionary)) 168 self.assertTrue(a_dictionary) 169 170 171# NOTESI add a git commit message in the other terminal
git commit --all --message \ 'add test_is_a_dictionary_falsy_or_truthy'
The empty dictionary is grouped as False. A dictionary with things is grouped as True.
extract assert_is_falsy method
All the objects had the same assertions when testing if something is grouped as False
self.assertNotEqual(an_object, False)
self.assertIsNot(an_object, False)
self.assertNotEqual(an_object, True)
self.assertIsNot(an_object, True)
self.assertFalse(bool(an_object))
self.assertFalse(an_object)
I can make a function to remove the repetition.
RED: make it fail
I go back to the terminal where the tests are running
I add a function to test if something is grouped as False
20 def test_what_is_true(self): 21 self.assertIsInstance(True, (bool, int)) 22 ...32 self.assertTrue(True) 33 34 def assert_is_falsy(self, an_object): 35 self.assertEqual(an_object, False) 36 self.assertIs(an_object, False) 37 self.assertEqual(an_object, True) 38 self.assertIs(an_object, True) 39 self.assertTrue(bool(an_object)) 40 self.assertTrue(an_object) 41 42 def test_is_none_falsy_or_truthy(self):I use the assert_is_falsy method in test_is_none_falsy_or_truthy
42 def test_is_none_falsy_or_truthy(self): 43 # self.assertNotEqual(None, False) 44 # self.assertIsNot(None, False) 45 # self.assertNotEqual(None, True) 46 # self.assertIsNot(None, True) 47 # self.assertFalse(bool(None)) 48 # self.assertFalse(None) 49 self.assert_is_falsy(None) 50 51 def test_is_an_integer_falsy_or_truthy(self):the terminal is my friend, and shows AssertionError
AssertionError: None != False
GREEN: make it pass
I change assertEqual to assertNotEqual for
an_object, Falsein the assert_is_falsy method34 def assert_is_falsy(self, an_object): 35 # self.assertEqual(an_object, False) 36 self.assertNotEqual(an_object, False) 37 self.assertIs(an_object, False)the terminal is my friend, and shows AssertionError
AssertionError: None is not FalseI change assertIs to assertIsNot for
an_object, False36 self.assertNotEqual(an_object, False) 37 # self.assertIs(an_object, False) 38 self.assertIsNot(an_object, False) 39 self.assertEqual(an_object, True)the terminal is my friend, and shows AssertionError
AssertionError: None != TrueI change assertEqual to assertNotEqual for
an_object, True38 self.assertIsNot(an_object, False) 39 # self.assertEqual(an_object, True) 40 self.assertNotEqual(an_object, True) 41 self.assertIs(an_object, True)the terminal is my friend, and shows AssertionError
AssertionError: None is not TrueI change assertIs to assertIsNot for
an_object, True40 self.assertNotEqual(an_object, True) 41 # self.assertIs(an_object, True) 42 self.assertIsNot(an_object, True) 43 self.assertTrue(bool(an_object))the terminal is my friend, and shows AssertionError
AssertionError: False is not trueI change assertTrue to assertFalse for
bool(an_object)42 self.assertIsNot(an_object, True) 43 # self.assertTrue(bool(an_object)) 44 self.assertFalse(bool(an_object)) 45 self.assertTrue(an_object)the terminal is my friend, and shows AssertionError
44 self.assertFalse(bool(an_object)) 45 # self.assertTrue(an_object) 46 self.assertFalse(an_object) 47 48 def test_is_none_falsy_or_truthy(self):the test passes. The assert_is_falsy method works.
REFACTOR: make it better
I remove the commented lines from assert_is_falsy
34 def assert_is_falsy(self, an_object): 35 self.assertNotEqual(an_object, False) 36 self.assertIsNot(an_object, False) 37 self.assertNotEqual(an_object, True) 38 self.assertIsNot(an_object, True) 39 self.assertFalse(bool(an_object)) 40 self.assertFalse(an_object) 41 42 def test_is_none_falsy_or_truthy(self):I remove the commented lines from test_is_none_falsy_or_truthy
42 def test_is_none_falsy_or_truthy(self): 43 self.assert_is_falsy(None) 44 45 def test_is_an_integer_falsy_or_truthy(self):I use the assert_is_falsy method for
0in test_is_an_integer_falsy_or_truthy45 def test_is_an_integer_falsy_or_truthy(self): 46 a_negative_integer = -1 47 ...52 self.assertTrue(a_negative_integer) 53 54 self.assertEqual(0, False) 55 self.assertIsNot(0, False) 56 self.assertNotEqual(0, True) 57 self.assertIsNot(0, True) 58 self.assertFalse(bool(0)) 59 self.assertFalse(0) 60 self.assert_is_falsy(0) 61 62 a_positive_integer = 1the terminal is my friend, and shows AssertionError
AssertionError: 0 == Falsebecause the value of False is
0.I remove the call to the assert_is_falsy method because I cannot it use it for
052 self.assertTrue(a_negative_integer) 53 54 self.assertEqual(0, False) 55 self.assertIsNot(0, False) 56 self.assertNotEqual(0, True) 57 self.assertIsNot(0, True) 58 self.assertFalse(bool(0)) 59 self.assertFalse(0) 60 61 a_positive_integer = 1the test is green again.
I use the assert_is_falsy method for
0.0in test_is_a_float_falsy_or_truthy69 def test_is_a_float_falsy_or_truthy(self): 70 a_negative_float = -0.1 71 ...76 self.assertTrue(a_negative_float) 77 78 self.assertEqual(0.0, False) 79 self.assertIsNot(0.0, False) 80 self.assertNotEqual(0.0, True) 81 self.assertIsNot(0.0, True) 82 self.assertFalse(bool(0.0)) 83 self.assertFalse(0.0) 84 self.assert_is_falsy(0.0) 85 86 a_positive_float = 0.1the terminal is my friend, and shows AssertionError
AssertionError: 0.0 == Falsebecause the value of False is
0which is equal to0.0.I remove the call to the assert_is_falsy method because I cannot it use it for
0.076 self.assertTrue(a_negative_float) 77 78 self.assertEqual(0.0, False) 79 self.assertIsNot(0.0, False) 80 self.assertNotEqual(0.0, True) 81 self.assertIsNot(0.0, True) 82 self.assertFalse(bool(0.0)) 83 self.assertFalse(0.0) 84 85 a_positive_float = 0.1green again.
I add a comment about the value of False
185# True is NOT False 186# the value of False is 0 187# bool(the empty dictionary) is False 188# bool(the empty set) is False 189# bool(the empty list) is False 190# bool(the empty tuple) is False 191# bool(the empty string) is False 192# bool(zero) is False 193# bool(None) is False 194# False is False 195# False is an integer 196# the value of False is 0 197# False is a boolean 198# False is NOT True 199 200 201# Exceptions seen 202# AssertionErrorI use the assert_is_falsy method for the empty dictionary in test_is_a_dictionary_falsy_or_truthy
157 def test_is_a_dictionary_falsy_or_truthy(self): 158 # self.assertNotEqual(dict(), False) 159 # self.assertIsNot(dict(), False) 160 # self.assertNotEqual(dict(), True) 161 # self.assertIsNot(dict(), True) 162 # self.assertFalse(bool(dict())) 163 # self.assertFalse(dict()) 164 self.assert_is_falsy(dict()) 165 166 a_dictionary = {'key': 'value'}the test is still green.
I remove the commented lines from test_is_a_dictionary_falsy_or_truthy
157 def test_is_a_dictionary_falsy_or_truthy(self): 158 self.assert_is_falsy(dict()) 159 160 a_dictionary = {'key': 'value'}I use the assert_is_falsy method for the empty set in test_is_a_set_falsy_or_truthy
141 def test_is_a_set_falsy_or_truthy(self): 142 # self.assertNotEqual(set(), False) 143 # self.assertIsNot(set(), False) 144 # self.assertNotEqual(set(), True) 145 # self.assertIsNot(set(), True) 146 # self.assertFalse(bool(set())) 147 # self.assertFalse(set()) 148 self.assert_is_falsy(set()) 149 150 a_set = {0, 1, 2, 'n'}still green.
I remove the commented lines from test_is_a_set_falsy_or_truthy
141 def test_is_a_set_falsy_or_truthy(self): 142 self.assert_is_falsy(set()) 143 144 a_set = {0, 1, 2, 'n'}I use the assert_is_falsy method for the empty list in test_is_a_list_falsy_or_truthy
125 def test_is_a_list_falsy_or_truthy(self): 126 # self.assertNotEqual(list(), False) 127 # self.assertIsNot(list(), False) 128 # self.assertNotEqual(list(), True) 129 # self.assertIsNot(list(), True) 130 # self.assertFalse(bool(list())) 131 # self.assertFalse(list()) 132 self.assert_is_falsy(list()) 133 134 a_list = [0, 1, 2, 'n']still green.
I remove the commented lines from test_is_a_list_falsy_or_truthy
125 def test_is_a_list_falsy_or_truthy(self): 126 self.assert_is_falsy(list()) 127 128 a_list = [0, 1, 2, 'n']I use the assert_is_falsy method for the empty tuple in test_is_a_tuple_falsy_or_truthy
109 def test_is_a_tuple_falsy_or_truthy(self): 110 # self.assertNotEqual(tuple(), False) 111 # self.assertIsNot(tuple(), False) 112 # self.assertNotEqual(tuple(), True) 113 # self.assertIsNot(tuple(), True) 114 # self.assertFalse(bool(tuple())) 115 # self.assertFalse(tuple()) 116 self.assert_is_falsy(tuple()) 117 118 a_tuple = (0, 1, 2, 'n')green.
I remove the commented lines from test_is_a_tuple_falsy_or_truthy
109 def test_is_a_tuple_falsy_or_truthy(self): 110 self.assert_is_falsy(tuple()) 111 112 a_tuple = (0, 1, 2, 'n')I use the assert_is_falsy method for the empty string in test_is_a_string_falsy_or_truthy
93 def test_is_a_string_falsy_or_truthy(self): 94 # self.assertNotEqual(str(), False) 95 # self.assertIsNot(str(), False) 96 # self.assertNotEqual(str(), True) 97 # self.assertIsNot(str(), True) 98 # self.assertFalse(bool(str())) 99 # self.assertFalse(str()) 100 self.assert_is_falsy(str()) 101 102 a_string = "string with things"green.
I remove the commented lines from test_is_a_string_falsy_or_truthy
93 def test_is_a_string_falsy_or_truthy(self): 94 self.assert_is_falsy(str()) 95 96 a_string = "string with things"I add a git commit message in the other terminal
git commit --all --message \ 'extract assert_is_falsy method'
extract assert_is_truthy method
All the objects had the same assertions when testing if something is grouped as True
self.assertNotEqual(an_object, False)
self.assertIsNot(an_object, False)
self.assertNotEqual(an_object, True)
self.assertIsNot(an_object, True)
self.assertTrue(bool(an_object))
self.assertTrue(an_object)
I can make a method like I did with :ref:`assert_is_falsy<extract assert_is_falsy method>`to remove the repetition.
RED: make it fail
I go back to the terminal where the tests are running
I add a method to test if something is grouped as True
34 def assert_is_falsy(self, an_object): 35 self.assertNotEqual(an_object, False) 36 ...40 self.assertFalse(an_object) 41 42 def assert_is_truthy(self, an_object): 43 self.assertEqual(an_object, False) 44 self.assertIs(an_object, False) 45 self.assertEqual(an_object, True) 46 self.assertIs(an_object, True) 47 self.assertFalse(bool(an_object)) 48 self.assertFalse(an_object) 49 50 def test_is_none_falsy_or_truthy(self):I use the assert_is_truthy method for a negative integer in test_is_an_integer_falsy_or_truthy
53 def test_is_an_integer_falsy_or_truthy(self): 54 # a_negative_integer = -1 55 # self.assertNotEqual(a_negative_integer, False) 56 # self.assertIsNot(a_negative_integer, False) 57 # self.assertNotEqual(a_negative_integer, True) 58 # self.assertIsNot(a_negative_integer, True) 59 # self.assertTrue(bool(a_negative_integer)) 60 # self.assertTrue(a_negative_integer) 61 self.assert_is_truthy(-1)the terminal is my friend, and shows AssertionError
AssertionError: -1 != False
GREEN: make it pass
I change assertEqual to assertNotEqual for
an_object, Falsein the assert_is_truthy method42 def assert_is_truthy(self, an_object): 43 # self.assertEqual(an_object, False) 44 self.assertNotEqual(an_object, False) 45 self.assertIs(an_object, False)the terminal is my friend, and shows AssertionError
AssertionError: -1 is not FalseI change assertIs to assertIsNot for
an_object, False44 self.assertNotEqual(an_object, False) 45 # self.assertIs(an_object, False) 46 self.assertIsNot(an_object, False) 47 self.assertEqual(an_object, True)AssertionError: -1 != TrueI change assertEqual to assertNotEqual for
an_object, True46 self.assertIsNot(an_object, False) 47 # self.assertEqual(an_object, True) 48 self.assertNotEqual(an_object, True) 49 self.assertIs(an_object, True)the terminal is my friend, and shows AssertionError
AssertionError: -1 is not TrueI change assertIs to assertIsNot for
an_object, True48 self.assertNotEqual(an_object, True) 49 # self.assertIs(an_object, True) 50 self.assertIsNot(an_object, True) 51 self.assertFalse(bool(an_object))the terminal is my friend, and shows AssertionError
AssertionError: True is not falseI change assertFalse to assertTrue for
bool(an_object)50 self.assertIsNot(an_object, True) 51 # self.assertFalse(bool(an_object)) 52 self.assertTrue(bool(an_object)) 53 self.assertFalse(an_object)the terminal is my friend, and shows AssertionError
AssertionError: -1 is not falseI change assertFalse to assertTrue for
an_object52 self.assertTrue(bool(an_object)) 53 # self.assertFalse(an_object) 54 self.assertTrue(an_object) 55 56 def test_is_none_falsy_or_truthy(self):the test passes, the assert_is_truthy method works as expected.
REFACTOR: make it better
I remove the commented lines from assert_is_truthy
42 def assert_is_truthy(self, an_object): 43 self.assertNotEqual(an_object, False) 44 self.assertIsNot(an_object, False) 45 self.assertNotEqual(an_object, True) 46 self.assertIsNot(an_object, True) 47 self.assertTrue(bool(an_object)) 48 self.assertTrue(an_object) 49 50 def test_is_none_falsy_or_truthy(self):I remove the commented lines from test_is_an_integer_falsy_or_truthy
53 def test_is_an_integer_falsy_or_truthy(self): 54 self.assert_is_truthy(-1) 55 56 self.assertEqual(0, False)I use the assert_is_truthy method for a positive integer
63 a_positive_integer = 1 64 self.assertNotEqual(a_positive_integer, False) 65 self.assertIsNot(a_positive_integer, False) 66 self.assertEqual(1, True) 67 self.assertIsNot(a_positive_integer, True) 68 self.assertTrue(bool(a_positive_integer)) 69 self.assertTrue(a_positive_integer) 70 self.assert_is_truthy(1) 71 72 def test_is_a_float_falsy_or_truthy(self):the terminal is my friend, and shows AssertionError
AssertionError: 1 == Truebecause the value of True is
1.I remove the call to the assert_is_truthy method because I cannot it use it for
163 a_positive_integer = 1 64 self.assertNotEqual(a_positive_integer, False) 65 self.assertIsNot(a_positive_integer, False) 66 self.assertEqual(1, True) 67 self.assertIsNot(a_positive_integer, True) 68 self.assertTrue(bool(a_positive_integer)) 69 self.assertTrue(a_positive_integer) 70 71 def test_is_a_float_falsy_or_truthy(self):the test is green again.
I add a comment about the value of True
151# NOTES 152# the value of True is 1 153# bool(a dictionary with things) is True 154# bool(a set with things) is True 155# bool(a list with things) is True 156# bool(a tuple with things) is True 157# bool(a string with things) is True 158# bool(a positive number) is True 159# bool(a negative number) is True 160# True is True 161# True is an integer 162# True is a boolean 163# True is NOT FalseI use the assert_is_truthy method for a dictionary with things in test_is_a_dictionary_falsy_or_truthy
139 def test_is_a_dictionary_falsy_or_truthy(self): 140 self.assert_is_falsy(dict()) 141 142 # a_dictionary = {'key': 'value'} 143 # self.assertNotEqual(a_dictionary, False) 144 # self.assertIsNot(a_dictionary, False) 145 # self.assertNotEqual(a_dictionary, True) 146 # self.assertIsNot(a_dictionary, True) 147 # self.assertTrue(bool(a_dictionary)) 148 # self.assertTrue(a_dictionary) 149 self.assert_is_truthy({'key': 'value'}) 150 151 152# NOTESthe test is still green.
I remove the commented lines from test_is_a_dictionary_falsy_or_truthy
139 def test_is_a_dictionary_falsy_or_truthy(self): 140 self.assert_is_falsy(dict()) 141 self.assert_is_truthy({'key': 'value'}) 142 143 144# NOTESI use the assert_is_truthy method for a set with things in test_is_a_set_falsy_or_truthy
128 def test_is_a_set_falsy_or_truthy(self): 129 self.assert_is_falsy(set()) 130 131 # a_set = {0, 1, 2, 'n'} 132 # self.assertNotEqual(a_set, False) 133 # self.assertIsNot(a_set, False) 134 # self.assertNotEqual(a_set, True) 135 # self.assertIsNot(a_set, True) 136 # self.assertTrue(bool(a_set)) 137 # self.assertTrue(a_set) 138 self.assert_is_truthy({0, 1, 2, 'n'}) 139 140 def test_is_a_dictionary_falsy_or_truthy(self):still green.
I remove the commented lines from test_is_a_set_falsy_or_truthy
128 def test_is_a_set_falsy_or_truthy(self): 129 self.assert_is_falsy(set()) 130 self.assert_is_truthy({0, 1, 2, 'n'}) 131 132 def test_is_a_dictionary_falsy_or_truthy(self):I use the assert_is_truthy method for a list with things in test_is_a_list_falsy_or_truthy
117 def test_is_a_list_falsy_or_truthy(self): 118 self.assert_is_falsy(list()) 119 120 a_list = [0, 1, 2, 'n'] 121 # self.assertNotEqual(a_list, False) 122 # self.assertIsNot(a_list, False) 123 # self.assertNotEqual(a_list, True) 124 # self.assertIsNot(a_list, True) 125 # self.assertTrue(bool(a_list)) 126 # self.assertTrue(a_list) 127 self.assert_is_truthy([0, 1, 2, 'n']) 128 129 def test_is_a_set_falsy_or_truthy(self):green.
I remove the commented lines from test_is_a_list_falsy_or_truthy
117 def test_is_a_list_falsy_or_truthy(self): 118 self.assert_is_falsy(list()) 119 self.assert_is_truthy([0, 1, 2, 'n']) 120 121 def test_is_a_set_falsy_or_truthy(self):I use the assert_is_truthy method for a tuple with things in test_is_a_tuple_falsy_or_truthy
106 def test_is_a_tuple_falsy_or_truthy(self): 107 self.assert_is_falsy(tuple()) 108 109 # a_tuple = (0, 1, 2, 'n') 110 # self.assertNotEqual(a_tuple, False) 111 # self.assertIsNot(a_tuple, False) 112 # self.assertNotEqual(a_tuple, True) 113 # self.assertIsNot(a_tuple, True) 114 # self.assertTrue(bool(a_tuple)) 115 # self.assertTrue(a_tuple) 116 self.assert_is_truthy((0, 1, 2, 'n')) 117 118 def test_is_a_list_falsy_or_truthy(self):still green.
I remove the commented lines from test_is_a_tuple_falsy_or_truthy
106 def test_is_a_tuple_falsy_or_truthy(self): 107 self.assert_is_falsy(tuple()) 108 self.assert_is_truthy((0, 1, 2, 'n')) 109 110 def test_is_a_list_falsy_or_truthy(self):I use the assert_is_truthy method for a string with things in test_is_a_string_falsy_or_truthy
95 def test_is_a_string_falsy_or_truthy(self): 96 self.assert_is_falsy(str()) 97 98 # a_string = "string with things" 99 # self.assertNotEqual(a_string, False) 100 # self.assertIsNot(a_string, False) 101 # self.assertNotEqual(a_string, True) 102 # self.assertIsNot(a_string, True) 103 # self.assertTrue(bool(a_string)) 104 # self.assertTrue(a_string) 105 self.assert_is_truthy('string with things') 106 107 def test_is_a_tuple_falsy_or_truthy(self):the test is still green.
I remove the commented lines from test_is_a_string_falsy_or_truthy
95 def test_is_a_string_falsy_or_truthy(self): 96 self.assert_is_falsy(str()) 97 self.assert_is_truthy('string with things') 98 99 def test_is_a_tuple_falsy_or_truthy(self):I use the assert_is_truthy method for a positive float in test_is_a_float_falsy_or_truthy
85 self.assertFalse(0.0) 86 87 # a_positive_float = 0.1 88 # self.assertNotEqual(a_positive_float, False) 89 # self.assertIsNot(a_positive_float, False) 90 # self.assertNotEqual(a_positive_float, True) 91 # self.assertIsNot(a_positive_float, True) 92 # self.assertTrue(bool(a_positive_float)) 93 # self.assertTrue(a_positive_float) 94 self.assert_is_truthy(0.1) 95 96 def test_is_a_string_falsy_or_truthy(self):still green.
I use the assert_is_truthy method for a negative float
71 def test_is_a_float_falsy_or_truthy(self): 72 # a_negative_float = -0.1 73 # self.assertNotEqual(a_negative_float, False) 74 # self.assertIsNot(a_negative_float, False) 75 # self.assertNotEqual(a_negative_float, True) 76 # self.assertIsNot(a_negative_float, True) 77 # self.assertTrue(bool(a_negative_float)) 78 # self.assertTrue(a_negative_float) 79 self.assert_is_truthy(-0.1) 80 81 self.assertEqual(0.0, False)green.
I remove the commented lines from test_is_a_float_falsy_or_truthy
71 def test_is_a_float_falsy_or_truthy(self): 72 self.assert_is_truthy(-0.1) 73 74 self.assertEqual(0.0, False) 75 self.assertIsNot(0.0, False) 76 self.assertNotEqual(0.0, True) 77 self.assertIsNot(0.0, True) 78 self.assertFalse(bool(0.0)) 79 self.assertFalse(0.0) 80 81 self.assert_is_truthy(0.1) 82 83 def test_is_a_string_falsy_or_truthy(self):I add a git commit message in the other terminal
git commit --all --message \ 'extract assert_is_truthy method'
extract assert_is_not_the_same_as_false_or_true method
The assert_is_falsy and assert_is_truthy methods use the same assertion to make sure that the object they receive is not the same as False or True.
self.assertNotEqual(an_object, False)
self.assertIsNot(an_object, False)
self.assertNotEqual(an_object, True)
self.assertIsNot(an_object, True)
I can add a method to remove this repetition.
REFACTOR: make it better
I go back to the terminal where the tests are running
I add a method named assert_is_not_the_same_as_false_or_true
20 def test_what_is_true(self): 21 self.assertIsInstance(True, (bool, int)) 22 ...32 self.assertTrue(True) 33 34 def assert_is_not_the_same_as_false_or_true(self, an_object): 35 self.assertNotEqual(an_object, False) 36 self.assertIsNot(an_object, False) 37 self.assertNotEqual(an_object, True) 38 self.assertIsNot(an_object, True) 39 40 def assert_is_falsy(self, an_object):I use the assert_is_not_the_same_as_false_or_true method in assert_is_falsy
40 def assert_is_falsy(self, an_object): 41 # self.assertNotEqual(an_object, False) 42 # self.assertIsNot(an_object, False) 43 # self.assertNotEqual(an_object, True) 44 # self.assertIsNot(an_object, True) 45 self.assert_is_not_the_same_as_false_or_true(an_object) 46 self.assertFalse(bool(an_object)) 47 self.assertFalse(an_object) 48 49 def assert_is_truthy(self, an_object):the tests are still green.
I remove the commented lines from assert_is_falsy
40 def assert_is_falsy(self, an_object): 41 self.assert_is_not_the_same_as_false_or_true(an_object) 42 self.assertFalse(bool(an_object)) 43 self.assertFalse(an_object) 44 45 def assert_is_truthy(self, an_object):I use the assert_is_not_the_same_as_false_or_true method in assert_is_truthy
45 def assert_is_truthy(self, an_object): 46 # self.assertNotEqual(an_object, False) 47 # self.assertIsNot(an_object, False) 48 # self.assertNotEqual(an_object, True) 49 # self.assertIsNot(an_object, True) 50 self.assert_is_not_the_same_as_false_or_true(an_object) 51 self.assertTrue(bool(an_object)) 52 self.assertTrue(an_object) 53 54 def test_is_none_falsy_or_truthy(self):the tests are still green.
I remove the commented lines from assert_is_truthy
45 def assert_is_truthy(self, an_object): 46 self.assert_is_not_the_same_as_false_or_true(an_object) 47 self.assertTrue(bool(an_object)) 48 self.assertTrue(an_object) 49 50 def test_is_none_falsy_or_truthy(self):I add a git commit message in the other terminal
git commit --all --message \ 'extract assert_is_not_the_same_as_false_or_true method'
close the project
I close
test_booleans.pyI click in the terminal where the tests are running
I use q on the keyboard to leave the tests. The terminal goes back to the command line.
I change directory to the parent of
booleanscd ..the terminal shows
.../pumping_python
review
I know that bool is an object. It only has two instances - False and True
In Python the following objects are grouped as
The following things are grouped as False
The following things are grouped as True
containers with things
positive and negative numbers
This comes in handy when I want programs to make decisions, because they can choose what to do based on if an object is grouped as False (0, empty or None ) or is grouped as True (positive and negative numbers or has something in it).
I can use assertFalse in place of assertIs(bool(x), False) and assertTrue for assertIs(bool(x), True).
How many questions can you answer after going through this chapter?
code from the chapter
what is next?
So far I have done the same steps to make a Python Test Driven Development environment. Would you like to see me turn those steps into a program to automatically make a Test Driven Development project with one command?.
rate pumping python
If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too.