summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Greenan <kmg@box.com>2015-04-06 12:52:03 -0700
committerKevin Greenan <kmg@box.com>2015-04-06 12:52:03 -0700
commit88c46cc3ac30fca2204080ba2af99f66e7bf8acf (patch)
tree5165e68c180ba9c5ca93cfe7988cc32bd965cfb1
parent65976eb0cc749c0ac245c6b0e6a3e830e60ce0a8 (diff)
downloadpyeclib-88c46cc3ac30fca2204080ba2af99f66e7bf8acf.tar.gz
Revert "Merged in bloodeagle40234/pyeclib/fix-error-handling (pull request #22)"
This reverts commit 65976eb0cc749c0ac245c6b0e6a3e830e60ce0a8, reversing changes made to 29c20a8d23d81e7c12546c3e3cf7b91d4061bcf7.
-rw-r--r--pyeclib/ec_iface.py8
-rw-r--r--test/test_pyeclib_api.py44
2 files changed, 3 insertions, 49 deletions
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 4785d18..fbe82f0 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -112,12 +112,8 @@ class PyECLib_FRAGHDRCHKSUM_Types(PyECLibEnum):
# Generic ECDriverException
class ECDriverError(Exception):
- def __init__(self, error):
- try:
- self.error_str = str(error)
- except TypeError:
- self.error_str = 'Error retrieving the error message from %s' \
- % error.__class__.__name__
+ def __init__(self, error_str):
+ self.error_str = error_str
def __str__(self):
return self.error_str
diff --git a/test/test_pyeclib_api.py b/test/test_pyeclib_api.py
index 1e1be44..71552c1 100644
--- a/test/test_pyeclib_api.py
+++ b/test/test_pyeclib_api.py
@@ -26,14 +26,12 @@ from string import ascii_letters, ascii_uppercase, digits
import sys
import tempfile
import unittest
-import mock
from pyeclib.ec_iface import ECDriverError
from pyeclib.ec_iface import ECDriver, VALID_EC_TYPES, ECDriverError, \
PyECLib_EC_Types
from test_pyeclib_c import _available_backends
import pyeclib_c
-from pyeclib_c import error as PyECLibError
if sys.version < '3':
def b2i(b):
@@ -209,7 +207,7 @@ class TestPyECLibDriver(unittest.TestCase):
def test_get_metadata_formatted(self):
pyeclib_driver = ECDriver(k=12, m=2, ec_type="jerasure_rs_vand", chksum_type="inline_crc32")
-
+
filesize = 1024 * 1024 * 3
file_str = ''.join(random.choice(ascii_letters) for i in range(filesize))
file_bytes = file_str.encode('utf-8')
@@ -549,45 +547,5 @@ class TestPyECLibDriver(unittest.TestCase):
self.assertTrue(
pyeclib_drivers[0].min_parity_fragments_needed() == 1)
- def test_ECDriver_error_handling(self):
- driver = ECDriver(k=3, m=1, ec_type="jerasure_rs_vand")
-
- class MockPyECLibError(PyECLibError):
- def __str__(self):
- return mock.MagicMock()
-
- with mock.patch('pyeclib_c.decode', side_effect=MockPyECLibError()):
- with self.assertRaises(ECDriverError) as cm:
- driver.decode([' ' for x in xrange(4)])
- exception = cm.exception
- expected = 'Error retrieving the error message from MockPyECLibError'
- self.assertEquals(expected, str(exception))
-
- def test_ECDriverError_init(self):
-
- class mock_class(object):
- def __init__(self, return_str):
- self.return_str = return_str
-
- def __str__(self):
- if self.return_str:
- return 'message'
- else:
- return mock.MagicMock()
-
- # init with str
- error = ECDriverError('message')
- self.assertEquals('message', str(error))
-
- # init with instance with valid __str__
- error = ECDriverError(mock_class(True))
- self.assertEquals('message', str(error))
-
- # init with instance with invalid __str__
- error = ECDriverError(mock_class(False))
- self.assertEquals('Error retrieving the error message from mock_class',
- str(error))
-
-
if __name__ == '__main__':
unittest.main()