From 268e3b6a47ecbce489552ca4134b5d57eea72194 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Mon, 31 Oct 2022 23:49:37 -0300 Subject: [PATCH] Add journal --- journal/_src/posts/2022-10-31-lab-14.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/journal/_src/posts/2022-10-31-lab-14.md b/journal/_src/posts/2022-10-31-lab-14.md index d31f313..7677a36 100644 --- a/journal/_src/posts/2022-10-31-lab-14.md +++ b/journal/_src/posts/2022-10-31-lab-14.md @@ -1,9 +1,21 @@ Title: Lab Fourteen Date: 2022-10-31T08:30:00 - Tags: cs2613, lab, python + Tags: cs2613, lab, python, pytest, exceptions, modules -Sample description +In this lab I learned about python, pytest, python exceptions and modules. -## Sample Body -Sample Body \ No newline at end of file +## Pytest +Pytest is a python testing framework. It can show you code coverage with line counts. This is pretty similar to `nyc` from javascript. You run tests by just running `pytest` or `pytest -cov` for code coverage. Tests are defined by in a file having a function with an assert statement. Pytest will then scan your files for assert statements and run those functions to run tests. Testing in python is pretty simple, like with javascript. Racket testing is a little more abstract and confusing in my opinion. + +## Modules +In python functions are exported by default, in contrast to javascript. You must guard your main method with the `if __name__ =='__main__'` text so it does not run when the module is imported. You can make tests to ensure you have documentation for your functions, by checking for the imports `__doc__` variable. + +## Indentation +In python, blocks are defined by indentation (also known as whitespace). This sets the scope for a given statement. It can be a little confusing to tell if an if statement is in a for loop or not, but linters help. + +## Exceptions +Python can raise errors when things go wrong, for example diving by zero. You can catch these exceptions and handle them if you desire. + +## FizzBuzz missing case +You can fix the missing case just by adding another if statement above the other if statement for the fizz case. \ No newline at end of file