diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cba38de64..58d1cd495 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -169,4 +169,3 @@ jobs: make install pip install ".[test]" make test_spark - diff --git a/Makefile b/Makefile index 22a69c758..17249b074 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ docs: mkdocs build test: + pytest --nbtest tests/notebooks/ pytest tests/unit/ pytest tests/issues/ - pytest --nbval tests/notebooks/ ydata_profiling -h test_spark: @@ -14,9 +14,9 @@ test_spark: ydata_profiling -h test_cov: + pytest --cov=. --cov-append --nbtest tests/notebooks/ pytest --cov=. tests/unit/ pytest --cov=. --cov-append tests/issues/ - pytest --cov=. --cov-append --nbval tests/notebooks/ ydata_profiling -h examples: diff --git a/make.bat b/make.bat index 20888d6bd..cc8715ca1 100644 --- a/make.bat +++ b/make.bat @@ -12,7 +12,7 @@ IF "%1%" == "docs" ( IF "%1" == "test" ( pytest tests/unit/ pytest tests/issues/ - pytest --nbval tests/notebooks/ + pytest --nbtest tests/notebooks/ ECHO "Tests completed!" GOTO end ) diff --git a/pyproject.toml b/pyproject.toml index e1e668788..838e9abd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,7 +120,7 @@ test = [ "coverage>=6.5, <8", "codecov", "pytest-cov", - "nbval", + "nbtest-gen", "pyarrow", "twine>=3.1.1", "kaggle", @@ -150,4 +150,4 @@ ydata_profiling = ["py.typed"] universal = true [tool.setuptools.package-dir] -"" = "src" +"" = "src" \ No newline at end of file diff --git a/tests/notebooks/lazy_pipeline.ipynb b/tests/notebooks/lazy_pipeline.ipynb index 381173414..c4eff4df4 100644 --- a/tests/notebooks/lazy_pipeline.ipynb +++ b/tests/notebooks/lazy_pipeline.ipynb @@ -21,7 +21,15 @@ "\n", "# Our package\n", "from ydata_profiling import ProfileReport\n", - "from ydata_profiling.utils.cache import cache_file" + "from ydata_profiling.utils.cache import cache_file\n", + "\n", + "import nbtest\n", + "\n", + "# The tests in this notebook only run in the continuous integration pipeline\n", + "# in order to run manually uncomment the following two lines:\n", + "\n", + "# import os\n", + "# os.environ['NBTEST_RUN_ASSERTS'] = '1'" ] }, { @@ -48,10 +56,8 @@ "with capture_output() as out:\n", " profile = ProfileReport(df, title=\"Titanic Dataset\", progress_bar=True, lazy=False)\n", "\n", - "assert all(\n", - " any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs\n", - ")\n", - "assert len(out.outputs) == 2" + "nbtest.assert_true(all(any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs))\n", + "nbtest.assert_equal(len(out.outputs), 2)" ] }, { @@ -69,22 +75,20 @@ " lazy=True,\n", " )\n", "\n", - "assert len(out.outputs) == 0\n", + "nbtest.assert_equal(len(out.outputs), 0)\n", "\n", "with capture_output() as out:\n", " _ = profile.to_html()\n", "\n", "\n", - "assert all(\n", - " any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs\n", - ")\n", - "assert len(out.outputs) == 3\n", + "nbtest.assert_true(all(any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs))\n", + "nbtest.assert_equal(len(out.outputs), 3)\n", "\n", "with capture_output() as out:\n", " _ = profile.to_file(\"/tmp/tmpfile.html\")\n", "\n", - "assert \"Export report to file\" in out.outputs[0].data[\"text/plain\"]\n", - "assert len(out.outputs) == 1" + "nbtest.assert_in(\"Export report to file\", out.outputs[0].data[\"text/plain\"])\n", + "nbtest.assert_equal(len(out.outputs), 1)" ] }, { @@ -96,30 +100,30 @@ "# Test caching of the iterative building process\n", "with capture_output() as out:\n", " profile = ProfileReport(df, title=\"Titanic Dataset\", progress_bar=True, lazy=True)\n", - "assert len(out.outputs) == 0\n", + "nbtest.assert_equal(len(out.outputs), 0)\n", "\n", "with capture_output() as out:\n", " profile.description_set\n", - "assert len(out.outputs) == 1\n", + "nbtest.assert_equal(len(out.outputs), 1)\n", "\n", "with capture_output() as out:\n", " profile.report\n", - "assert len(out.outputs) == 1\n", + "nbtest.assert_equal(len(out.outputs), 1)\n", "\n", "with capture_output() as out:\n", " profile.html\n", - "assert len(out.outputs) == 1\n", + "nbtest.assert_equal(len(out.outputs), 1)\n", "\n", "with capture_output() as out:\n", " profile.config.html.style.theme = \"united\"\n", " profile.invalidate_cache(\"rendering\")\n", " profile.to_file(\"/tmp/cache1.html\")\n", - "assert len(out.outputs) == 2\n", + "nbtest.assert_equal(len(out.outputs), 2)\n", "\n", "with capture_output() as out:\n", " profile.config.pool_size = 1\n", " profile.html\n", - "assert len(out.outputs) == 0\n", + "nbtest.assert_equal(len(out.outputs), 0)\n", "\n", "with capture_output() as out:\n", " profile.config.pool_size = 0\n", @@ -127,15 +131,29 @@ " profile.config.samples.tail = 15\n", " profile.invalidate_cache()\n", " profile.to_file(\"/tmp/cache2.html\")\n", - "assert len(out.outputs) == 4" + "nbtest.assert_equal(len(out.outputs), 4)" ] } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.11" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/tests/notebooks/meteorites.ipynb b/tests/notebooks/meteorites.ipynb index 212c11def..8c2afcf66 100644 --- a/tests/notebooks/meteorites.ipynb +++ b/tests/notebooks/meteorites.ipynb @@ -22,7 +22,15 @@ "from IPython.utils.capture import capture_output\n", "\n", "import ydata_profiling\n", - "from ydata_profiling.utils.cache import cache_file" + "from ydata_profiling.utils.cache import cache_file\n", + "\n", + "import nbtest\n", + "\n", + "# The tests in this notebook only run in the continuous integration pipeline\n", + "# in order to run manually uncomment the following two lines:\n", + "\n", + "# import os\n", + "# os.environ['NBTEST_RUN_ASSERTS'] = '1'" ] }, { @@ -83,9 +91,9 @@ " )\n", " display(pr)\n", "\n", - "assert len(out.outputs) == 2\n", - "assert out.outputs[0].data[\"text/plain\"] == \"\"\n", - "assert out.outputs[1].data[\"text/plain\"] == \"\"" + "nbtest.assert_equal(len(out.outputs), 2)\n", + "nbtest.assert_equal(out.outputs[0].data[\"text/plain\"], \"\")\n", + "nbtest.assert_equal(out.outputs[1].data[\"text/plain\"], \"\")" ] }, { @@ -103,10 +111,8 @@ " lazy=False,\n", " )\n", "\n", - "assert all(\n", - " any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs\n", - ")\n", - "assert len(out.outputs) == 2" + "nbtest.assert_true(all(any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs))\n", + "nbtest.assert_equal(len(out.outputs), 2)" ] }, { @@ -119,10 +125,8 @@ "with capture_output() as out:\n", " pfr.to_file(\"/tmp/example.html\")\n", "\n", - "assert all(\n", - " any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs\n", - ")\n", - "assert len(out.outputs) == 2" + "nbtest.assert_true(all(any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs))\n", + "nbtest.assert_equal(len(out.outputs), 2)" ] }, { @@ -135,9 +139,9 @@ "with capture_output() as out:\n", " display(pfr)\n", "\n", - "assert len(out.outputs) == 2\n", - "assert out.outputs[0].data[\"text/plain\"] == \"\"\n", - "assert out.outputs[1].data[\"text/plain\"] == \"\"" + "nbtest.assert_equal(len(out.outputs), 2)\n", + "nbtest.assert_equal(out.outputs[0].data[\"text/plain\"], \"\")\n", + "nbtest.assert_equal(out.outputs[1].data[\"text/plain\"], \"\")" ] } ], @@ -157,9 +161,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.11.11" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/tests/notebooks/titanic.ipynb b/tests/notebooks/titanic.ipynb index 768759214..c0313f6c5 100644 --- a/tests/notebooks/titanic.ipynb +++ b/tests/notebooks/titanic.ipynb @@ -21,7 +21,15 @@ "from ipywidgets import widgets\n", "\n", "from ydata_profiling import ProfileReport\n", - "from ydata_profiling.utils.cache import cache_file" + "from ydata_profiling.utils.cache import cache_file\n", + "\n", + "import nbtest\n", + "\n", + "# The tests in this notebook only run in the continuous integration pipeline\n", + "# in order to run manually uncomment the following two lines:\n", + "\n", + "# import os\n", + "# os.environ['NBTEST_RUN_ASSERTS'] = '1'" ] }, { @@ -54,10 +62,9 @@ " lazy=False,\n", " )\n", "\n", - "assert all(\n", - " any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs\n", - ")\n", - "assert len(out.outputs) == 2" + "nbtest.assert_true(all(any(v in s.data[\"text/plain\"] for v in [\"%|\", \"FloatProgress\"]) for s in out.outputs))\n", + "\n", + "nbtest.assert_equal(len(out.outputs), 2)" ] }, { @@ -76,7 +83,7 @@ " lazy=False,\n", " )\n", "\n", - "assert len(out.outputs) == 0" + "nbtest.assert_equal(len(out.outputs), 0)" ] }, { @@ -87,14 +94,14 @@ "source": [ "# Waiting on issue: https://github.com/computationalmodelling/nbval/issues/136\n", "\n", - "# The Notebook Widgets Interface\n", + "# The Notebook Widgets Interface - faced execution error here, hence, the tests below have been commented\n", "# with capture_output() as out:\n", "# profile.to_widgets()\n", "\n", - "# assert len(out.outputs) == 2\n", - "# assert out.outputs[0].data['text/plain'].startswith('Tab(children=(HTML(value=')\n", - "# assert out.outputs[1].data['text/plain'] == ''\n", - "# assert 'ydata-profiling' in out.outputs[1].data['text/html']" + "# nbtest.assert_equal(len(out.outputs), 2)\n", + "# nbtest.assert_true(out.outputs[0].data['text/plain'].startswith('Tab(children=(HTML(value='))\n", + "# nbtest.assert_equal(out.outputs[1].data['text/plain'], '')\n", + "# nbtest.assert_in('ydata-profiling', out.outputs[1].data['text/html'])" ] }, { @@ -107,14 +114,14 @@ "with capture_output() as out:\n", " profile.to_notebook_iframe()\n", "\n", - "assert len(out.outputs) == 1\n", - "assert out.outputs[0].data[\"text/plain\"] == \"\"" + "nbtest.assert_equal(len(out.outputs), 1)\n", + "nbtest.assert_equal(out.outputs[0].data[\"text/plain\"], \"\")" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -128,9 +135,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.11.11" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }