{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Functional Test Documentation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Generates documentation for fastai's functional tests" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.gen_doc.nbdoc import *\n", "from fastai.gen_doc.nbtest import * " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find tests for any function/class" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[`show_test`](/gen_doc.nbtest.html#show_test) and [`doctest`](/gen_doc.nbtest.html#doctest) searches for any implemented tests for a given fastai class or function \n", "\n", "For test writers: \n", "* Use this module to search for tests and get a better idea on which parts of the fastai api need more functional tests\n", "\n", "For fastai users: \n", "* Usage is similar to [`nbdoc.show_doc`](/gen_doc.nbdoc.html#show_doc) and [`nbdoc.doc`](/gen_doc.nbdoc.html#doc). \n", "* It's here to help you find associated tests for a given function can help understand usage. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Usage:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

show_test[source][test]

\n", "\n", "> show_test(**`elt`**) → `str`\n", "\n", "
×

No tests found for show_test. To contribute a test please refer to this guide and this discussion.

\n", "\n", "Show associated tests for a fastai function/class " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(show_test)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Show tests from function**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "Tests found for `fit`: \n", "\n", "\n", "* `pytest -sv tests/test_train.py::test_fit` [source]\n", "\n", "Some other tests where `fit` is used:\n", "* `pytest -sv tests/test_basic_train.py::test_destroy` [source]\n", "\n", "To run tests please refer to this [guide](/dev/test.html#quick-guide)." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from fastai.basic_train import Learner\n", "show_test(Learner.fit)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Show tests from a Class**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "Tests found for `DataBunch`: \n", "\n", "\n", "* `pytest -sv tests/test_data_block.py::test_custom_dataset` [source]\n", "\n", "Some other tests where `DataBunch` is used:\n", "* `pytest -sv tests/test_basic_data.py::test_DataBunch_Create` [source]\n", "* `pytest -sv tests/test_basic_data.py::test_DataBunch_no_valid_dl` [source]\n", "* `pytest -sv tests/test_basic_data.py::test_DataBunch_save_load` [source]\n", "\n", "To run tests please refer to this [guide](/dev/test.html#quick-guide)." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from fastai.basic_data import DataBunch\n", "show_test(DataBunch)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "Tests found for `TextList`: \n", "\n", "Some other tests where `TextList` is used:\n", "* `pytest -sv tests/test_text_data.py::test_filter_classes` [source]\n", "* `pytest -sv tests/test_text_data.py::test_from_folder` [source]\n", "* `pytest -sv tests/test_text_data.py::test_regression` [source]\n", "\n", "To run tests please refer to this [guide](/dev/test.html#quick-guide)." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from fastai.text.data import TextList\n", "show_test(TextList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Different test types" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Above, you will see 2 different test types: `Tests found for...` and `Some other tests...`\n", "\n", "* `Tests found for...` - Searches for function matches in `test_registry.json`. This json file is populated from `doctest.this_tests` calls.\n", "* `Some other tests...` - Returns any test function where the fastai function in called inside the body" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show in notebook inline:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

doctest[source][test]

\n", "\n", "> doctest(**`elt`**)\n", "\n", "
×

Tests found for doctest:

Some other tests where doctest is used:

  • pytest -sv tests/test_gen_doc_nbtest.py::test_this_tests [source]

To run tests please refer to this guide.

\n", "\n", "Inline notebook popup for [`show_test`](/gen_doc.nbtest.html#show_test) " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(doctest)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Internal search methods" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

lookup_db[source][test]

\n", "\n", "> lookup_db(**`elt`**) → `List`\\[`Dict`\\[`KT`, `VT`\\]\\]\n", "\n", "
×

No tests found for lookup_db. To contribute a test please refer to this guide and this discussion.

\n", "\n", "Finds `this_test` entries from test_registry.json " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(lookup_db)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "\n", "\n", "> find_related_tests(**`elt`**) → `Tuple`\\[`List`\\[`Dict`\\[`KT`, `VT`\\]\\], `List`\\[`Dict`\\[`KT`, `VT`\\]\\]\\]\n", "\n", "\n", "\n", "Searches `fastai/tests` folder for any test functions related to `elt` " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(find_related_tests)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

find_test_matches[source][test]

\n", "\n", "> find_test_matches(**`elt`**, **`test_file`**:`Path`) → `Tuple`\\[`List`\\[`Dict`\\[`KT`, `VT`\\]\\], `List`\\[`Dict`\\[`KT`, `VT`\\]\\]\\]\n", "\n", "
×

No tests found for find_test_matches. To contribute a test please refer to this guide and this discussion.

\n", "\n", "Find all functions in `test_file` related to `elt` " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(find_test_matches)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

find_test_files[source][test]

\n", "\n", "> find_test_files(**`elt`**, **`exact_match`**:`bool`=***`False`***) → `List`\\[`Path`\\]\n", "\n", "
×

No tests found for find_test_files. To contribute a test please refer to this guide and this discussion.

\n", "\n", "Searches in `fastai/tests` directory for module tests " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(find_test_files)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "

fuzzy_test_match[source][test]

\n", "\n", "> fuzzy_test_match(**`fn_name`**:`str`, **`lines`**:`List`\\[`Dict`\\[`KT`, `VT`\\]\\], **`rel_path`**:`str`) → `List`\\[[`TestFunctionMatch`](/gen_doc.nbtest.html#TestFunctionMatch)\\]\n", "\n", "
×

Tests found for fuzzy_test_match:

  • pytest -sv tests/test_gen_doc_nbtest.py::test_fuzzy_test_match [source]

To run tests please refer to this guide.

\n", "\n", "Find any lines where `fn_name` is invoked and return the parent test function " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show_doc(fuzzy_test_match)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Undocumented Methods - Methods moved below this line will intentionally be hidden" ] } ], "metadata": { "jekyll": { "keywords": "fastai", "summary": "Helper functions to search for api tests", "title": "gen_doc.nbtest" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }