Skip to content

Commit e006e57

Browse files
committed
Replace assert statements with proper error handling in non-test files
Signed-off-by: bhoomi-bombom <[email protected]>
1 parent ff2a615 commit e006e57

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/attributecode/attrib.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,15 @@ def generate_sctk_input(abouts, min_license_score, license_dict):
193193
for key in lic_key:
194194
lic_name.append(license_dict[key][0])
195195
lic_score = about.license_score.value
196-
assert len(lic_key) == len(lic_name)
197-
assert len(lic_key) == len(lic_score)
198-
196+
len_lic_key = len(lic_key)
197+
if len_lic_key != len(lic_name):
198+
raise ValueError(
199+
f"Mismatch between lengths: lic_key ({len_lic_key}) vs lic_name ({len(lic_name)})"
200+
)
201+
if len_lic_key != len(lic_score):
202+
raise ValueError(
203+
f"Mismatch between lengths: lic_key ({len_lic_key}) vs lic_score ({len(lic_score)})"
204+
)
199205
lic_key_expression = about.license_key_expression.value
200206
if lic_key_expression:
201207
updated_lic_key_expression = []

src/attributecode/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def get_locations(location):
167167
"""
168168
location = add_unc(location)
169169
location = get_absolute(location)
170-
assert os.path.exists(location)
170+
if not os.path.exists(location):
171+
raise FileNotFoundError(f"Expected path does not exist: {location}")
172+
171173

172174
if os.path.isfile(location):
173175
yield location
@@ -283,9 +285,10 @@ def get_relative_path(base_loc, full_loc):
283285
base = norm(base_loc)
284286
path = norm(full_loc)
285287

286-
assert path.startswith(base), (
287-
"Cannot compute relative path: %(path)r does not start with %(base)r" % locals()
288-
)
288+
if not path.startswith(base):
289+
raise ValueError(
290+
f"Cannot compute relative path: {path!r} does not start with {base!r}"
291+
)
289292
base_name = resource_name(base)
290293
no_dir = base == base_name
291294
same_loc = base == path

0 commit comments

Comments
 (0)