{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using `watchdog` tricks to automatically run tests.\n", "\n", "`watchdog` contains a command line tools to define watch events using a yaml file.\n", "\n", "Use `pytest` to demonstrate the technique.\n", "\n", " !watchmedo tricks tricks.yml" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ " commands = \"\"\"pytest\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ignore some of the by products of the notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ " print(commands)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ " tricks = \"\"\"tricks:\n", " - watchdog.tricks.ShellCommandTrick:\n", " patterns:\n", " - \"*/*.ipynb\"\n", " ignore_patterns:\n", " - '*/.~*.ipynb'\n", " - '*/.ipynb_checkpoints*'\n", " shell_command: >\n", " {}\n", " \"\"\".format(commands)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write the tricks file to disk if it doesn't exist." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ " if __name__ == '__main__':\n", " from IPython import get_ipython\n", " path = __import__('pathlib').Path('tricks.yml')\n", " if not path.exists(): path.write_text(tricks) " ] } ], "metadata": { "kernelspec": { "display_name": "p6", "language": "python", "name": "other-env" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }