booleans 3
Inheritance showed that a class can have more than one parent, and the parents are not the same.
Earlier on, I tested if booleans are Integers and the tests showed that False and True are both integers and booleans which begs the question - is bool a child of int or are they both parents of False and True?
open the project
I change directory to the
booleansfoldercd booleansthe terminal shows I am in the
booleansfolder.../pumping_python/booleansI activate the virtual environment
source .venv/bin/activateAttention
on Windows without Windows Subsystem for Linux use
.venv/bin/activate.ps1NOTsource .venv/bin/activate.venv/scripts/activate.ps1the terminal shows
(.venv) .../pumping_python/booleansI use
pytest-watchto run the testspytest-watchthe terminal shows
rootdir: .../pumping_python/booleans collected 4 items tests/test_booleans.py .... [100%] ============================ 4 passed in X.YZs =============================I hold ctrl on the keyboard and click on
tests/test_booleans.pyto open it in the editor
test_if_bool_is_an_int
RED: make it fail
I add a new test
49 self.assertEqual(True/1, 1)
50
51 def test_if_bool_is_an_int(self):
52 self.assertIsInstance(bool, int)
53
54
55 # NOTES
the terminal shows AssertionError
AssertionError: <class 'bool'> is not an instance of <class 'int'>
GREEN: make it pass
I change assertIsInstance to assertNotIsInstance
51 def test_if_bool_is_an_int(self):
52 self.assertNotIsInstance(bool, int)
the test passes
review
code from the chapter
what is next?
you have gone through a lot of things and know
Would you like to use one of the class methods with the calculator?
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