Skip to content

Commit 1aa3ea5

Browse files
committed
Version 0.6.3: Fixed MultipleExceptions.merge raising TracedException.
1 parent 342ff60 commit 1aa3ea5

File tree

8 files changed

+49
-60
lines changed

8 files changed

+49
-60
lines changed

conda/raffiot/meta.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "raffiot" %}
2-
{% set version = "0.6.2" %}
2+
{% set version = "0.6.3" %}
33

44
package:
55
name: "{{ name|lower }}"

docs/api/index.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,8 @@ <h3>Class variables</h3>
10681068
if isinstance(item, abc.Iterable) and not isinstance(item, str):
10691069
stack.extend(item)
10701070
continue
1071-
base_exceptions.append(item)
1071+
base_exceptions.append(TracedException.ensure_traced(item))
10721072

1073-
if len(base_exceptions) == 1:
1074-
return base_exceptions[0]
10751073
base_exceptions.reverse()
10761074
return MultipleExceptions(base_exceptions, errs)
10771075

@@ -1139,10 +1137,8 @@ <h3>Static methods</h3>
11391137
if isinstance(item, abc.Iterable) and not isinstance(item, str):
11401138
stack.extend(item)
11411139
continue
1142-
base_exceptions.append(item)
1140+
base_exceptions.append(TracedException.ensure_traced(item))
11431141

1144-
if len(base_exceptions) == 1:
1145-
return base_exceptions[0]
11461142
base_exceptions.reverse()
11471143
return MultipleExceptions(base_exceptions, errs)</code></pre>
11481144
</details>

docs/api/untyped/index.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,8 @@ <h3>Class variables</h3>
10471047
if isinstance(item, abc.Iterable) and not isinstance(item, str):
10481048
stack.extend(item)
10491049
continue
1050-
base_exceptions.append(item)
1050+
base_exceptions.append(TracedException.ensure_traced(item))
10511051

1052-
if len(base_exceptions) == 1:
1053-
return base_exceptions[0]
10541052
base_exceptions.reverse()
10551053
return MultipleExceptions(base_exceptions, errs)
10561054

@@ -1117,10 +1115,8 @@ <h3>Static methods</h3>
11171115
if isinstance(item, abc.Iterable) and not isinstance(item, str):
11181116
stack.extend(item)
11191117
continue
1120-
base_exceptions.append(item)
1118+
base_exceptions.append(TracedException.ensure_traced(item))
11211119

1122-
if len(base_exceptions) == 1:
1123-
return base_exceptions[0]
11241120
base_exceptions.reverse()
11251121
return MultipleExceptions(base_exceptions, errs)</code></pre>
11261122
</details>

docs/api/untyped/utils.html

+3-9
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ <h1 class="title">Module <code>raffiot.untyped.utils</code></h1>
145145
if isinstance(item, abc.Iterable) and not isinstance(item, str):
146146
stack.extend(item)
147147
continue
148-
base_exceptions.append(item)
148+
base_exceptions.append(TracedException.ensure_traced(item))
149149

150-
if len(base_exceptions) == 1:
151-
return base_exceptions[0]
152150
base_exceptions.reverse()
153151
return MultipleExceptions(base_exceptions, errs)
154152

@@ -368,10 +366,8 @@ <h3>Class variables</h3>
368366
if isinstance(item, abc.Iterable) and not isinstance(item, str):
369367
stack.extend(item)
370368
continue
371-
base_exceptions.append(item)
369+
base_exceptions.append(TracedException.ensure_traced(item))
372370

373-
if len(base_exceptions) == 1:
374-
return base_exceptions[0]
375371
base_exceptions.reverse()
376372
return MultipleExceptions(base_exceptions, errs)
377373

@@ -438,10 +434,8 @@ <h3>Static methods</h3>
438434
if isinstance(item, abc.Iterable) and not isinstance(item, str):
439435
stack.extend(item)
440436
continue
441-
base_exceptions.append(item)
437+
base_exceptions.append(TracedException.ensure_traced(item))
442438

443-
if len(base_exceptions) == 1:
444-
return base_exceptions[0]
445439
base_exceptions.reverse()
446440
return MultipleExceptions(base_exceptions, errs)</code></pre>
447441
</details>

docs/api/utils.html

+3-9
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,8 @@ <h1 class="title">Module <code>raffiot.utils</code></h1>
153153
if isinstance(item, abc.Iterable) and not isinstance(item, str):
154154
stack.extend(item)
155155
continue
156-
base_exceptions.append(item)
156+
base_exceptions.append(TracedException.ensure_traced(item))
157157

158-
if len(base_exceptions) == 1:
159-
return base_exceptions[0]
160158
base_exceptions.reverse()
161159
return MultipleExceptions(base_exceptions, errs)
162160

