Skip to content

Commit a889515

Browse files
committed
lint
1 parent 82c5938 commit a889515

8 files changed

Lines changed: 38 additions & 31 deletions

File tree

_unittests/ut_graph/test_graph_distance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ def test_image_video_kohonen(self):
3838
graph2["C"].label = "c"
3939
store = {}
4040
if len(list(graph1.enumerate_all_paths(True))) != 17:
41-
raise Exception("expecting 17 here")
41+
raise AssertionError("expecting 17 here")
4242
if len(list(graph2.enumerate_all_paths(True))) != 19:
43-
raise Exception("expecting 19 here")
43+
raise AssertionError("expecting 19 here")
4444

4545
distance, graph = graph1.distance_matching_graphs_paths(graph2,
4646
use_min=False, store=store)
4747

4848
if graph["h"].Label != "h":
49-
raise Exception("we expect this node to be merged in the process")
49+
raise AssertionError("we expect this node to be merged in the process")
5050

5151
if distance is None:
52-
raise Exception("expecting something different from None")
52+
raise AssertionError("expecting something different from None")
5353

5454
outfile1 = os.path.join(temp, "unittest_GraphDistance4_sub1.png")
5555
outfile2 = os.path.join(temp, "unittest_GraphDistance4_sub2.png")

_unittests/ut_module/test_doc_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_doc_page(self):
114114
if "contains reference to nonexisting document" in lines[i + 1]:
115115
continue
116116
mes = f'WARNING issue\n File "{rst}", line {i + 1}'
117-
raise Exception(mes)
117+
raise AssertionError(mes)
118118

119119

120120
if __name__ == "__main__":

_unittests/ut_nlp/test_LONG_completion.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_build_dynamic_trie_mks_min(self):
4444
fLOG(i)
4545
leave = trie.find(q[1])
4646
if leave.stat is None:
47-
raise Exception(f"None for {leave}")
47+
raise AssertionError(f"None for {leave}")
4848

