{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Deathbeds tests\n", "\n", "Update the local `tricks.yml` to run this.\n", "```bash\n", "ipython -m deathbeds.2018-07-02-Watch-Testing -- --commands \"'ipython -m tests'\"\n", "\n", "```" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "import deathbeds\n", "from pathlib import Path\n", "from IPython.utils.capture import capture_output\n", "from IPython import get_ipython\n", "import os, sys" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C:\\\\Users\\\\deathbeds\\\\deathbeds.github.io\\\\deathbeds'" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pattern = '''[0-9]*.ipynb'''\n", "root = Path(deathbeds.__file__).parent\n", "cwd = os.getcwd()" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(str)>" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "md_list = lambda str: __import__('IPython').display.Markdown(''.join(f\"\"\"* [{str}]({str}) \"\"\" for str in str.splitlines()))" ] }, { "cell_type": "code", "execution_count": 135, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2018-07-20-Literate-Markdown-Kernel.ipynb\\n2018-07-06-Revisiting-cadquery-and-ipywidgets-part-1.ipynb\\n2018-07-17-Extracting-a-blog-roll-for-deathbeds.ipynb\\n2018-07-13-Supercharged-imarkdown-as-code.md.ipynb\\n'" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "skip = \"\"\"2018-07-20-Literate-Markdown-Kernel.ipynb\n", "2018-07-06-Revisiting-cadquery-and-ipywidgets-part-1.ipynb\n", "2018-07-17-Extracting-a-blog-roll-for-deathbeds.ipynb\n", "2018-07-13-Supercharged-imarkdown-as-code.md.ipynb\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 136, "metadata": {}, "outputs": [], "source": [ "from deathbeds import __Markdown_code_cells" ] }, { "cell_type": "code", "execution_count": 137, "metadata": {}, "outputs": [], "source": [ "with __Markdown_code_cells.MarkdownImporter(): __import__('deathbeds.2018-07-13-Supercharged-imarkdown-as-code')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load the testable files from the git tracker." ] }, { "cell_type": "code", "execution_count": 148, "metadata": {}, "outputs": [], "source": [ "os.chdir(root)\n", "notebooks = '\\n'.join(object for object in __import__('delegator').run('git ls-files [0-9]*.ipynb').out.splitlines() if object not in skip)\n", "os.chdir(cwd)" ] }, { "cell_type": "code", "execution_count": 149, "metadata": {}, "outputs": [], "source": [ "try: import cv2 \n", "except: notebooks = notebooks.replace(\"\"\"2018-06-20-OpenCV-and-a-Widget.ipynb\\n\"\"\", \"\")\n", "\"\"\"pwd doesn't work on windows.\"\"\"\n", "try: import luigi \n", "except: notebooks = notebooks.replace(\"\"\"2018-07-03-Luigi-command-line.ipynb\\n\"\"\", \"\")" ] }, { "cell_type": "code", "execution_count": 150, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['-c', '../tox.ini', '--doctest-modules', '--mpl', '--verbose']" ] }, "execution_count": 150, "metadata": {}, "output_type": "execute_result" } ], "source": [ "opts = \"-c ../tox.ini --doctest-modules --mpl --verbose\".split()" ] }, { "cell_type": "code", "execution_count": 151, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "kernel-26eb5ae1-baa1-4d15-9026-df8c9b46cfd8.json False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "usage: ipykernel_launcher.py [options] [file_or_dir] [file_or_dir] [...]\n", "ipykernel_launcher.py: error: unrecognized arguments: --mpl\n", " inifile: ../tox.ini\n", " rootdir: C:\\Users\\deathbeds\\deathbeds.github.io\\deathbeds\n" ] }, { "ename": "SystemExit", "evalue": "2", "output_type": "error", "traceback": [ "An exception has occurred, use %tb to see the full traceback.\n", "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 2\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2971: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n", " warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n" ] } ], "source": [ "if __name__ == '__main__':\n", " print(Path(sys.argv[-1]).name, Path(sys.argv[-1]).name in notebooks.splitlines())\n", " if (Path(sys.argv[-1]).name in notebooks.splitlines()):\n", " opts += sys.argv[1:-1] + [Path(sys.argv[-1]).name]\n", " elif __name__ == '__main__':\n", " opts += notebooks.splitlines() \n", " try:\n", " os.chdir(str(root))\n", " with capture_output(False, False): raise SystemExit(\n", " __import__('pytest').main(\n", " opts, [__Markdown_code_cells]))\n", " finally: os.chdir(cwd)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }