diff --git a/source/Showcase/pytest_integration.ipynb b/source/Showcase/pytest_integration.ipynb deleted file mode 100644 index 7f16f7124bb0a4080d309295d226573f8f0c64ba..0000000000000000000000000000000000000000 --- a/source/Showcase/pytest_integration.ipynb +++ /dev/null @@ -1,441 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "ed5cb36f-5137-49b4-9b3f-e46ed0214d8a", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-3c5e5a652846d1fc", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - } - }, - "source": [ - "# Pytest Integration" - ] - }, - { - "cell_type": "markdown", - "id": "1f18a76f-5acb-42fd-9062-2c86dd3f2e03", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-cf30a47e414eea72", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "source": [ - "## Example: Divisibility" - ] - }, - { - "cell_type": "markdown", - "id": "1098fa0f-433d-440d-b3bd-8c56c9d75836", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-2030eeeb2e1edddb", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "source": [ - "You get a `lower_bound` and an `upper_bound` of an interval, as well as a `divisor`.\n", - "\n", - "How many numbers in the interval are divisible by `divisor`? Write your solution to `number_of_divisibles`!" - ] - }, - { - "cell_type": "markdown", - "id": "3947c769-e153-48e5-8f6d-d55ec8ab5098", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-60c6e103f5cc30e0", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - } - }, - "source": [ - "Here is an example. Note that your code needs to work with different numbers as well!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e5474f20-00d2-4ed0-b550-c8688d4f820b", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-481d8be3c93bd0c1", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "outputs": [], - "source": [ - "lower_bound, upper_bound, divisor = 4, 19, 7\n", - "number_of_divisibles = 2" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "eadc399b-0fbc-42df-820e-a3adb557ca9c", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-908b013e61f39e10", - "locked": false, - "schema_version": 3, - "solution": true, - "task": false - }, - "tags": [] - }, - "outputs": [], - "source": [ - "### BEGIN SOLUTION\n", - "\n", - "number_of_divisibles = 0\n", - "for value in range(lower_bound, upper_bound):\n", - " if value % divisor == 0:\n", - " number_of_divisibles += 1\n", - "\n", - "### END SOLUTION" - ] - }, - { - "cell_type": "markdown", - "id": "98d0695a-033d-4a81-bb3e-6933b283d345", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-9523bb4ec1d42c10", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "source": [ - "### Submit to Pytest" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c8f51814-d7d3-488e-a54c-e920c9c2231f", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-384802b57e9616a3", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "outputs": [], - "source": [ - "import pytest\n", - "from pytest_nbgrader import loader\n", - "import pathlib\n", - "\n", - "loader.Submission.submit(_i)" - ] - }, - { - "cell_type": "markdown", - "id": "4c1ec8d5-b1ac-446d-aad0-add9e12f8096", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-eb7bffe7c6564fa9", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "source": [ - "### Run test cases" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "49fe1fa4-c73d-4d05-a208-21164756d32f", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-e85ea73c515a5d14", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "outputs": [], - "source": [ - "test_cases = pathlib.Path('tests') / 'number_divisible.yml'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1080730e-c653-4f11-84fd-3625685f333c", - "metadata": { - "nbgrader": { - "grade": true, - "grade_id": "cell-334d60287cfb1bb2", - "locked": true, - "points": 0, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "outputs": [], - "source": [ - "assert pytest.main(['-x', '--cases', test_cases]) is pytest.ExitCode.OK" - ] - }, - { - "cell_type": "markdown", - "id": "93200728-9e8e-462f-98fb-a8fdcf134465", - "metadata": { - "nbgrader": { - "grade": false, - "grade_id": "cell-5e3d1be042a72d86", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - }, - "tags": [] - }, - "source": [ - "### Run Pytest File" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "559d321a-f829-4c9e-ad38-dae66259a9de", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "aiofiles @ file:///home/conda/feedstock_root/build_artifacts/aiofiles_1664378549280/work\n", - "aiosqlite @ file:///home/conda/feedstock_root/build_artifacts/aiosqlite_1682491975081/work\n", - "alembic==1.12.0\n", - "anyio==3.7.1\n", - "argon2-cffi @ file:///home/conda/feedstock_root/build_artifacts/argon2-cffi_1692818318753/work\n", - "argon2-cffi-bindings @ file:///home/conda/feedstock_root/build_artifacts/argon2-cffi-bindings_1666850842190/work\n", - "arrow @ file:///home/conda/feedstock_root/build_artifacts/arrow_1662382474514/work\n", - "asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1694046349000/work\n", - "attrs @ file:///home/conda/feedstock_root/build_artifacts/attrs_1683424013410/work\n", - "Babel @ file:///home/conda/feedstock_root/build_artifacts/babel_1677767029043/work\n", - "backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work\n", - "backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1687772187254/work\n", - "beautifulsoup4 @ file:///home/conda/feedstock_root/build_artifacts/beautifulsoup4_1680888073205/work\n", - "bleach @ file:///home/conda/feedstock_root/build_artifacts/bleach_1674535352125/work\n", - "Brotli @ file:///home/conda/feedstock_root/build_artifacts/brotli-split_1693583441880/work\n", - "cached-property @ file:///home/conda/feedstock_root/build_artifacts/cached_property_1615209429212/work\n", - "certifi==2023.7.22\n", - "cffi @ file:///home/conda/feedstock_root/build_artifacts/cffi_1671179355965/work\n", - "charset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1688813409104/work\n", - "click @ file:///home/conda/feedstock_root/build_artifacts/click_1692311806742/work\n", - "colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1666700638685/work\n", - "comm @ file:///home/conda/feedstock_root/build_artifacts/comm_1691044910542/work\n", - "contourpy @ file:///home/conda/feedstock_root/build_artifacts/contourpy_1686733806710/work\n", - "cycler @ file:///home/conda/feedstock_root/build_artifacts/cycler_1635519461629/work\n", - "debugpy @ file:///home/conda/feedstock_root/build_artifacts/debugpy_1694569164216/work\n", - "decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work\n", - "defusedxml @ file:///home/conda/feedstock_root/build_artifacts/defusedxml_1615232257335/work\n", - "entrypoints @ file:///home/conda/feedstock_root/build_artifacts/entrypoints_1643888246732/work\n", - "exceptiongroup @ file:///home/conda/feedstock_root/build_artifacts/exceptiongroup_1692026125334/work\n", - "executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1667317341051/work\n", - "fastjsonschema @ file:///home/conda/feedstock_root/build_artifacts/python-fastjsonschema_1690055433477/work/dist\n", - "fonttools @ file:///home/conda/feedstock_root/build_artifacts/fonttools_1692542607195/work\n", - "fqdn @ file:///home/conda/feedstock_root/build_artifacts/fqdn_1638810296540/work/dist\n", - "greenlet==2.0.2\n", - "hypothesis @ file:///home/conda/feedstock_root/build_artifacts/hypothesis_1694394297869/work\n", - "idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1663625384323/work\n", - "importlib-metadata @ file:///home/conda/feedstock_root/build_artifacts/importlib-metadata_1688754491823/work\n", - "importlib-resources @ file:///home/conda/feedstock_root/build_artifacts/importlib_resources_1691408075105/work\n", - "iniconfig @ file:///home/conda/feedstock_root/build_artifacts/iniconfig_1673103042956/work\n", - "ipykernel @ file:///home/conda/feedstock_root/build_artifacts/ipykernel_1693880262622/work\n", - "ipython @ file:///home/conda/feedstock_root/build_artifacts/ipython_1693579759651/work\n", - "ipython-genutils==0.2.0\n", - "ipywidgets @ file:///home/conda/feedstock_root/build_artifacts/ipywidgets_1694607144474/work\n", - "isoduration @ file:///home/conda/feedstock_root/build_artifacts/isoduration_1638811571363/work/dist\n", - "jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1690896916983/work\n", - "Jinja2 @ file:///home/conda/feedstock_root/build_artifacts/jinja2_1654302431367/work\n", - "json5 @ file:///home/conda/feedstock_root/build_artifacts/json5_1688248289187/work\n", - "jsonpointer @ file:///home/conda/feedstock_root/build_artifacts/jsonpointer_1694629064854/work\n", - "jsonschema @ file:///home/conda/feedstock_root/build_artifacts/jsonschema-meta_1691761378595/work\n", - "jsonschema-specifications @ file:///home/conda/feedstock_root/build_artifacts/jsonschema-specifications_1689701150890/work\n", - "jupyter @ file:///home/conda/feedstock_root/build_artifacts/jupyter_1670249594847/work\n", - "jupyter-console @ file:///home/conda/feedstock_root/build_artifacts/jupyter_console_1678118109161/work\n", - "jupyter-events @ file:///home/conda/feedstock_root/build_artifacts/jupyter_events_1691505939576/work\n", - "jupyter-server==1.24.0\n", - "jupyter-ydoc @ file:///home/conda/feedstock_root/build_artifacts/jupyter_ydoc_1685535850115/work/dist\n", - "jupyter_client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1673615989977/work\n", - "jupyter_core @ file:///home/conda/feedstock_root/build_artifacts/jupyter_core_1686775603054/work\n", - "jupyter_server_fileid @ file:///home/conda/feedstock_root/build_artifacts/jupyter_server_fileid_1681071667289/work\n", - "jupyter_server_terminals @ file:///home/conda/feedstock_root/build_artifacts/jupyter_server_terminals_1673491454549/work\n", - "jupyter_server_ydoc @ file:///home/conda/feedstock_root/build_artifacts/jupyter_server_ydoc_1678043727957/work\n", - "jupyterlab @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_1687805419669/work\n", - "jupyterlab-deck @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab-deck_1667437084920/work\n", - "jupyterlab-fonts @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab-fonts_1666644845625/work\n", - "jupyterlab-pygments @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_pygments_1649936611996/work\n", - "jupyterlab-widgets @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_widgets_1694598704522/work\n", - "jupyterlab_server @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_server-split_1694531968623/work\n", - "JupyterQuiz==2.6.3\n", - "kiwisolver @ file:///home/conda/feedstock_root/build_artifacts/kiwisolver_1692883585750/work\n", - "Mako==1.2.4\n", - "MarkupSafe @ file:///home/conda/feedstock_root/build_artifacts/markupsafe_1685769042879/work\n", - "matplotlib @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-suite_1688684873414/work\n", - "matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1660814786464/work\n", - "mistune @ file:///home/conda/feedstock_root/build_artifacts/mistune_1692116650819/work\n", - "munkres==1.1.4\n", - "nbclassic @ file:///home/conda/feedstock_root/build_artifacts/nbclassic_1683202081046/work\n", - "nbclient @ file:///home/conda/feedstock_root/build_artifacts/nbclient_1684790896106/work\n", - "nbconvert @ file:///home/conda/feedstock_root/build_artifacts/nbconvert-meta_1693331710275/work\n", - "nbformat @ file:///home/conda/feedstock_root/build_artifacts/nbformat_1690814868471/work\n", - "nbgrader==0.8.5\n", - "nbgrader-jupyterquiz==0.0.9\n", - "nest-asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1664684991461/work\n", - "notebook @ file:///home/conda/feedstock_root/build_artifacts/notebook_1691436218243/work\n", - "notebook_shim @ file:///home/conda/feedstock_root/build_artifacts/notebook-shim_1682360583588/work\n", - "numpy @ file:///home/conda/feedstock_root/build_artifacts/numpy_1691056235090/work\n", - "overrides @ file:///home/conda/feedstock_root/build_artifacts/overrides_1691338815398/work\n", - "packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1681337016113/work\n", - "pandas @ file:///home/conda/feedstock_root/build_artifacts/pandas_1693415143648/work\n", - "pandocfilters @ file:///home/conda/feedstock_root/build_artifacts/pandocfilters_1631603243851/work\n", - "parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1638334955874/work\n", - "pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1667297516076/work\n", - "pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work\n", - "Pillow @ file:///home/conda/feedstock_root/build_artifacts/pillow_1688255851102/work\n", - "pkgutil_resolve_name @ file:///home/conda/feedstock_root/build_artifacts/pkgutil-resolve-name_1694617248815/work\n", - "platformdirs @ file:///home/conda/feedstock_root/build_artifacts/platformdirs_1690813113769/work\n", - "pluggy @ file:///home/conda/feedstock_root/build_artifacts/pluggy_1693086607691/work\n", - "ply==3.11\n", - "prometheus-client @ file:///home/conda/feedstock_root/build_artifacts/prometheus_client_1689032443210/work\n", - "prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1688565951714/work\n", - "psutil @ file:///home/conda/feedstock_root/build_artifacts/psutil_1681775010077/work\n", - "ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1609419310487/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl\n", - "pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work\n", - "pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1636257122734/work\n", - "Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1691408637400/work\n", - "pyparsing @ file:///home/conda/feedstock_root/build_artifacts/pyparsing_1652235407899/work\n", - "PyQt5==5.15.9\n", - "PyQt5-sip==12.12.2\n", - "PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1661604839144/work\n", - "pytest @ file:///home/conda/feedstock_root/build_artifacts/pytest_1694128424395/work\n", - "Pytest-Nbgrader==0.0\n", - "python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1626286286081/work\n", - "python-json-logger @ file:///home/conda/feedstock_root/build_artifacts/python-json-logger_1677079630776/work\n", - "pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1693930252784/work\n", - "PyYAML @ file:///home/conda/feedstock_root/build_artifacts/pyyaml_1692737134679/work\n", - "pyzmq @ file:///home/conda/feedstock_root/build_artifacts/pyzmq_1666828549901/work\n", - "qtconsole @ file:///home/conda/feedstock_root/build_artifacts/qtconsole-base_1693604303222/work\n", - "QtPy @ file:///home/conda/feedstock_root/build_artifacts/qtpy_1693347765905/work\n", - "rapidfuzz==3.3.0\n", - "referencing @ file:///home/conda/feedstock_root/build_artifacts/referencing_1691337268233/work\n", - "requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1684774241324/work\n", - "rfc3339-validator @ file:///home/conda/feedstock_root/build_artifacts/rfc3339-validator_1638811747357/work\n", - "rfc3986-validator @ file:///home/conda/feedstock_root/build_artifacts/rfc3986-validator_1598024191506/work\n", - "rpds-py @ file:///home/conda/feedstock_root/build_artifacts/rpds-py_1694630936738/work\n", - "scipy @ file:///home/conda/feedstock_root/build_artifacts/scipy-split_1694606876598/work/base/dist/scipy-1.11.2-cp311-cp311-linux_x86_64.whl#sha256=a0b7957f603be694c9ce7dd897141b4da87eed874affd97e6b9e442d399d66d6\n", - "Send2Trash @ file:///home/conda/feedstock_root/build_artifacts/send2trash_1682601222253/work\n", - "sip @ file:///home/conda/feedstock_root/build_artifacts/sip_1690986065722/work\n", - "six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work\n", - "sniffio @ file:///home/conda/feedstock_root/build_artifacts/sniffio_1662051266223/work\n", - "sortedcontainers @ file:///home/conda/feedstock_root/build_artifacts/sortedcontainers_1621217038088/work\n", - "soupsieve @ file:///home/conda/feedstock_root/build_artifacts/soupsieve_1693929250441/work\n", - "SQLAlchemy==2.0.20\n", - "stack-data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1669632077133/work\n", - "terminado @ file:///home/conda/feedstock_root/build_artifacts/terminado_1670253674810/work\n", - "tinycss2 @ file:///home/conda/feedstock_root/build_artifacts/tinycss2_1666100256010/work\n", - "toml @ file:///home/conda/feedstock_root/build_artifacts/toml_1604308577558/work\n", - "tomli @ file:///home/conda/feedstock_root/build_artifacts/tomli_1644342247877/work\n", - "tornado @ file:///home/conda/feedstock_root/build_artifacts/tornado_1692311768944/work\n", - "traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1675110562325/work\n", - "typing-utils @ file:///home/conda/feedstock_root/build_artifacts/typing_utils_1622899189314/work\n", - "typing_extensions @ file:///home/conda/feedstock_root/build_artifacts/typing_extensions_1688315532570/work\n", - "tzdata @ file:///home/conda/feedstock_root/build_artifacts/python-tzdata_1680081134351/work\n", - "uri-template @ file:///home/conda/feedstock_root/build_artifacts/uri-template_1688655812972/work/dist\n", - "urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1689789803562/work\n", - "wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1673864653149/work\n", - "webcolors @ file:///home/conda/feedstock_root/build_artifacts/webcolors_1679900785843/work\n", - "webencodings @ file:///home/conda/feedstock_root/build_artifacts/webencodings_1694681268211/work\n", - "websocket-client @ file:///home/conda/feedstock_root/build_artifacts/websocket-client_1694440396544/work\n", - "widgetsnbextension @ file:///home/conda/feedstock_root/build_artifacts/widgetsnbextension_1694598693908/work\n", - "y-py @ file:///home/conda/feedstock_root/build_artifacts/y-py_1677231021422/work\n", - "ypy-websocket @ file:///home/conda/feedstock_root/build_artifacts/ypy-websocket_1670333059911/work\n", - "zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1689374466814/work\n" - ] - } - ], - "source": [ - "!pip freeze" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "641296d4-86fb-481e-91c9-ec1e62a41209", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/source/Showcase/_data_generation.ipynb b/source/Showcase_Exam/_data_generation.ipynb similarity index 96% rename from source/Showcase/_data_generation.ipynb rename to source/Showcase_Exam/_data_generation.ipynb index d53f792a3c51e1b269e05f8b517ad0b7bf3bb9c6..4e7a424e855bbe7158dc63ca6bc3243529ecb99b 100644 --- a/source/Showcase/_data_generation.ipynb +++ b/source/Showcase_Exam/_data_generation.ipynb @@ -56,7 +56,7 @@ "task_divisibility = {\n", " 'number_of_divisibles': TestSubtask(\n", " test_cases,\n", - " assertions={equal_value: (('number_of_divisibles'), {})},\n", + " assertions={equal_value: (('number_of_divisibles', ), {})},\n", " )\n", "}" ] diff --git a/source/Showcase_Exam/tests/manual.py b/source/Showcase_Exam/tests/manual.py new file mode 100644 index 0000000000000000000000000000000000000000..8521e17b458572044d3f49e4a3e4da64723a9d75 --- /dev/null +++ b/source/Showcase_Exam/tests/manual.py @@ -0,0 +1,7 @@ +"""Pytest file for divisibility code""" + +class TestDivisibility: + def test_not_too_many_lines(self, submission): + scope = {'lower_bound': -10, 'upper_bound': 5, 'divisor': 3} + exec(submission, scope) + assert scope.get('number_of_divisibles') == 5 diff --git a/source/Showcase_Exam/tests_with_pytest.ipynb b/source/Showcase_Exam/tests_with_pytest.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..caa8990dbee83536ae7b42874ad66370582ccbcd --- /dev/null +++ b/source/Showcase_Exam/tests_with_pytest.ipynb @@ -0,0 +1,278 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "ed5cb36f-5137-49b4-9b3f-e46ed0214d8a", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-3c5e5a652846d1fc", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "source": [ + "# Pytest Integration" + ] + }, + { + "cell_type": "markdown", + "id": "1f18a76f-5acb-42fd-9062-2c86dd3f2e03", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-cf30a47e414eea72", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "source": [ + "## Example: Divisibility" + ] + }, + { + "cell_type": "markdown", + "id": "1098fa0f-433d-440d-b3bd-8c56c9d75836", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-2030eeeb2e1edddb", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "source": [ + "You get a `lower_bound` and an `upper_bound` of an interval, as well as a `divisor`.\n", + "\n", + "How many numbers in the interval are divisible by `divisor`? Write your solution to `number_of_divisibles`!" + ] + }, + { + "cell_type": "markdown", + "id": "3947c769-e153-48e5-8f6d-d55ec8ab5098", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-60c6e103f5cc30e0", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + } + }, + "source": [ + "Here is an example. Note that your code needs to work with different numbers as well!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5474f20-00d2-4ed0-b550-c8688d4f820b", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-481d8be3c93bd0c1", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "lower_bound, upper_bound, divisor = 4, 19, 7\n", + "number_of_divisibles = 2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eadc399b-0fbc-42df-820e-a3adb557ca9c", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-908b013e61f39e10", + "locked": false, + "schema_version": 3, + "solution": true, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "\n", + "number_of_divisibles = 0\n", + "for value in range(lower_bound, upper_bound):\n", + " if value % divisor == 0:\n", + " number_of_divisibles += 1\n", + "\n", + "### END SOLUTION" + ] + }, + { + "cell_type": "markdown", + "id": "98d0695a-033d-4a81-bb3e-6933b283d345", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-9523bb4ec1d42c10", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "source": [ + "### Submit to Pytest" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c8f51814-d7d3-488e-a54c-e920c9c2231f", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-384802b57e9616a3", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "import pytest\n", + "from pytest_nbgrader import loader\n", + "import pathlib\n", + "\n", + "loader.Submission.submit(_i)" + ] + }, + { + "cell_type": "markdown", + "id": "4c1ec8d5-b1ac-446d-aad0-add9e12f8096", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-eb7bffe7c6564fa9", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "source": [ + "### Run test cases" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "49fe1fa4-c73d-4d05-a208-21164756d32f", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-e85ea73c515a5d14", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "test_cases = pathlib.Path('tests') / 'Divisibility' / 'number_of_divisibles.yml'\n", + "pytest_options = ['-x', '-W', 'ignore::_pytest.warning_types.PytestAssertRewriteWarning']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1080730e-c653-4f11-84fd-3625685f333c", + "metadata": { + "nbgrader": { + "grade": true, + "grade_id": "cell-334d60287cfb1bb2", + "locked": true, + "points": 0, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "outputs": [], + "source": [ + "assert pytest.main([*pytest_options, '--cases', test_cases]) is pytest.ExitCode.OK" + ] + }, + { + "cell_type": "markdown", + "id": "93200728-9e8e-462f-98fb-a8fdcf134465", + "metadata": { + "nbgrader": { + "grade": false, + "grade_id": "cell-5e3d1be042a72d86", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + }, + "tags": [] + }, + "source": [ + "### Run Pytest File" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "641296d4-86fb-481e-91c9-ec1e62a41209", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "pytest.main([*pytest_options, 'manual.py'])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/source/Showcase/jupyterquiz_integration.ipynb b/source/Showcase_Exercise/exercise_with_jupyterquiz.ipynb similarity index 100% rename from source/Showcase/jupyterquiz_integration.ipynb rename to source/Showcase_Exercise/exercise_with_jupyterquiz.ipynb diff --git a/source/Showcase/basic_features.ipynb b/source/Showcase_Homework/tests_with_nbgrader.ipynb similarity index 100% rename from source/Showcase/basic_features.ipynb rename to source/Showcase_Homework/tests_with_nbgrader.ipynb