| 1 |
import pickle |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from conda_package_handling.exceptions import ( |
| 6 |
CaseInsensitiveFileSystemError, |
| 7 |
ConversionError, |
| 8 |
InvalidArchiveError, |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
@pytest.mark.parametrize( |
| 13 |
("error_type", "constructor_args"), |
| 14 |
( |
| 15 |
(InvalidArchiveError, ("archive.conda", "invalid archive")), |
| 16 |
(CaseInsensitiveFileSystemError, ("archive.conda", "destination")), |
| 17 |
(ConversionError, (["missing"], ["mismatched"], "extra context")), |
| 18 |
), |
| 19 |
ids=( |
| 20 |
"InvalidArchiveError", |
| 21 |
"CaseInsensitiveFileSystemError", |
| 22 |
"ConversionError", |
| 23 |
), |
| 24 |
) |
| 25 |
def test_exception_pickle_round_trip(mocker, error_type, constructor_args): |
| 26 |
error = error_type(*constructor_args) |
| 27 |
error.extra_state = {"preserved": True} |
| 28 |
init = mocker.spy(error_type, "__init__") |
| 29 |
|
| 30 |
restored = pickle.loads(pickle.dumps(error)) |
| 31 |
|
| 32 |
init.assert_called_once_with(restored, *constructor_args) |
| 33 |
assert type(restored) is type(error) |
| 34 |
assert restored.args == error.args |
| 35 |
assert str(restored) == str(error) |
| 36 |
assert vars(restored) == vars(error) |