TDM 30100: Project 6 — 2022

Motivation: Code, especially newly written code, is refactored, updated, and improved frequently. It is for these reasons that testing code is imperative. Testing code is a good way to ensure that code is working as intended. When a change is made to code, you can run a suite a tests, and feel confident (or at least more confident) that the changes you made are not introducing new bugs. While methods of programming like TDD (test-driven development) are popular in some circles, and unpopular in others, what is agreed upon is that writing good tests is a useful skill and a good habit to have.

Context: This is the first of a series of two projects that explore writing unit tests, and doc tests. In The Data Mine, we will focus on using pytest, doc tests, and mypy, while writing code to manipulate and work with data.

Scope: Python, testing, pytest, mypy, doc tests

Learning Objectives
  • Write and run unit tests using pytest.

  • Include and run doc tests in your docstrings, using pytest.

  • Gain familiarity with mypy, and explain why static type checking can be useful.

  • Comprehend what a function is, and the components of a function in Python.

Make sure to read about, and use the template found here, and the important information about projects submissions here.

Dataset(s)

The following questions will use the following dataset(s):

  • /anvil/projects/tdm/data

Questions

We will dig in a little deeper in the next project, however, this project is designed to give you a little bit of a rest before October break.

We’ve provided you with two files for this project:

  1. /anvil/projects/tdm/etc/project06.py

  2. /anvil/projects/tdm/etc/test_project06.py

Start by copying these files to your own working directory.

%%bash

rm -rf $HOME/project06 || true
mkdir $HOME/project06
cp /anvil/projects/tdm/etc/project06.py $HOME/project06
cp /anvil/projects/tdm/etc/test_project06.py $HOME/project06

The first file, project06.py is a module with a bunch of functions. The second file, test_project06.py is the set of tests for the project06.py module. You can run the tests as follows.

%%bash

cd $HOME/project06
python3 -m pytest

The goal of this project is to fix all of the code in project06.py so that all of the unit tests pass. Do not modify the tests in test_project06.py, only modify the code in project06.py.

  1. Fix find_longest_timegap.

  2. Fix space_in_dir.

  3. Fix event_plotter.

  4. Fix player_info.

Items to submit
  • Your modified project06.py file.

  • Your .ipynb notebook file with a bash cell showing 100 percent of your tests passing.

  • Your .ipynb notebook file with a markdown cell for each question, and an explanation of what was wrong, and how you fixed it.

Please make sure to double check that your submission is complete, and contains all of your code and output before submitting. If you are on a spotty internet connection, it is recommended to download your submission after submitting it to make sure what you think you submitted, was what you actually submitted.

In addition, please review our submission guidelines before submitting your project.