improve except
This commit is contained in:
@@ -45,20 +45,14 @@ def is_robot_available(robot_type):
|
|||||||
del robot
|
del robot
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except Exception as e:
|
||||||
print(f"\nA {robot_type} robot is not available.")
|
print(f"\nA {robot_type} robot is not available.")
|
||||||
print(f"\nInstall module '{e.name}'")
|
|
||||||
traceback.print_exc()
|
|
||||||
return False
|
|
||||||
|
|
||||||
except SerialException:
|
if isinstance(e, ModuleNotFoundError):
|
||||||
traceback.print_exc()
|
print(f"\nInstall module '{e.name}'")
|
||||||
print(f"\nA {robot_type} robot is not available.")
|
elif isinstance(e, SerialException):
|
||||||
print("\nNo physical motors bus detected.")
|
print("\nNo physical motors bus detected.")
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
print(f"\nA {robot_type} robot is not available.")
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -76,23 +70,17 @@ def is_camera_available(camera_type):
|
|||||||
del camera
|
del camera
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except Exception as e:
|
||||||
print(f"\nA {camera_type} camera is not available.")
|
print(f"\nA {camera_type} camera is not available.")
|
||||||
print(f"\nInstall module '{e.name}'")
|
|
||||||
|
if isinstance(e, ModuleNotFoundError):
|
||||||
|
print(f"\nInstall module '{e.name}'")
|
||||||
|
elif isinstance(e, ValueError) and "camera_index" in e.args[0]:
|
||||||
|
print("\nNo physical camera detected.")
|
||||||
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception:
|
|
||||||
print(f"\nA {camera_type} camera is not available.")
|
|
||||||
print("\nNo physical camera detected.")
|
|
||||||
traceback.print_exc()
|
|
||||||
return False
|
|
||||||
|
|
||||||
# except Exception as e:
|
|
||||||
# print(f"\nA {camera_type} camera is not available.")
|
|
||||||
# traceback.print_exc()
|
|
||||||
# return False
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def is_motor_available(motor_type):
|
def is_motor_available(motor_type):
|
||||||
@@ -107,20 +95,14 @@ def is_motor_available(motor_type):
|
|||||||
del motors_bus
|
del motors_bus
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except ModuleNotFoundError as e:
|
except Exception as e:
|
||||||
print(f"\nA {motor_type} motor is not available.")
|
print(f"\nA {motor_type} motor is not available.")
|
||||||
print(f"\nInstall module '{e.name}'")
|
|
||||||
traceback.print_exc()
|
|
||||||
return False
|
|
||||||
|
|
||||||
except SerialException:
|
if isinstance(e, ModuleNotFoundError):
|
||||||
print(f"\nA {motor_type} motor is not available.")
|
print(f"\nInstall module '{e.name}'")
|
||||||
print("\nNo physical motors bus detected.")
|
elif isinstance(e, SerialException):
|
||||||
traceback.print_exc()
|
print("\nNo physical motors bus detected.")
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
print(f"\nA {motor_type} motor is not available.")
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user