Title: [WIP] Add doctests for tutorials
Author: stevhliu (MEMBER)
State: closed
Created: 2021-11-29T18:40:46Z

Opening a PR as discussed with @LysandreJik for some help with doctest issues. The goal is to add doctests for each of the tutorials in the documentation to make sure the code samples work as shown.

### Issues

A doctest has been added in the docstring of the `load_dataset_builder` function in `load.py` to handle variable outputs with the `ELLIPSIS` directive. When I run doctest on the `load_hub.rst` file, doctest should recognize the expected output from the docstring, and the corresponding code sample in `load_hub.rst` should pass. I am having the same issue with handling tracebacks in the `load_dataset` function.

From the docstring:
```
>>> dataset_builder.cache_dir #doctest: +ELLIPSIS
/Users/.../.cache/huggingface/datasets/imdb/plain_text/1.0.0/...
```
Test result:
```
Failed example:
    dataset_builder.cache_dir
Expected:
    /Users/.../.cache/huggingface/datasets/imdb/plain_text/1.0.0/...
Got:
    /Users/steven/.cache/huggingface/datasets/imdb/plain_text/1.0.0/2fdd8b9bcadd6e7055e742a706876ba43f19faee861df134affd7a3f60fc38a1
```

I am able to get the doctest to pass by adding the doctest directives (`ELLIPSIS` and `NORMALIZE_WHITESPACE`) to the code samples in the `rst` file directly. But my understanding is that these directives should also work in the docstrings of the functions. I am running the test from the root of the directory:

```
python -m doctest -v docs/source/load_hub.rst
```

Comments:
I manage to remove the mentions of ellipsis in the code by launching the command as follows:

```
python -m doctest -v docs/source/load_hub.rst -o=ELLIPSIS
```

The way you put your ellipsis will only work on mac, I've adapted it for linux as well with the following:

```diff
    >>> from datasets import load_dataset_builder
    >>> dataset_builder = load_dataset_builder('imdb')
-   >>> print(dataset_builder.cache_dir) #doctest: +ELLIPSIS
-   /Users/.../.cache/huggingface/datasets/imdb/plain_text/1.0.0/...
+   >>> print(dataset_builder.cache_dir)
+   /.../.cache/huggingface/datasets/imdb/plain_text/1.0.0/...
```

This passes on my machine:

```
Trying:
    print(dataset_builder.cache_dir)
Expecting:
    /.../.cache/huggingface/datasets/imdb/plain_text/1.0.0/...
ok
```

I'm getting a last error:

```py
Expected:
    DatasetDict({
        train: Dataset({
            features: ['sentence1', 'sentence2', 'label', 'idx'],
            num_rows: 3668
        })
        validation: Dataset({
            features: ['sentence1', 'sentence2', 'label', 'idx'],
            num_rows: 408
        })
        test: Dataset({
            features: ['sentence1', 'sentence2', 'label', 'idx'],
            num_rows: 1725
        })
    })
Got:
    DatasetDict({
        train: Dataset({
            features: ['idx', 'label', 'sentence1', 'sentence2'],
            num_rows: 3668
        })
        validation: Dataset({
            features: ['idx', 'label', 'sentence1', 'sentence2'],
            num_rows: 408
        })
        test: Dataset({
            features: ['idx', 'label', 'sentence1', 'sentence2'],
            num_rows: 1725
        })
    })
```

But this is due to `doctest` looking for an exact match and the list having an unordered print order. I wish `doctest` would be a bit more flexible with that.