PythiloLesson 11 of 12 · progress kept in this browser

Doctest

Examples in a docstring, written like an interactive session, can run as tests. doctest finds each line starting with >>>, runs it, and compares what it shows with the lines below. A documented example that has stopped being true then fails like any other test.

import doctest

def initials(name):
    """Return the capital initials.

    >>> initials("ada lovelace")
    'AL'
    >>> initials("")
    ''
    """
    words = name.split()
    caps = [w[0].upper() for w in words]
    return "".join(caps)

print(doctest.testmod())
Your task

parse_duration(text) is written for you, without a docstring. Give it one with at least three examples: "1h30m", a minutes-only duration such as "45m", and the ValueError it raises for "soon".