From 431441f0d6134c02a7cd3d9931d52f5ffc7a89d8 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Mon, 27 Jun 2016 22:00:24 +0200 Subject: [PATCH] input_io_* tests --- borg/testsuite/archive.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/borg/testsuite/archive.py b/borg/testsuite/archive.py index 919d57a0c..229ff8bda 100644 --- a/borg/testsuite/archive.py +++ b/borg/testsuite/archive.py @@ -5,6 +5,7 @@ import pytest from ..archive import Archive, CacheChunkBuffer, RobustUnpacker, valid_msgpacked_dict, ITEM_KEYS +from ..archive import InputOSError, input_io, input_io_iter from ..key import PlaintextKey from ..helpers import Manifest from . import BaseTestCase @@ -145,3 +146,27 @@ def test_key_length_msgpacked_items(): data = {key: b''} item_keys_serialized = [msgpack.packb(key), ] assert valid_msgpacked_dict(msgpack.packb(data), item_keys_serialized) + + +def test_input_io(): + with pytest.raises(InputOSError): + with input_io(): + raise OSError(123) + + +def test_input_io_iter(): + class Iterator: + def __init__(self, exc): + self.exc = exc + + def __next__(self): + raise self.exc() + + oserror_iterator = Iterator(OSError) + with pytest.raises(InputOSError): + for _ in input_io_iter(oserror_iterator): + pass + + normal_iterator = Iterator(StopIteration) + for _ in input_io_iter(normal_iterator): + assert False, 'StopIteration handled incorrectly'