Skip to content

Commit

Permalink
Finish first-pass replacing " -> '
Browse files Browse the repository at this point in the history
  • Loading branch information
civerachb-cpr committed Nov 4, 2024
1 parent baed5bf commit 2f7bf85
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 113 deletions.
4 changes: 2 additions & 2 deletions clearpath_config/common/types/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def is_valid(cls, mode: str) -> bool:
@classmethod
def assert_valid(cls, mode: str) -> None:
assert cls.is_valid(mode), ('\n'.join[
f'Discovery mode '{mode}' not supported.'
f'Discovery mode must be one of: '{cls.ALL_SUPPORTED}''
f'Discovery mode "{mode}" not supported.'
f'Discovery mode must be one of: "{cls.ALL_SUPPORTED}"'
])
10 changes: 5 additions & 5 deletions clearpath_config/common/types/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ def is_valid(hostname: str) -> bool:
@staticmethod
def assert_valid(hostname: str):
assert isinstance(hostname, str), (
'Hostname '%s' must be of type 'str'' % hostname
'Hostname "%s" must be of type "str"' % hostname
)
# Min 1 ASCII Characters
assert len(hostname) > 0, (
'Hostname '%s' is blank.' % hostname
'Hostname "%s" is blank.' % hostname
)
# Max 253 ASCII Characters
assert len(hostname) < 254, (
'Hostname '%s' exceeds 253 ASCII character limit.' % hostname
'Hostname "%s" exceeds 253 ASCII character limit.' % hostname
)
# No Trailing Dots
assert hostname[-1] != '.', (
'Hostname '%s' should not end with a ('.') period.' % hostname
'Hostname "%s" should not end with a "." period.' % hostname
)
# Only [A-Z][0-9] and '-' Allowed
allowed = re.compile(r'(?!-)[A-Z\d-]{1,63}(?<!-)$', re.IGNORECASE)
assert all(allowed.match(x) for x in hostname.split('.')), (
'Hostname '%s' cannot contain characters other than %s.' % (
'Hostname "%s" cannot contain characters other than %s.' % (
hostname,
'[A-Z][0-9] and hypens ('-')'
)
Expand Down
4 changes: 2 additions & 2 deletions clearpath_config/common/types/rmw_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def is_valid(cls, rmw: str) -> bool:
@classmethod
def assert_valid(cls, rmw: str) -> None:
assert cls.is_valid(rmw), ('\n'.join[
'RMW '%s' not supported.' % rmw,
'RMW must be one of: '%s'' % cls.ALL_SUPPORTED
'RMW "%s" not supported.' % rmw,
'RMW must be one of: "%s"' % cls.ALL_SUPPORTED
])
6 changes: 3 additions & 3 deletions clearpath_config/common/types/username.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ def is_valid(username: str):
def assert_valid(username: str):
# Check Type
assert isinstance(username, str), (
'Username '%s' must of type 'str'' % username
'Username "%s" must of type "str"' % username
)
# Max 255 Characters
assert len(username) < 256, (
'Username '%s' exceeds 255 ASCII character limit.' % username
'Username "%s" exceeds 255 ASCII character limit.' % username
)
# Regex Convention
allowed = re.compile(r'[-a-z0-9_]')
assert all(allowed.match(c) for c in username), (
'Username '%s' cannot contain characters other than: %s, %s, %s, %s' % (
'Username "%s" cannot contain characters other than: %s, %s, %s, %s' % (
username,
'lowercase letters',
'digits',
Expand Down
11 changes: 3 additions & 8 deletions clearpath_config/platform/attachments/mux.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ class AttachmentsConfigMux:

def __new__(cls, platform: str, attachments: dict = None) -> AttachmentsConfig:
# Check Platform is Supported
assert platform in cls.PLATFORM, (
'Platform '%s' must be one of: '%s'' % (
platform,
cls.PLATFORM.keys()
)
)
assert platform in cls.PLATFORM, f'Platform "{platform}" must be one of "{self.PLATFORM.keys()}"' # noqa:E501
if not attachments:
return cls.PLATFORM[platform]
# Pre-Process Entries
Expand All @@ -74,8 +69,8 @@ def __new__(cls, platform: str, attachments: dict = None) -> AttachmentsConfig:
@staticmethod
def preprocess(platform: str, attachments: dict):
for i, a in enumerate(attachments):
assert 'name' in a, 'An attachment is missing 'name''
assert 'type' in a, 'An attachment is missing 'type''
assert 'name' in a, 'An attachment is missing "name"'
assert 'type' in a, 'An attachment is missing "type"'
if '.' not in a['type']:
a['type'] = '%s.%s' % (platform, a['type'])
attachments[i] = a
Expand Down
72 changes: 21 additions & 51 deletions clearpath_config/sensors/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ class InertialMeasurementUnit():

@classmethod
def assert_model(cls, model: str) -> None:
assert model in cls.MODEL, (
'Model '%s' must be one of: '%s'' % (
model,
cls.MODEL.keys()
)
)
assert model in cls.MODEL, f'Model "{model}" must be one of "{cls.MODEL.keys()}"'

def __new__(cls, model: str) -> BaseIMU:
cls.assert_model(model)
Expand All @@ -107,12 +102,7 @@ class Camera():

@classmethod
def assert_model(cls, model: str) -> None:
assert model in cls.MODEL, (
'Model '%s' must be one of: '%s'' % (
model,
cls.MODEL.keys()
)
)
assert model in cls.MODEL, f'Model "{model}" must be one of "{cls.MODEL.keys()}"'

def __new__(cls, model: str) -> BaseCamera:
cls.assert_model(model)
Expand All @@ -136,12 +126,7 @@ class GlobalPositioningSystem():

@classmethod
def assert_model(cls, model: str) -> None:
assert model in cls.MODEL, (
'Model '%s' must be one of: '%s'' % (
model,
cls.MODEL.keys()
)
)
assert model in cls.MODEL, f'Model "{model}" must be one of "{cls.MODEL.keys()}"'

def __new__(cls, model: str) -> BaseGPS:
cls.assert_model(model)
Expand All @@ -159,12 +144,7 @@ class Lidar2D():

@classmethod
def assert_model(cls, model: str) -> None:
assert model in cls.MODEL, (
'Model '%s' must be one of: '%s'' % (
model,
cls.MODEL.keys()
)
)
assert model in cls.MODEL, f'Model "{model}" must be one of "{cls.MODEL.keys()}"'

def __new__(cls, model: str) -> BaseLidar2D:
cls.assert_model(model)
Expand All @@ -180,12 +160,7 @@ class Lidar3D():

@classmethod
def assert_model(cls, model: str) -> None:
assert model in cls.MODEL, (
'Model '%s' must be one of: '%s'' % (
model,
cls.MODEL.keys()
)
)
assert model in cls.MODEL, f'Model "{model}" must be one of "{cls.MODEL.keys()}"'

def __new__(cls, model: str) -> BaseLidar3D:
cls.assert_model(model)
Expand All @@ -209,12 +184,7 @@ class Sensor():

@classmethod
def assert_type(cls, _type: str) -> None:
assert _type in cls.TYPE, (
'Sensor type '%s' must be one of: '%s'' % (
_type,
cls.TYPE.keys()
)
)
assert _type in cls.TYPE, f'Sensor type "{_type}" must be one of "{cls.TYPE.keys()}"'

def __new__(cls, _type: str, _model: str) -> BaseSensor:
cls.assert_type(_type)
Expand Down Expand Up @@ -319,11 +289,11 @@ def camera(self) -> OrderedListConfig:
@camera.setter
def camera(self, value: List[dict]) -> None:
assert isinstance(value, list), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all([isinstance(d, dict) for d in value]), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all(['model' in d for d in value]), (
'Sensor 'dict' must have 'model' key')
'Sensor "dict" must have "model" key')
sensor_list = []
for d in value:
sensor = Camera(d['model'])
Expand All @@ -342,11 +312,11 @@ def gps(self) -> OrderedListConfig:
@gps.setter
def gps(self, value: List[dict]) -> None:
assert isinstance(value, list), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all([isinstance(d, dict) for d in value]), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all(['model' in d for d in value]), (
'Sensor 'dict' must have 'model' key')
'Sensor "dict" must have "model" key')
sensor_list = []
for d in value:
sensor = GlobalPositioningSystem(d['model'])
Expand All @@ -365,11 +335,11 @@ def imu(self) -> OrderedListConfig:
@imu.setter
def imu(self, value: List[dict]) -> None:
assert isinstance(value, list), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all([isinstance(d, dict) for d in value]), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all(['model' in d for d in value]), (
'Sensor 'dict' must have 'model' key')
'Sensor "dict" must have "model" key')
sensor_list = []
for d in value:
sensor = InertialMeasurementUnit(d['model'])
Expand All @@ -388,11 +358,11 @@ def lidar2d(self) -> OrderedListConfig:
@lidar2d.setter
def lidar2d(self, value: List[dict]) -> None:
assert isinstance(value, list), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all([isinstance(d, dict) for d in value]), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all(['model' in d for d in value]), (
'Sensor 'dict' must have 'model' key')
'Sensor "dict" must have "model" key')
sensor_list = []
for d in value:
sensor = Lidar2D(d['model'])
Expand All @@ -411,11 +381,11 @@ def lidar3d(self) -> OrderedListConfig:
@lidar3d.setter
def lidar3d(self, value: List[dict]) -> None:
assert isinstance(value, list), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all([isinstance(d, dict) for d in value]), (
'Sensors must be list of 'dict'')
'Sensors must be list of "dict"')
assert all(['model' in d for d in value]), (
'Sensor 'dict' must have 'model' key')
'Sensor "dict" must have "model" key')
sensor_list = []
for d in value:
sensor = Lidar3D(d['model'])
Expand Down
26 changes: 12 additions & 14 deletions clearpath_config/sensors/types/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ class Theora(Base):
}

