summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2017-05-02 15:47:41 -0700
committerTim Burke <tim.burke@gmail.com>2017-05-02 16:07:56 -0700
commitf990e62dc05c46e323019ca0267e5564c3cf15a7 (patch)
treedfa5b65a538d3d9d4684288ce7c5756a2ac9d546
parentb52657606572740359ead8b6892d744a05e9dc2c (diff)
downloadpyeclib-f990e62dc05c46e323019ca0267e5564c3cf15a7.tar.gz
Clean up ECDriver
- Add a docstring, since I can never remember the **kwargs. - Drop the (unused) *args. - Raise an error earlier if neither ec_type nor library_import_str is provided. Change-Id: I38b71ede59b6b0e249223792207b0f48438f7b97
-rw-r--r--pyeclib/ec_iface.py23
-rw-r--r--test/test_pyeclib_api.py13
2 files changed, 31 insertions, 5 deletions
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 59bf1fb..cc9c516 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -142,8 +142,22 @@ class PyECLib_FRAGHDRCHKSUM_Types(PyECLibEnum):
# Main ECDriver class
class ECDriver(object):
-
- def __init__(self, *args, **kwargs):
+ '''A driver to encode, decode, and reconstruct erasure-coded data.'''
+
+ def __init__(self, **kwargs):
+ '''
+ :param ec_type: the erasure coding type to use for this driver.
+ :param k: number of data fragments to use. Required.
+ :param m: number of parity fragments to use. Required.
+ :param chksum_type:
+ :param validate: default: False
+ :param library_import_str: default: 'pyeclib.core.ECPyECLibDriver'
+
+ You must provide either ``ec_type`` or ``library_import_str``;
+ typically you just want to use ``ec_type``. See ALL_EC_TYPES for the
+ list of all EC types supported by PyECLib, and VALID_EC_TYPES for the
+ list of all EC types currently available on this system.
+ '''
self.k = -1
self.m = -1
self.hd = -1
@@ -156,6 +170,11 @@ class ECDriver(object):
raise ECDriverError(
"Invalid Argument: %s is required" % required)
+ if 'ec_type' not in kwargs and 'library_import_str' not in kwargs:
+ raise ECDriverError(
+ "Invalid Argument: either ec_type or library_import_str "
+ "must be provided")
+
for (key, value) in kwargs.items():
if key == "k":
try:
diff --git a/test/test_pyeclib_api.py b/test/test_pyeclib_api.py
index 9585035..085a480 100644
--- a/test/test_pyeclib_api.py
+++ b/test/test_pyeclib_api.py
@@ -117,22 +117,29 @@ class TestPyECLibDriver(unittest.TestCase):
def tearDown(self):
pass
- def test_invalid_km_args(self):
+ def test_missing_required_args(self):
+ # missing ec_type
+ with self.assertRaises(ECDriverError) as err_context:
+ ECDriver(k=1, m=1)
+ self.assertEqual(str(err_context.exception),
+ "Invalid Argument: either ec_type or "
+ "library_import_str must be provided")
+
for ec_type in VALID_EC_TYPES:
# missing k
with self.assertRaises(ECDriverError) as err_context:
ECDriver(ec_type=ec_type, m=1)
-
self.assertEqual(str(err_context.exception),
"Invalid Argument: k is required")
# missing m
with self.assertRaises(ECDriverError) as err_context:
ECDriver(ec_type=ec_type, k=1)
-
self.assertEqual(str(err_context.exception),
"Invalid Argument: m is required")
+ def test_invalid_km_args(self):
+ for ec_type in VALID_EC_TYPES:
with self.assertRaises(ECDriverError) as err_context:
# k is smaller than 1
ECDriver(ec_type=ec_type, k=-100, m=1)