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 booleans folder

    cd booleans
    

    the terminal shows I am in the booleans folder

    .../pumping_python/booleans
    
  • I activate the virtual environment

    source .venv/bin/activate
    

    Attention

    on Windows without Windows Subsystem for Linux use .venv/bin/activate.ps1 NOT source .venv/bin/activate

    .venv/scripts/activate.ps1
    

    the terminal shows

    (.venv) .../pumping_python/booleans
    
  • I use pytest-watch to run the tests

    pytest-watch
    

    the 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.py to 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'>

the bool class is not a child of the int class


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

Do you want to see all the CODE I typed in this 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