@@ -5,7 +5,7 @@ Debugging and testing
55
66In :numref: `Chapter %s <errors_and_exceptions >` we learned about
77:term: `exceptions <exception> ` and how to read the :term: `traceback ` that is
8- printed when an unhandled exception is raised. This week we will look at other
8+ printed when an unhandled exception is raised. In this chapter we will look at other
99tools and techniques that we can use to understand what is wrong with a piece
1010of code, and therefore how to fix it. Before we do that, we'll divert just
1111briefly to introduce an important Python module that we'll use in a lot of the
@@ -84,7 +84,7 @@ Observe that the :class:`~pandas.DataFrame` acts as a dictionary of
8484one-dimensional data :class: `~pandas.Series `. A :class: `pandas.Series ` can be
8585indexed and sliced like any other Python :ref: `sequence type <typesseq >`. This
8686very high level introduction is all we'll need to use pandas in demonstrations
87- this week . Much more documentation is available on the `pandas website <https://pandas.pydata.org/docs/ >`__.
87+ in this chapter . Much more documentation is available on the `pandas website <https://pandas.pydata.org/docs/ >`__.
8888
8989.. note ::
9090
@@ -120,7 +120,7 @@ advantage that integrates well with IPython. Another advanced command-line
120120debugger is `pdb++
121121<https://github.com/pdbpp/pdbpp#pdb-a-drop-in-replacement-for-pdb> `__. The
122122distinct advantage of pdb++ is that it replaces the built-in pdb. Among other
123- things, this means it can be triggered from a failed `pytest
123+ things, this means it can be triggered from a failed `Pytest
124124<https://docs.pytest.org/en/stable/> `__ test.
125125
126126The alternative to a command-line debugger is to use a graphical debugger
@@ -650,15 +650,15 @@ and fails if it is.
650650Creating a test command
651651~~~~~~~~~~~~~~~~~~~~~~~
652652
653- Since pytest provides a framework for creating programs which succeed or fail,
653+ Since Pytest provides a framework for creating programs which succeed or fail,
654654one approach is write the test that we wish had existed at the time the bug
655655slipped into our code. The bisection search effectively enables us to
656656retrospectively introduce this test into our repository. Because we're going to
657657be rolling back the state of our repository to before we created this command,
658658this is one exception to the rule that you must always commit all of your work
659659to the git repository. Make a copy of this command (for example the Python file
660- containing the pytest test) outside your repository. For the rest of this
661- section, we'll assume that you've created a pytest test in a file called
660+ containing the Pytest test) outside your repository. For the rest of this
661+ section, we'll assume that you've created a Pytest test in a file called
662662:file: `bug_test.py ` which you have placed in the folder containing your
663663repository (if you followed the instructions in :numref: `Chapter %s
664664<programs_files>` then this folder might be called
@@ -830,49 +830,85 @@ Glossary
830830Exercises
831831---------
832832
833- The exercises work a little differently this week, because the objective is not
834- to write code but to practice debugging techniques. The quiz is not on
835- BlackBoard but is instead a Google form, because that offers instant feedback.
836- You should work through the the exercises and quiz together. For most of exercises,
837- there are quiz questions which you will be able to answer if you are
838- successfully able to do the exercise.
833+ .. only :: not book
839834
840- Obtain the `skeleton code for these exercises from GitHub classroom
841- <https://classroom.github.com/a/mi6I-jcG> `__.
835+ The exercises work a little differently this week, because the objective is
836+ not to write code but to practice debugging techniques. The information on
837+ the `book website
838+ <https://object-oriented-programming.github.io/edition1/exercises.html> `__
839+ points not just to the skeleton code but also to an online quiz which will
840+ provide instant feedback on the questions below. You should access the
841+ skeleton code and then work through the quiz questions.
842842
843- .. panels ::
844- :card: quiz shadow
843+ .. only :: book
845844
846- .. link-button :: https://forms.gle/cL5eZycNC9Js19uL7
847- :text: This week's quiz
848- :classes: stretched-link
845+ The exercises work a little differently this week, because the objective is
846+ not to write code but to practice debugging techniques. The information on
847+ the book website [#exercise_page ]_
848+ points not just to the skeleton code but also to an online quiz which will
849+ provide instant feedback on the questions below. You should access the
850+ skeleton code and then work through exercises, using the online quiz to
851+ check your answers.
849852
850853.. proof :exercise :: Debugging python code
851854
852855 The skeleton code contains a Python script :file: `scripts/tests_report `.
853- Run this script under the Visual Studio code debugger and answer the quiz
854- questions about what you find.
856+ Run this script under the Visual Studio code debugger and answer the
857+ following questions about what you find. Entering the answers into the
858+ online quiz will tell you if you are correct.
859+
860+ 1. On which line of the file does the exception occur?
861+ 2. How many stack frames are there on the call stack when the exception occurs?
862+ 3. What is the exact value of the variable t?
855863
856864.. proof :exercise :: Minimal failing example
857865
858866 In the file :file: `scripts/tests_report_mfe.py ` construct a :term: `minimal failing
859867 example ` which exhibits the error you discovered in the previous section.
860868 Your minimal failing example should contain one import and one other line
861- of code. :file: `tests/test_mfe.py ` is a pytest test for this exercise.
869+ of code. :file: `tests/test_mfe.py ` is a Pytest test for this exercise.
870+
871+ .. only :: book
872+
873+ .. raw :: latex
874+
875+ \clearpage
862876
863877.. proof :exercise :: Bisection
864878
865- The Unified Form Language (UFL) is a computer symbolic algebra package used to
866- represent partial differential equations in software applying a numerical
867- technique called the finite element method. Clone the `course fork of the
868- UFL repository <https://github.com/object-oriented-python/ufl> `__. At some
869- point in the past, the following code worked:
879+ .. only :: not book
880+
881+ The Unified Form Language (UFL) is a computer symbolic algebra package
882+ used to represent partial differential equations in software applying a
883+ numerical technique called the finite element method. Clone the `course
884+ fork of the UFL repository
885+ <https://github.com/object-oriented-python/ufl> `__. At some point in
886+ the past, the following code worked:
887+
888+ .. only :: book
889+
890+ The Unified Form Language (UFL) is a computer symbolic algebra package
891+ used to represent partial differential equations in software applying a
892+ numerical technique called the finite element method. Clone the course
893+ fork of the UFL repository [#ufl ]_. At some point in
894+ the past, the following code worked:
870895
871896 .. code-block :: python3
872897
873898 import ufl
874899 argyris = ufl.FiniteElement("Argyris", degree=6, cell=ufl.triangle)
875900
876901 Use `git bisect ` to identify the first commit at which this code failed,
877- and the last commit at which it worked, and answer the corresponding quiz
878- questions.
902+ and the last commit at which it worked, and answer the following questions.
903+ The online quiz will tell you if you are correct.
904+
905+ 1. What is the commit ID of the first bad commit?
906+ 2. What is the commit ID of the last good commit?
907+
908+ .. rubric :: Footnotes
909+
910+ .. [#ufl ] `https://github.com/object-oriented-python/ufl
911+ <https://github.com/object-oriented-python/ufl> `__
912+
913+ .. [#exercise_page ] `https://object-oriented-programming.github.io/edition1/exercises.html
914+ <https://object-oriented-programming.github.io/edition1/exercises.html> `__
0 commit comments