def __new__(self, config: dict) -> None:
assert self.TYPE in config, (
'Republisher must have '%s' specified.' % self.TYPE)
assert config[self.TYPE] in self.TYPES, (
'Republisher '%s' must be one of: '%s'.' % (self.TYPE, [i for i in self.TYPES]))
assert self.TYPE in config, f'Republisher must have "{self.TYPE}" specified'
assert config[self.TYPE] in self.TYPES, f'Republisher "{self.TYPE}" must be one of "{[t for t in self.TYPES]}"' # noqa:E501
return self.TYPES[config[self.TYPE]](config)


Expand Down Expand Up @@ -192,10 +190,10 @@ def set_fps(self, fps: int) -> None:
@staticmethod
def assert_valid_fps(fps: int) -> None:
assert isinstance(fps, int), (
'FPS '%s' is invalid, must be an integer.' % fps
'FPS "%s" is invalid, must be an integer.' % fps
)
assert 0 <= fps, (
'FPS '%s' must be a positive integer.' % fps
'FPS "%s" must be a positive integer.' % fps
)

@property
Expand Down Expand Up @@ -374,17 +372,17 @@ def clean_profile(profile: str | list) -> list:
if isinstance(profile, str):
profile = profile.split(',')
assert len(profile) == 3, (
'Profile '%s' is not three comma separated values')
'Profile "%s" is not three comma separated values')
try:
profile = [int(entry) for entry in profile]
except ValueError:
raise AssertionError(
'Profile '%s' cannot be cast to integer')
'Profile "%s" cannot be cast to integer')
else:
assert len(profile) == 3, (
'Profile '%s' is not three integer values')
'Profile "%s" is not three integer values')
assert all([isinstance(entry, int) for entry in profile]), (
'Profile '%s' is not three integer values')
'Profile "%s" is not three integer values')
return profile

