In [ ]:
# Required boilerplate
import sys
!{sys.executable} -m pip install pytest
!{sys.executable} -m pip install ipytest

import ipytest.magics
import pytest

__file__ = 'testing2_exercise.ipynb'

1. Finalize test cases

The testing part of the TodoList implementation is incomplete. Fill ____ parts of the tests.

In [ ]:
class TodoNotFound(Exception):
    pass


class TodoList:
    def __init__(self):
        self._todo = {}
        self._done = {}
        self._task_counter = 1

    @property
    def todo_tasks(self):
        return self._todo

    @property
    def done_tasks(self):
        return self._done

    def add(self, task):
        self._todo[self._task_counter] = task
        self._task_counter += 1

    def complete(self, number):
        if number not in self._todo:
            raise TodoNotFound('{} not in todos'.format(number))

        task = self._todo.pop(number)
        self._done[number] = task

    def remove(self, number):
        if number not in self._todo:
            raise TodoNotFound('{} not in todos'.format(number))

        del self._todo[number]

Finalize tests for TodoList.

In [ ]:
%%run_pytest[clean]


@pytest.____
def todo_list():
    tl = TodoList()
    tl.add('buy milk')
    tl.add('take dog out')
    tl.add('learn pytest fixtures')
    ____ ____


def test_todo_tasks_property(todo_list):
    todo = todo_list.todo_tasks
    assert todo == {
        1: 'buy milk',
        2: 'take dog out',
        3: 'learn pytest fixtures'
    }


def test_add(____):
    todo_list.add('check pytest docs')
    todos = todo_list.todo_tasks
    assert todos[4] == ____


def test_complete(todo_list):
    # Make sure there is not done tasks yet
    assert not todo_list.done_tasks

    todo_list.complete(3)
    done = todo_list.____
    todo = todo_list.____
    assert done[3] == 'learn pytest fixtures'
    assert 3 not in ____


def test_complete_with_unknown_task_number(todo_list):
    # This is how you can test that a certain exception is raised
    with pytest.raises(TodoNotFound):
        todo_list.complete(10)


def test_remove(todo_list):
    todo_list.remove(1)
    done = todo_list.done_tasks
    todo = todo_list.todo_tasks

    assert 1 not in ____
    # Make sure it was not moved to done
    ____ not done


def test_remove_with_unknown_task_number(todo_list):
    with pytest.____(____):
        todo_list.remove(12)

2. Testing the Fibonacci numbers

Implement a test for the fibonacci function. Use pytest.mark.parametrize and test at least with numbers: 0, 1, 2, 3, and 10. You can find the expected results and more information about the Fibonacci numbers here.

In [ ]:
def fibonacci(number):
    if number in [0, 1]:
        return number
    return fibonacci(number - 1) + fibonacci(number - 2)
In [ ]:
%%run_pytest[clean]

# Your implementation here