Unverified Commit 9372ce67 authored by Akke Viitanen's avatar Akke Viitanen
Browse files

add doctests

parent cfb58e17
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -363,6 +363,20 @@ def create_directory(filename: str) -> None:

    If 'filename' is a directory, then create that directory. If 'filename' is
    an ordinary file, then create the directory that would contain the file.

    Examples
    --------
    >>> import os
    >>> dirname = os.path.join("data", "tests", "test_util")
    >>> create_directory(f"{dirname}") # creates 'tests' if did not exists
    >>> create_directory(f"{dirname}/") # creates 'test_util'
    >>> create_directory(f"{dirname}/foo") # creates 'dirname'
    >>> create_directory(f"{dirname}/foo/") # creates 'foo'
    >>> create_directory(f"{dirname}/bar/test.dat") # creates 'bar'
    >>> assert os.path.exists("data/tests")
    >>> assert os.path.exists("data/tests/test_util")
    >>> assert os.path.exists("data/tests/test_util/foo")
    >>> assert os.path.exists("data/tests/test_util/bar")
    """
    if not os.path.isdir(filename):
        filename = os.path.dirname(filename)