def assert_pixel_length(
Expand Down Expand Up @@ -413,7 +411,7 @@ def device_type(self) -> str:
@device_type.setter
def device_type(self, device_type: str) -> None:
assert device_type in self.DEVICE_TYPES, (
'Device type '%s' is not one of '%s'' % (
'Device type "%s" is not one of "%s"' % (
device_type,
self.DEVICE_TYPES
)
Expand Down Expand Up @@ -773,7 +771,7 @@ def encoding(self) -> str:
@encoding.setter
def encoding(self, encoding: str) -> None:
assert encoding in FlirBlackfly.ENCODINGS, (
'Encoding '%s' not found in support encodings: '%s'' % (
'Encoding "%s" not found in support encodings: "%s"' % (
encoding, FlirBlackfly.ENCODINGS
)
)
Expand Down Expand Up @@ -907,7 +905,7 @@ def device_type(self) -> str:
@device_type.setter
def device_type(self, device_type: str) -> None:
assert device_type in self.DEVICE_TYPES, (
'Device type '%s' is not one of '%s'' % (
'Device type "%s" is not one of "%s"' % (
device_type,
self.DEVICE_TYPES
)
Expand All @@ -921,7 +919,7 @@ def resolution(self) -> str:
@resolution.setter
def resolution(self, resolution: str) -> None:
assert resolution in self.RESOLUTION_PRESETS, (
'Resolution preset '%s' is not one oserial_numberf '%s'' % (
'Resolution preset "%s" is not one oserial_numberf "%s"' % (
resolution,
self.RESOLUTION_PRESETS
)
Expand Down
4 changes: 2 additions & 2 deletions clearpath_config/sensors/types/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def baud(self) -> int:

@baud.setter
def baud(self, baud: int) -> None:
assert isinstance(baud, int), ('Baud must be of type 'int'.')
assert isinstance(baud, int), ('Baud must be of type "int".')
assert baud >= 0, ('Baud must be positive integer.')
self._baud = baud

Expand Down Expand Up @@ -374,7 +374,7 @@ def baud(self) -> int:

@baud.setter
def baud(self, baud: int) -> None:
assert isinstance(baud, int), ('Baud must be of type 'int'.')
assert isinstance(baud, int), ('Baud must be of type "int".')
assert baud >= 0, ('Baud must be positive integer.')
self._baud = baud

Expand Down
2 changes: 1 addition & 1 deletion clearpath_config/sensors/types/lidars_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def device_type(self) -> str:
@device_type.setter
def device_type(self, device_type) -> None:
assert device_type in self.DEVICE_TYPES, (
'Device type '%s' is not one of '%s'' % (
'Device type "%s" is not one of "%s"' % (
device_type,
self.DEVICE_TYPES
)
Expand Down
10 changes: 3 additions & 7 deletions clearpath_config/sensors/types/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,8 @@ def get_topic_rate(self, topic: str) -> float:
return self.TOPICS.RATE[topic]

def set_topic(self, topic: str) -> None:
assert isinstance(topic, str), (
'Topic '%s' of type '%s', expected 'str'' % (topic, type(topic))
)
assert ' ' not in topic, (
'Topic '%s' contains empty spaces.' % topic
)
assert isinstance(topic, str), f'Topic "{topic}" is of type "{type(topic)}", expected "str"'
assert ' ' not in topic, f'Topic "{topic}" contains whitespace'
self.topic = topic

def enable_urdf(self) -> None:
Expand Down Expand Up @@ -201,7 +197,7 @@ def ros_parameters_template(self) -> dict:

@ros_parameters_template.setter
def ros_parameters_template(self, d: dict) -> None:
assert isinstance(d, dict), ('Template must be of type 'dict'')
assert isinstance(d, dict), ('Template must be of type "dict"')
# Check that template has all properties
flat = flatten_dict(d)
for _, val in flat.items():
Expand Down
Loading

0 comments on commit 2f7bf85

Please sign in to comment.