diff --git a/README.md b/README.md index 20ab22828..3e8150f03 100644 --- a/README.md +++ b/README.md @@ -142,4 +142,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..5598f87dc --- /dev/null +++ b/checklist.md @@ -0,0 +1,80 @@ +# Check Your Code Against the Following Points + +## Code Style + +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: + +```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 +``` + +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 +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 +``` + +2. Use descriptive and correct variable names. + +Good example: + +```python +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) -> str: + return f"{x} {y}" +``` + +## Clean Code + +1. You can avoid else when have return statement. + +Good example: + +```python +def is_adult(age: int) -> str: + if age >= 18: + return "adult" + return "not an adult" +``` + +Bad example: + +```python +def is_adult(age: int) -> str: + 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..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", @@ -101,3 +109,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"