mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-13 20:56:54 +01:00
FIX: Make 02 flake8 complient
This commit is contained in:
@@ -15,6 +15,7 @@ def check_temperature(temp_str: str) -> int | None:
|
||||
print("Error: " + temp_str + "°C", ex)
|
||||
return (None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== Garden Temperature checker ===")
|
||||
print("\nTesting temperature: 25")
|
||||
|
||||
@@ -8,7 +8,7 @@ class GardenError(Exception):
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"Caught a garden error: {self.message}"
|
||||
return f"Caught a garden error: {self.message}"
|
||||
|
||||
|
||||
class PlantError(GardenError):
|
||||
@@ -17,7 +17,7 @@ class PlantError(GardenError):
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"Caught PlantError: {self.message}"
|
||||
return f"Caught PlantError: {self.message}"
|
||||
|
||||
|
||||
class WaterError(GardenError):
|
||||
@@ -26,7 +26,7 @@ class WaterError(GardenError):
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"Caught WaterError: {self.message}"
|
||||
return f"Caught WaterError: {self.message}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
def water_plants(plant_list: list[str | None]) -> None:
|
||||
"""Display watering plant if plant is a string"""
|
||||
for plant in plant_list:
|
||||
if plant == None:
|
||||
if not plant:
|
||||
raise ValueError
|
||||
print("Watering", plant)
|
||||
|
||||
@@ -14,7 +14,7 @@ def test_watering_system() -> None:
|
||||
try:
|
||||
print("Opening watering system")
|
||||
water_plants(plants)
|
||||
except:
|
||||
except ValueError:
|
||||
print("Error: Cannot water None - invalid plant!")
|
||||
finally:
|
||||
print("Closing watering system (cleanup)")
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
def check_plant_health(plant_name: str, water_level: int, sunlight_hours: int) -> None:
|
||||
def check_plant_health(plant_name: str, water_level: int,
|
||||
sunlight_hours: int) -> None:
|
||||
if not plant_name or not plant_name[0]:
|
||||
raise ValueError("Error: Plant name cannot be empty")
|
||||
elif water_level < 1:
|
||||
raise ValueError(f"Error: Water level {water_level} is too low (min 1)")
|
||||
raise ValueError(f"Error: Water level {water_level}\
|
||||
is too low (min 1)")
|
||||
elif water_level > 10:
|
||||
raise ValueError(f"Error: Water level {water_level} is too high (max 10)")
|
||||
raise ValueError(f"Error: Water level {water_level}\
|
||||
is too high (max 10)")
|
||||
elif sunlight_hours < 2:
|
||||
raise ValueError(f"Error: Sunlight hours {sunlight_hours} is too low (min 2)")
|
||||
raise ValueError(f"Error: Sunlight hours {sunlight_hours}\
|
||||
is too low (min 2)")
|
||||
elif sunlight_hours > 12:
|
||||
raise ValueError(f"Error: Sunlight hours {sunlight_hours} is too high (max 12)")
|
||||
raise ValueError(f"Error: Sunlight hours {sunlight_hours}\
|
||||
is too high (max 12)")
|
||||
else:
|
||||
print("Plant '" + plant_name + "' is healthy!")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class GardenError(Exception):
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"Caught a garden error: {self.message}"
|
||||
return f"Caught a garden error: {self.message}"
|
||||
|
||||
|
||||
class SunlightError(GardenError):
|
||||
@@ -17,7 +17,7 @@ class SunlightError(GardenError):
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"Caught SunlightError: {self.message}"
|
||||
return f"Caught SunlightError: {self.message}"
|
||||
|
||||
|
||||
class WaterError(GardenError):
|
||||
@@ -34,7 +34,8 @@ class Plant:
|
||||
__water_level: int
|
||||
__sunlight_hours: int
|
||||
|
||||
def __init__(self, name: str, water_level: int, sunlight_hours: int) -> None:
|
||||
def __init__(self, name: str, water_level: int,
|
||||
sunlight_hours: int) -> None:
|
||||
if name == "":
|
||||
raise Exception("Plant name cannot be empty")
|
||||
self.set_name(name)
|
||||
@@ -57,7 +58,7 @@ class Plant:
|
||||
self.__name = name
|
||||
|
||||
def set_water_level(self, water_level: int) -> None:
|
||||
if water_level < 1:
|
||||
if water_level < 1:
|
||||
raise WaterError(f"Water level {water_level} is too low (min 1)")
|
||||
if water_level > 10:
|
||||
raise WaterError(f"Water level {water_level} is too high (max 10)")
|
||||
@@ -65,9 +66,11 @@ class Plant:
|
||||
|
||||
def set_sunlight_hours(self, sunlight_hours: int) -> None:
|
||||
if sunlight_hours < 2:
|
||||
raise SunlightError(f"Sunlight hours {sunlight_hours} is too low (min 2)")
|
||||
raise SunlightError(f"Sunlight hours {sunlight_hours}\
|
||||
is too low (min 2)")
|
||||
if sunlight_hours > 12:
|
||||
raise SunlightError(f"Sunlight hours {sunlight_hours} is too high (max 12)")
|
||||
raise SunlightError(f"Sunlight hours {sunlight_hours}\
|
||||
is too high (max 12)")
|
||||
self.__sunlight_hours = sunlight_hours
|
||||
|
||||
def water_plant(self) -> None:
|
||||
@@ -88,7 +91,6 @@ class GardenManager:
|
||||
def __str__(self) -> str:
|
||||
return f"Caught WaterTankError: {self.message}"
|
||||
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.garden = []
|
||||
self.__water_tank_level = 0
|
||||
@@ -115,15 +117,20 @@ class GardenManager:
|
||||
try:
|
||||
for plant in self.garden:
|
||||
if plant.get_water_level() < 1:
|
||||
raise WaterError(f"{plant.get_name()}: Water level {plant.get_water_level()} is too low (min 1)")
|
||||
raise WaterError(f"{plant.get_name()}: Water level\
|
||||
{plant.get_water_level()} is too low (min 1)")
|
||||
elif plant.get_water_level() > 10:
|
||||
raise WaterError(f"{plant.get_name()}: Water level {plant.get_water_level()} is too high (max 10)")
|
||||
raise WaterError(f"{plant.get_name()}: Water level\
|
||||
{plant.get_water_level()} is too high (max 10)")
|
||||
elif plant.get_sunlight_hours() < 2:
|
||||
raise SunlightError(f"{plant.get_name()}: Sunlight hours {plant.get_sunlight_hours()} is too low (min 2)")
|
||||
raise SunlightError(f"{plant.get_name()}: Sunlight hours\
|
||||
{plant.get_sunlight_hours()} is too low (min 2)")
|
||||
elif plant.get_sunlight_hours() > 12:
|
||||
raise SunlightError(f"{plant.get_name()}: Sunlight hours {plant.get_sunlight_hours()} is too high (max 12)")
|
||||
raise SunlightError(f"{plant.get_name()}: Sunlight hours\
|
||||
{plant.get_sunlight_hours()} is too high (max 12)")
|
||||
else:
|
||||
print(f"{plant.get_name()}: healthy (water: {plant.get_water_level()}, sun: {plant.get_sunlight_hours()})")
|
||||
print(f"{plant.get_name()}: healthy (water:\
|
||||
{plant.get_water_level()}, sun: {plant.get_sunlight_hours()})")
|
||||
except (WaterError, SunlightError) as err:
|
||||
print(err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user