Skip to content

Commit

Permalink
vscode tests instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Nov 12, 2019
1 parent b916a8d commit 2a8ccb5
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 11 deletions.
71 changes: 68 additions & 3 deletions exercises/errors-and-testing/errors-and-testing-solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,9 @@
"</div>\n",
"\n",
"\n",
"Is there anything better than `assert`for testing? `assert` can be a quick way to check but doesn't tell us exactly which is the wrong number in the list returned by `even_number(5)`. Luckily, Python offers us a better option, which is a complete testing framework called [unittest](https://docs.python.org/3/library/unittest.html). \n",
"Is there anything better than `assert`for testing? `assert` can be a quick way to check but doesn't tell us exactly which is the wrong number in the list returned by `even_number(5)`. Luckily, Python offers us a better option, which is a complete testing framework called [unittest](https://docs.python.org/3/library/unittest.html). We will use unittest because it is the standard one, but if you're doing other projects you might consider using better ones like [pytest](https://docs.pytest.org/en/latest/)\n",
"\n",
"Let's give it a try. Suppose you have a file called `my-file.py` like this:"
"So let's give unittest a try. Suppose you have a file called `my-file.py` like this:"
]
},
{
Expand Down Expand Up @@ -1940,6 +1940,64 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Running unittests in Visual Studio Code\n",
"\n",
"\n",
"You can run and debug tests in Visual Studio Code, which is very handy. First, you need to set it up.\n",
"\n",
"1. Hit `Control-Shift-P` and type `Python: Configure Tests` \n",
"\n",
"![](img/vscode-1.png)\n",
"\n",
"2. Select unittest:\n",
"\n",
"![](img/vscode-2.png)\n",
"\n",
"3. Select `. root directory` (we assume tests are in the folder that you've opened):\n",
"\n",
"![](img/vscode-3.png)\n",
"\n",
"4. Select `*Python files containing the word 'test'`:\n",
"\n",
"![](img/vscode-4.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hopefully, on the currently opened test file new labels should appear above class and test methods, like in the following example. Try to click on them: \n",
"\n",
"![](img/vscode-5.png)\n",
"\n",
"In the bottom bar, you should see a recap of run tests (right side of the picture):\n",
"\n",
"![](img/vscode-6.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Troubleshooting Visual Studio Code\n",
"\n",
"- Sometimes, labels `Run Test` do not show up in code. In these cases, you might try _Right click->Run current Test File_. \n",
"\n",
"- if nothing works, when [selecting the testing framework](#Running-unittests-in-Visual-Studio-Code) , try pytest, which is also capable to discover and execute unittests.\n",
"\n",
"- if you are really out of luck with the editor, there is always the option of running tests from the console. \n",
"\n",
"<div class=\"alert alert-warning\">\n",
"\n",
"**NOTE: during the exam testing in VSCode might not work, so please be prepared to use the console**\n",
"\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -1950,10 +2008,17 @@
"\n",
"**Immutable data structures**: all data structures are (or are meant to be) immutable -> no code can ever tweak your data, so other developers just cannot (should not) be able to inadvertently change your data. \n",
"\n",
"**Simpler parralel computing**: point above is particularly inmportant in parallel computation, wheb the system can schedule thread executions differently _each_ time you run the program: this implies that when you have multiple threads it can be very very hard to reproduce a bug where a thread wrongly changes a data which is supposed to be exclusively managed by another one, as it might fail in one run and succeed in another just because the system scheduled differently the code execution ! Functional programming frameworks like [Spark](https://spark.apache.org) solve these problems very nicely.\n",
"**Simpler parallel computing**: point above is particularly inmportant in parallel computation, wheb the system can schedule thread executions differently _each_ time you run the program: this implies that when you have multiple threads it can be very very hard to reproduce a bug where a thread wrongly changes a data which is supposed to be exclusively managed by another one, as it might fail in one run and succeed in another just because the system scheduled differently the code execution ! Functional programming frameworks like [Spark](https://spark.apache.org) solve these problems very nicely.\n",
"\n",
"**Easier to reason about code**: it is much easier to reason about functions, as we can use standard equational reasoning on input/outputs as traditionally done in algebra. To understand what we're talking about, you can see these slides: [Visual functional programming](https://docs.google.com/presentation/d/1hTHty5aML9WDDTvkflvvdGDh0AfZwV_8ZEr10-rUPVA) (will talk more about it in class)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Binary file added exercises/errors-and-testing/img/vscode-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/errors-and-testing/img/vscode-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/errors-and-testing/img/vscode-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/errors-and-testing/img/vscode-4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/errors-and-testing/img/vscode-5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added exercises/errors-and-testing/img/vscode-6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions exercises/oop/oop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7f07102203c8>\n"
"<__main__.ComplexNumber object at 0x7f162c26ee48>\n"
]
}
],
Expand Down Expand Up @@ -796,7 +796,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7f07102203c8>\n"
"<__main__.ComplexNumber object at 0x7f162c26ee48>\n"
]
}
],
Expand Down Expand Up @@ -1085,7 +1085,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7f071022bd68>\n"
"<__main__.ComplexNumber object at 0x7f162c275cf8>\n"
]
}
],
Expand Down Expand Up @@ -1160,7 +1160,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<__main__.ComplexNumber object at 0x7f071023a748>\n"
"<__main__.ComplexNumber object at 0x7f162c2df5c0>\n"
]
}
],
Expand Down Expand Up @@ -1715,7 +1715,7 @@
"source": [
"## 3. MultiSet\n",
"\n",
"You are going to implement a class called `MultiSet`, where you are only given the class skeleton, and you will need to determine which Python basic datastructures like list, set, dict (or combinations thereof) is best suited to actually hold the data. \n",
"You are going to implement a class called `MultiSet`, where you are only given the class skeleton, and you will need to determine which Python basic datastructures like `list`, `set`, `dict` (or combinations thereof) is best suited to actually hold the data. \n",
"\n",
"In math a multiset (or bag) generalizes a set by allowing multiple instances of the multiset's elements. \n",
"\n",
Expand Down Expand Up @@ -1776,7 +1776,7 @@
"\n",
"Once done, running this will run only the tests in `AddGetTest` class and hopefully they will pass. \n",
"\n",
"**Notice that `exercise1` is followed by a dot and test class name `.AddGetTest` : **\n",
"**Notice that** `exercise1` **is followed by a dot and test class name** `.AddGetTest` :\n",
"\n",
"```bash\n",
"\n",
Expand Down Expand Up @@ -1823,12 +1823,12 @@
"text": [
".................\n",
"----------------------------------------------------------------------\n",
"Ran 17 tests in 0.010s\n",
"Ran 17 tests in 0.013s\n",
"\n",
"OK\n",
".......\n",
"----------------------------------------------------------------------\n",
"Ran 7 tests in 0.003s\n",
"Ran 7 tests in 0.005s\n",
"\n",
"OK\n"
]
Expand Down
24 changes: 24 additions & 0 deletions slides.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,30 @@
"* lesson: [Pandas](exercises/pandas/pandas-solution.ipynb) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Lab A.12\n",
"\n",
"Tuesday 5 November\n",
"\n",
"* Numpy NANs and infinities - redownload updated [Matrices: Numpy](https://datasciprolab.readthedocs.io/en/latest/exercises/matrices-numpy/matrices-numpy-solution.html#NaNs-and-infinities)\n",
"* [Exercises on strings from leetcode](https://datasciprolab.readthedocs.io/en/latest/exercises/strings/strings-solution.html#Further-resources)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Lab B.1\n",
"\n",
"Tuesday 12 November\n",
"\n",
"* [Testing with unittest](exercises/errors-and-testing/errors-and-testing-solution.ipynb#Testing-with-Unittest)\n",
"* [OOP](exercises/oop/oop.ipynb) (first part)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 2a8ccb5

Please sign in to comment.