4949
self.assertTrue(hasattr(leave, "stat"))
5050
self.assertTrue(hasattr(leave.stat, "mks0"))
@@ -61,29 +61,32 @@ def test_build_dynamic_trie_mks_min(self):
6161
st = leave.stat.str_mks()
6262
text = leave.str_all_completions()
6363
text2 = leave.str_all_completions(use_precompute=False)
64-
raise Exception(
64+
raise AssertionError(
6565
f"{info}\n---\nleave='{leave.value}'\n{st}\n---\n{text}\n---\n{text2}")
6666

6767
mk1 = trie.min_keystroke0(leave.value)
6868
try:
6969
mk = trie.min_dynamic_keystroke(leave.value)
7070
mk2 = trie.min_dynamic_keystroke2(leave.value)
7171
except Exception as e:
72-
raise Exception(
72+
raise RuntimeError(
7373
f"{id(trie)}-{id(leave)}-{str(leave)}-{leave.leave}") from e
7474

7575
if mk[0] > mk1[0]:
7676
st = leave.stat.str_mks()
7777
text = leave.str_all_completions()
7878
text2 = leave.str_all_completions(use_precompute=False)
79-
raise Exception("weird {0} > {1} -- leave='{2}'\n{3}\n---\n{4}\n---\n{5}".format(
80-
mk, mk1, leave.value, st, text, text2))
79+
raise RuntimeError(
80+
"weird {0} > {1} -- leave='{2}'\n{3}\n---\n"
81+
"{4}\n---\n{5}".format(
82+
mk, mk1, leave.value, st, text, text2))
8183
if mk2[0] < mk[0]:
8284
st = leave.stat.str_mks()
8385
text = leave.str_all_completions()
8486
text2 = leave.str_all_completions(use_precompute=False)
85-
raise Exception("weird {0} > {1} -- leave='{2}'\n{3}\n---\n{4}\n---\n{5}".format(
86-
mk, mk2, leave.value, st, text, text2))
87+
raise RuntimeError(
88+
"weird {0} > {1} -- leave='{2}'\n{3}\n---\n{4}\n---\n{5}".format(
89+
mk, mk2, leave.value, st, text, text2))
8790
clog("end")
8891
fLOG("end")
8992

_unittests/ut_nlp/test_completion_longer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_check_bug_about_mergeing_completions(self):
4444
if s[1].value == "Cannes 2005":
4545
verif += 1
4646
if verif == 0:
47-
raise Exception(leave.str_all_completions(use_precompute=True))
47+
raise AssertionError(leave.str_all_completions(use_precompute=True))
4848

4949
sugg = leave.all_completions()
5050
assert len(sugg) > 0
@@ -55,7 +55,7 @@ def test_check_bug_about_mergeing_completions(self):
5555
if s == "Cannes 2005":
5656
verif += 1
5757
if verif == 0:
58-
raise Exception(leave.str_all_completions(use_precompute=False))
58+
raise AssertionError(leave.str_all_completions(use_precompute=False))
5959

6060

6161
if __name__ == "__main__":

_unittests/ut_nlp/test_completion_simple.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_build_trie_simple(self):
3838
diffs = trie.compare_with_trie(fLOG=fLOG)
3939
if diffs:
4040
res = [_[-1] for _ in diffs]
41-
raise Exception("\n".join(res))
41+
raise AssertionError("\n".join(res))
4242
r = trie[2]
4343
assert r._info
4444
s = trie[2].str_all_completions()
@@ -47,7 +47,7 @@ def test_build_trie_simple(self):
4747
for k, v in sorted(r._info._completions.items()):
4848
assert isinstance(v, list)
4949
if k != '' and len(v) > 2:
50-
raise Exception(v)
50+
raise AssertionError(v)
5151
assert v
5252
fLOG(k, v)
5353
for _ in v:
@@ -72,7 +72,7 @@ def test_permutations(self):
7272
diffs = trie.compare_with_trie()
7373
if diffs:
7474
res = [_[-1] for _ in diffs]
75-
raise Exception("\n".join(res))
75+
raise AssertionError("\n".join(res))
7676

7777
def test_mks_consistency(self):
7878
fLOG(
@@ -86,14 +86,14 @@ def test_mks_consistency(self):
8686
diffs = trie.compare_with_trie()
8787
if diffs:
8888
res = [_[-1] for _ in diffs]
89-
raise Exception("\n".join(res))
89+
raise AssertionError("\n".join(res))
9090

9191
titles.append((None, '"la sequestree"', '"La séquestrée'))
9292
trie = CompletionSystem(titles)
9393
diffs = trie.compare_with_trie()
9494
if diffs:
9595
res = [_[-1] for _ in diffs]
96-
raise Exception("\n".join(res))
96+
raise AssertionError("\n".join(res))
9797

9898
def test_mks_consistency_port(self):
9999
fLOG(
@@ -107,15 +107,15 @@ def test_mks_consistency_port(self):
107107
diffs = trie.compare_with_trie()
108108
if diffs:
109109
res = [_[-1] for _ in diffs]
110-
raise Exception("\n".join(res))
110+
raise AssertionError("\n".join(res))
111111

112112
titles = ["po", "po rouge", "po vert", "po orange",
113113
"port", "port blanc", "port rouge"]
114114
trie = CompletionSystem(titles)
115115
diffs = trie.compare_with_trie()
116116
if diffs:
117117
res = [_[-1] for _ in diffs]
118-
raise Exception("\n".join(res))
118+
raise AssertionError("\n".join(res))
119119

120120
def test_completions(self):
121121
fLOG(
@@ -134,7 +134,7 @@ def test_completions(self):
134134
res = [_[-1] for _ in diffs]
135135
if len(res) > 3:
136136
res = res[:3]
137-
raise Exception("\n".join(res))
137+
raise AssertionError("\n".join(res))
138138
assert len(trie) > 0
139139

140140
def test_exception(self):
@@ -166,7 +166,7 @@ def cmks(trie):
166166
if len(diffs) > 3:
167167
diffs = diffs[:3]
168168
res = [_[-1] for _ in diffs]
169-
raise Exception("\n".join(res))
169+
raise AssertionError("\n".join(res))
170170

171171
gmks = 0.0
172172
gmksd = 0.0
@@ -177,8 +177,10 @@ def cmks(trie):
177177
if n.mks2 < n.mks1 or (n.value == "baaaab" and n.mks1 != 4):
178178
info = "" # n.str_all_completions()
179179
info2 = "" # n.str_all_completions(use_precompute=True)
180-
raise Exception("issue with query '{0}'\n{1}\n##########\n{2}\n############\n{3}".format(
181-
n.value, n.str_mks(), info, info2))
180+
raise AssertionError(
181+
"issue with query '{0}'\n{1}\n##########\n"
182+
"{2}\n############\n{3}".format(
183+
n.value, n.str_mks(), info, info2))
182184

183185
gmks += len(n.value) - n.mks0
184186
gmksd += len(n.value) - n.mks1
@@ -234,7 +236,7 @@ def test_completions_bug(self):
234236
res = [_[-1] for _ in diffs]
235237
if len(res) > 3:
236238
res = res[:3]
237-
raise Exception("\n".join(res))
239+
raise AssertionError("\n".join(res))
238240
assert len(ens) > 0
239241
m = ens.find("portes blanche")
240242
self.assertEqual(m.mks2, 7.8)

src/mlstatpy/graph/graph_distance.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,10 @@ def private_kruskal_matrix(self, matrix, reverse):
723723

724724
mini = min(cleft, cright)
725725
if len(matrix) < mini:
726-
raise Exception("impossible: the smallest set should get all" +
727-
"its element associated to at least one coming from the other set")
726+
raise RuntimeError(
727+
"impossible: the smallest set should get all "
728+
"its element associated to at least one coming "
729+
"from the other set")
728730

729731
def _private_string_path_matching(self, path, skipEdge=False):
730732
temp = []

src/mlstatpy/graph/graphviz_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def run_graphviz(filename, image, engine="dot"):
1919
"""
2020
ext = os.path.splitext(image)[-1]
2121
if ext != ".png":
22-
raise Exception("extension should be .png not " + str(ext))
22+
raise RuntimeError("extension should be .png not " + str(ext))
2323
if sys.platform.startswith("win"):
2424
bin_ = os.path.dirname(find_graphviz_dot())
2525
# if bin not in os.environ["PATH"]:
@@ -29,7 +29,7 @@ def run_graphviz(filename, image, engine="dot"):
2929
cmd = f'"{engine}" -Tpng "{filename}" -o "{image}"'
3030
out, err = run_cmd(cmd, wait=True)
3131
if len(err) > 0:
32-
raise Exception(
32+
raise RuntimeError(
3333
f"Unable to run Graphviz\nCMD:\n{cmd}\nOUT:\n{out}\nERR:\n{err}")
3434
return out
3535

src/mlstatpy/nlp/completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def update_dynamic_minimum_keystroke(self, lw, delta):
581581
sug.stat.mks2i_ = self.mks_iter
582582
update += 1
583583
else:
584-
raise Exception("this case should not happen")
584+
raise RuntimeError("this case should not happen")
585585

586586
# optimisation of second case of modified metric
587587
# in a separate function for profiling

0 commit comments

Comments
 (0)