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