|
7 | 7 | from zarr.util import (guess_chunks, human_readable_size, info_html_report,
|
8 | 8 | info_text_report, is_total_slice, normalize_chunks,
|
9 | 9 | normalize_fill_value, normalize_order,
|
10 |
| - normalize_resize_args, normalize_shape, |
| 10 | + normalize_resize_args, normalize_shape, retry_call, |
11 | 11 | tree_array_icon, tree_group_icon, tree_get_icon,
|
12 | 12 | tree_widget)
|
13 | 13 |
|
@@ -175,3 +175,30 @@ def test_tree_widget_missing_ipytree():
|
175 | 175 | )
|
176 | 176 | with pytest.raises(ImportError, match=re.escape(pattern)):
|
177 | 177 | tree_widget(None, None, None)
|
| 178 | + |
| 179 | + |
| 180 | +def test_retry_call(): |
| 181 | + |
| 182 | + class Fixture: |
| 183 | + |
| 184 | + def __init__(self, pass_on=1): |
| 185 | + self.c = 0 |
| 186 | + self.pass_on = pass_on |
| 187 | + |
| 188 | + def __call__(self): |
| 189 | + self.c += 1 |
| 190 | + if self.c != self.pass_on: |
| 191 | + raise PermissionError() |
| 192 | + |
| 193 | + for x in range(1, 11): |
| 194 | + # Any number of failures less than 10 will be accepted. |
| 195 | + fixture = Fixture(pass_on=x) |
| 196 | + retry_call(fixture, exceptions=(PermissionError,), wait=0) |
| 197 | + assert fixture.c == x |
| 198 | + |
| 199 | + def fail(x): |
| 200 | + # Failures after 10 will cause an error to be raised. |
| 201 | + retry_call(Fixture(pass_on=x), exceptions=(Exception,), wait=0) |
| 202 | + |
| 203 | + for x in range(11, 15): |
| 204 | + pytest.raises(PermissionError, fail, x) |
0 commit comments