Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module 5 updates #109

Merged
merged 7 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 42 additions & 24 deletions module01_introduction_to_python/01_01_data_analysis_example.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions module05_testing_your_code/05_00_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"```\n",
"\n",
"* Does not test correctness of code\n",
"* Checks code is a similarly wrong on day N as day 0"
"* Checks code is as similarly wrong on day N as day 0"
]
},
{
Expand Down Expand Up @@ -174,7 +174,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.9"
}
},
"nbformat": 4,
Expand Down
32 changes: 13 additions & 19 deletions module05_testing_your_code/05_01_how_to_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -784,25 +784,12 @@
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"tags": [
"raises-exception"
]
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (3187101134.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/var/folders/q7/nl3w6z854711jwsdy0hj7sxhwypcgh/T/ipykernel_66962/3187101134.py\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m assert I_only_accept_positive_numbers(-5) == # Gives a value error\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"cell_type": "markdown",
"metadata": {},
"source": [
"assert I_only_accept_positive_numbers(-5) == # Gives a value error"
"```python\n",
"assert I_only_accept_positive_numbers(-5) == # Gives a value error\n",
"```"
]
},
{
Expand All @@ -811,6 +798,13 @@
"source": [
"But to do that, we need to learn about more sophisticated testing tools, called \"test frameworks\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -832,7 +826,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.9"
}
},
"nbformat": 4,
Expand Down
47 changes: 22 additions & 25 deletions module05_testing_your_code/05_02_testing_frameworks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,40 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"* Language agnostic: [CTest](http://www.cmake.org/cmake/help/v2.8.12/ctest.html)\n",
"* Language agnostic: [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html)\n",
" * Test runner for executables, bash scripts, etc...\n",
" * Great for legacy code hardening\n",
" \n",
"* C unit-tests:\n",
" * all c++ frameworks,\n",
" * [Check](http://check.sourceforge.net/),\n",
" * [Check](https://libcheck.github.io/check/),\n",
" * [CUnit](http://cunit.sourceforge.net)\n",
"\n",
"* C++ unit-tests:\n",
" * [CppTest](http://cpptest.sourceforge.net/),\n",
" * [Boost::Test](http://www.boost.org/doc/libs/1_55_0/libs/test/doc/html/index.html),\n",
" * [google-test](https://code.google.com/p/googletest/),\n",
" * [Catch](https://github.com/philsquared/Catch) (best)\n",
" * [Boost::Test](https://www.boost.org/doc/libs/1_79_0/libs/test/doc/html/index.html),\n",
" * [google-test](https://google.github.io/googletest/),\n",
" * [Catch](https://github.com/catchorg/Catch2)\n",
"\n",
"* Python unit-tests:\n",
" * [nose](https://nose.readthedocs.org/en/latest/) includes test discovery, coverage, etc\n",
" * [unittest](http://docs.python.org/2/library/unittest.html) comes with standard python library\n",
" * [py.test](http://pytest.org/latest/), branched off of nose\n",
" * [unittest](https://docs.python.org/3/library/unittest.html) comes with standard python library\n",
" * [pytest](http://pytest.org/latest/), includes test discovery, coverage, etc\n",
"\n",
"* R unit-tests:\n",
" * [RUnit](http://cran.r-project.org/web/packages/RUnit/index.html),\n",
" * [svUnit](http://cran.r-project.org/web/packages/svUnit/index.html)\n",
" * (works with [SciViews](http://www.sciviews.org/) GUI)\n",
" * [RUnit](https://cran.r-project.org/web/packages/RUnit/index.html),\n",
" * [testthat](https://testthat.r-lib.org/)\n",
"\n",
"* Fortran unit-tests:\n",
" * [funit](http://nasarb.rubyforge.org/funit/),\n",
" * [pfunit](http://sourceforge.net/projects/pfunit/)(works with MPI)"
" * [pfunit](https://github.com/Goddard-Fortran-Ecosystem/pFUnit)(works with MPI)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## py.test framework: usage\n",
"## pytest framework: usage\n",
"\n",
"[py.test](https://docs.pytest.org/en/latest/) is a recommended python testing framework."
"[pytest](https://docs.pytest.org/en/latest/) is a recommended python testing framework."
]
},
{
Expand Down Expand Up @@ -211,9 +208,9 @@
"output_type": "stream",
"text": [
"============================= test session starts ==============================\n",
"platform darwin -- Python 3.8.13, pytest-7.1.2, py-1.10.0, pluggy-1.0.0\n",
"rootdir:/home/turingdev/projects/research-software/rse-course/ch03tests/saskatchewan\n",
"plugins: anyio-3.3.0\n",
"platform darwin -- Python 3.9.9, pytest-7.1.2, pluggy-1.0.0\n",
"rootdir: /Users/jroberts/GitHub/rse-course/module05_testing_your_code/saskatchewan\n",
"plugins: anyio-3.6.1, cov-3.0.0\n",
"collected 3 items\n",
"\n",
"test_overlap.py ..F [100%]\n",
Expand All @@ -229,7 +226,7 @@
"test_overlap.py:13: AssertionError\n",
"=========================== short test summary info ============================\n",
"FAILED test_overlap.py::test_no_overlap - assert 0.25 == 0.0\n",
"========================= 1 failed, 2 passed in 0.11s ==========================\n",
"========================= 1 failed, 2 passed in 0.07s ==========================\n",
"Tests failed\n"
]
}
Expand All @@ -238,7 +235,7 @@
"%%bash\n",
"#%%cmd #(windows)\n",
"cd saskatchewan\n",
"py.test || echo \"Tests failed\""
"pytest || echo \"Tests failed\""
]
},
{
Expand Down Expand Up @@ -272,8 +269,8 @@
"source": [
"Some options:\n",
"\n",
"* help: `py.test --help`\n",
"* run only tests for a given feature: `py.test -k foo` # tests with 'foo' in the test name"
"* help: `pytest --help`\n",
"* run only tests for a given feature: `pytest -k foo` # tests with 'foo' in the test name"
]
},
{
Expand Down Expand Up @@ -476,13 +473,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy ships with a number of assertions (in ``numpy.testing``) to make\n",
"Numpy ships with a number of assertions (in `numpy.testing`) to make\n",
"comparison easy:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 8,
"metadata": {
"attributes": {
"classes": [
Expand Down Expand Up @@ -529,7 +526,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.9"
}
},
"nbformat": 4,
Expand Down
Loading