1
1
from unittest import TestCase
2
2
3
- from raffiot .utils import *
3
+ import hypothesis .strategies as st
4
+ from hypothesis import given
4
5
5
- x = 5
6
- y = 6
7
- z = 7
6
+ from raffiot .utils import *
7
+ from typing import List
8
8
9
9
10
10
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
17
14
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
33
16
34
17
35
18
class TestTracedException (TestCase ):
@@ -44,3 +27,31 @@ def test_in_with_stack_trace_itempotence(self):
44
27
def test_in_with_ensure_traced_itempotence (self ):
45
28
exn = TracedException (MatchError ("" ), "" )
46
29
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