Skip to content

Commit

Permalink
test: catch: test 'when'
Browse files Browse the repository at this point in the history
  • Loading branch information
ebonnal committed Nov 30, 2023
1 parent 08a7cc0 commit 2290a63
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ def store_errors(error):
set(
Pipe(["1", "r", "2"].__iter__)
.map(int, n_threads=n_threads)
.catch(Exception, when=lambda error: "invalid literal for int() with base 10:" not in str(error))
.catch(Exception, when=store_errors)
.map(type)
),
Expand All @@ -380,12 +381,20 @@ def store_errors(error):
self.assertEqual(len(errors), 1)
self.assertIsInstance(next(iter(errors)), ValueError)

# ignore = False
self.assertRaises(
ValueError,
(
Pipe(["1", "r", "2"].__iter__)
.map(int, n_threads=n_threads)
.catch(ValueError, when=lambda error: False)
.collect
),
)
self.assertListEqual(
list(
Pipe(["1", "r", "2"].__iter__)
.map(int, n_threads=n_threads)
.catch(ValueError)
.catch(ValueError, when=lambda error: "invalid literal for int() with base 10:" in str(error))
.map(type)
),
[int, int],
Expand Down

0 comments on commit 2290a63

Please sign in to comment.