@@ -382,10 +380,8 @@ <h3>Class variables</h3>
382380
if isinstance(item, abc.Iterable) and not isinstance(item, str):
383381
stack.extend(item)
384382
continue
385-
base_exceptions.append(item)
383+
base_exceptions.append(TracedException.ensure_traced(item))
386384

387-
if len(base_exceptions) == 1:
388-
return base_exceptions[0]
389385
base_exceptions.reverse()
390386
return MultipleExceptions(base_exceptions, errs)
391387

@@ -453,10 +449,8 @@ <h3>Static methods</h3>
453449
if isinstance(item, abc.Iterable) and not isinstance(item, str):
454450
stack.extend(item)
455451
continue
456-
base_exceptions.append(item)
452+
base_exceptions.append(TracedException.ensure_traced(item))
457453

458-
if len(base_exceptions) == 1:
459-
return base_exceptions[0]
460454
base_exceptions.reverse()
461455
return MultipleExceptions(base_exceptions, errs)</code></pre>
462456
</details>

raffiot/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ def merge(cls, *exceptions: TracedException, errors: List[E] = None) -> Exceptio
125125
if isinstance(item, abc.Iterable) and not isinstance(item, str):
126126
stack.extend(item)
127127
continue
128-
base_exceptions.append(item)
128+
base_exceptions.append(TracedException.ensure_traced(item))
129129

130-
if len(base_exceptions) == 1:
131-
return base_exceptions[0]
132130
base_exceptions.reverse()
133131
return MultipleExceptions(base_exceptions, errs)
134132

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! env python3
22
from setuptools import setup
33

4-
version = "0.6.2"
4+
version = "0.6.3"
55

66
with open("README.md", "r", encoding="utf-8") as fh:
77
long_description = fh.read()

tests/test_utils.py

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
from unittest import TestCase
22

3-
from raffiot.utils import *
3+
import hypothesis.strategies as st
4+
from hypothesis import given
45

5-
x = 5
6-
y = 6
7-
z = 7
6+
from raffiot.utils import *
7+
from typing import List
88

99

1010
def test_sequence():
11-
assert seq(x, y, z) == z
12-
13-
14-
class TestMultipleExceptions(TestCase):
15-
def test_merge_none(self):
16-
assert MultipleExceptions.merge() == MultipleExceptions([], [])
11+
x = 5
12+
y = 6
13+
z = 7
1714

18-
def test_merge_one(self):
19-
exn = MatchError(x)
20-
assert MultipleExceptions.merge(exn) == exn
21-
22-
def test_merge_list_one(self):
23-
exn = MatchError(x)
24-
assert MultipleExceptions.merge([exn]) == exn
25-
26-
def test_merge_list_one(self):
27-
exn_x = MatchError(x)
28-
exn_y = MatchError(y)
29-
exn_z = MatchError(z)
30-
assert MultipleExceptions.merge(
31-
MultipleExceptions([exn_x], []), exn_y, MultipleExceptions([exn_z], [])
32-
) == MultipleExceptions([exn_x, exn_y, exn_z], [])
15+
assert seq(x, y, z) == z
3316

3417

3518
class TestTracedException(TestCase):
@@ -44,3 +27,31 @@ def test_in_with_stack_trace_itempotence(self):
4427
def test_in_with_ensure_traced_itempotence(self):
4528
exn = TracedException(MatchError(""), "")
4629
assert isinstance(TracedException.ensure_traced(exn).exception, MatchError)
30+
31+
32+
class TestMultipleExceptions(TestCase):
33+
@given(st.lists(st.lists(st.text())))
34+
def test_exns(self, l: List[str]):
35+
exceptions = [TracedException(MatchError(x), "") for x in l]
36+
assert MultipleExceptions.merge(*exceptions) == MultipleExceptions(
37+
exceptions=exceptions, errors=[]
38+
)
39+
40+
@given(st.lists(st.lists(st.text())))
41+
def test_list_of_lists(self, l: List[List[str]]):
42+
list_exceptions = [[TracedException(MatchError(x), "") for x in y] for y in l]
43+
expected = [exn for y in list_exceptions for exn in y]
44+
assert MultipleExceptions.merge(*list_exceptions) == MultipleExceptions(
45+
exceptions=expected, errors=[]
46+
)
47+
48+
@given(st.lists(st.lists(st.text())))
49+
def test_list_of_multiple(self, l: List[List[str]]):
50+
list_multiple = [
51+
MultipleExceptions.merge(*[TracedException(MatchError(x), "") for x in y])
52+
for y in l
53+
]
54+
expected = [TracedException(MatchError(x), "") for y in l for x in y]
55+
assert MultipleExceptions.merge(*list_multiple) == MultipleExceptions(
56+
exceptions=expected, errors=[]
57+
)

0 commit comments

Comments
 (0)