From 06d531d94e3457e5ff5b43b6a71e3ade0933bd42 Mon Sep 17 00:00:00 2001 From: Dmytro Svirsa <104418771+DmytroSvirsa@users.noreply.github.com> Date: Tue, 6 Sep 2022 12:23:53 +0300 Subject: [PATCH 1/2] checklist and test for coment added --- README.md | 4 ++- checklist.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test_main.py | 14 ++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 checklist.md diff --git a/README.md b/README.md index b4339dcf1..fe2aa2f2e 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,6 @@ ws.rate_service(5) ws.count_of_ratings == 12 ws.average_rating == 4.0 -``` \ No newline at end of file +``` + +### Note: Check your code using this [checklist](checklist.md) before pushing your solution. diff --git a/checklist.md b/checklist.md new file mode 100644 index 000000000..f66d77fee --- /dev/null +++ b/checklist.md @@ -0,0 +1,69 @@ +# Check Your Code Against the Following Points + +## Code Style + +1. If you have some long math, you can split it onto additional variables. + +Good example: + +```python +fuel_consumption = max_fuel_consumption * height_fuel_consumption_coeficient +estimated_speed = plan_max_speed - wind_awerage_speed * wind_angle_coefisient +estimated_time = distance_to_the_destinatoin / estimated_speed +how_much_fuel_needed = fuel_consumption * estimated_time * overlap_coeficient +``` + +Bad example: + +```python +how_much_fuel_needed = max_fuel_consumption \ + * height_fuel_consumption_coeficient \ + * distance_to_the_destinatoin / ( + plan_max_speed + - wind_awerage_speed + * wind_angle_coefisient + ) * overlap_coeficient +``` + +## Code Efficiency + +2. Use descriptive and correct variable names. + +Good example: + +```python +def get_full_name(first_name: str, last_name: str): + return f"{first_name} {last_name}" +``` + +Bad example: +```python +def get_full_name(x: str, y: str): + return f"{x} {y}" +``` + +## Clean Code + +1. You can avoid else when have return statement. + +Good example: + +```python +def is_adult(age): + if age >= 18: + return "adult" + return "not an adult" +``` + +Bad example: + +```python +def is_adult(age): + if age >= 18: + return "adult" + else: + return "not an adult" +``` + +2. Add comments, prints, and functions to check your solution when you write your code. +Don't forget to delete them when you are ready to commit and push your code. diff --git a/tests/test_main.py b/tests/test_main.py index 9e8b54785..158af067a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -101,3 +101,17 @@ def test_rate_service( f"'count_of_ratings' should equal to {result_num_ratings}, " f"when initial 'count_of_ratings' was {init_num_ratings}" ) + + +def test_unnecessary_comment(): + if os.path.exists(os.path.join(os.pardir, "app", "main.py")): + main_path = os.path.join(os.pardir, "app", "main.py") + else: + main_path = os.path.join("app", "main.py") + + with open(main_path, "r") as main: + main_content = main.read() + + assert ( + "# write your code here" not in main_content + ), "Remove unnecessary comment" From a07cd98360e56004c269d1e28d9cb04b230f14cf Mon Sep 17 00:00:00 2001 From: Dmytro Svirsa <104418771+DmytroSvirsa@users.noreply.github.com> Date: Mon, 19 Sep 2022 11:03:45 +0300 Subject: [PATCH 2/2] test added --- checklist.md | 25 ++++++++++++++++++------- tests/test_main.py | 8 ++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/checklist.md b/checklist.md index f66d77fee..5598f87dc 100644 --- a/checklist.md +++ b/checklist.md @@ -2,7 +2,8 @@ ## Code Style -1. If you have some long math, you can split it onto additional variables. +1. If you have some long math, you can split it onto additional variables, +or break after binary operations (not before - it cause the W504 errors) Good example: @@ -13,6 +14,18 @@ estimated_time = distance_to_the_destinatoin / estimated_speed how_much_fuel_needed = fuel_consumption * estimated_time * overlap_coeficient ``` +Good example: + +```python +how_much_fuel_needed = (max_fuel_consumption + * height_fuel_consumption_coeficient + * distance_to_the_destinatoin + / (plan_max_speed + - wind_awerage_speed + * wind_angle_coefisient) + * overlap_coeficient) +``` + Bad example: ```python @@ -25,20 +38,18 @@ how_much_fuel_needed = max_fuel_consumption \ ) * overlap_coeficient ``` -## Code Efficiency - 2. Use descriptive and correct variable names. Good example: ```python -def get_full_name(first_name: str, last_name: str): +def get_full_name(first_name: str, last_name: str) -> str: return f"{first_name} {last_name}" ``` Bad example: ```python -def get_full_name(x: str, y: str): +def get_full_name(x: str, y: str) -> str: return f"{x} {y}" ``` @@ -49,7 +60,7 @@ def get_full_name(x: str, y: str): Good example: ```python -def is_adult(age): +def is_adult(age: int) -> str: if age >= 18: return "adult" return "not an adult" @@ -58,7 +69,7 @@ def is_adult(age): Bad example: ```python -def is_adult(age): +def is_adult(age: int) -> str: if age >= 18: return "adult" else: diff --git a/tests/test_main.py b/tests/test_main.py index 158af067a..7928f9ae5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import pytest from app.main import Car, CarWashStation @@ -37,6 +39,12 @@ def test_car_wash_station(cars, wash_station, total_cost): income = wash_station.serve_cars(cars) assert income == total_cost, f"Income should equal to {total_cost}" +def test_wash_single_car_is_called(): + with patch.object(CarWashStation, 'wash_single_car') as mock_method: + CarWashStation(3, 9, 4, 11).serve_cars([Car(2, 1, "Ford")]) + assert mock_method.called, "Expected 'wash_single_car' to have " \ + "been called inside 'serve_cars' method" + @pytest.mark.parametrize( "cars,wash_station,cars_clean_marks",