mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-08 03:14:21 +00:00
pyfec: fix some error-checking, add more unit tests
This commit is contained in:
parent
dc25f327a3
commit
bac74e4353
@ -151,10 +151,14 @@ Encoder_encode(Encoder *self, PyObject *args) {
|
||||
unsigned c_desired_shares_ids[self->mm];
|
||||
unsigned c_desired_checkshares_ids[self->mm - self->kk];
|
||||
unsigned i;
|
||||
PyObject* fastinshares = NULL;
|
||||
|
||||
for (i=0; i<self->mm - self->kk; i++)
|
||||
pystrs_produced[i] = NULL;
|
||||
if (desired_shares_ids) {
|
||||
fast_desired_shares_ids = PySequence_Fast(desired_shares_ids, "Second argument (optional) was not a sequence.");
|
||||
if (!fast_desired_shares_ids)
|
||||
goto err;
|
||||
num_desired_shares = PySequence_Fast_GET_SIZE(fast_desired_shares_ids);
|
||||
fast_desired_shares_ids_items = PySequence_Fast_ITEMS(fast_desired_shares_ids);
|
||||
for (i=0; i<num_desired_shares; i++) {
|
||||
@ -173,7 +177,7 @@ Encoder_encode(Encoder *self, PyObject *args) {
|
||||
num_check_shares_produced = self->mm - self->kk;
|
||||
}
|
||||
|
||||
PyObject* fastinshares = PySequence_Fast(inshares, "First argument was not a sequence.");
|
||||
fastinshares = PySequence_Fast(inshares, "First argument was not a sequence.");
|
||||
if (!fastinshares)
|
||||
goto err;
|
||||
|
||||
|
@ -101,20 +101,42 @@ def test_random():
|
||||
def test_bad_args_enc():
|
||||
encer = fec.Encoder(2, 4)
|
||||
try:
|
||||
encer.encode(["a", "b", ], ["c", "d",])
|
||||
encer.encode(["a", "b", ], ["c", "I am not an integer shareid",])
|
||||
except fec.Error, e:
|
||||
assert "econd argument is required to contain int" in str(e), e
|
||||
assert "Precondition violation: second argument is required to contain int" in str(e), e
|
||||
else:
|
||||
raise "Should have gotten fec.Error for wrong type of second argument."
|
||||
|
||||
try:
|
||||
encer.encode(["a", "b", ], 98) # not a sequence at all
|
||||
except TypeError, e:
|
||||
assert "Second argument (optional) was not a sequence" in str(e), e
|
||||
else:
|
||||
raise "Should have gotten TypeError for wrong type of second argument."
|
||||
|
||||
def test_bad_args_dec():
|
||||
decer = fec.Decoder(2, 4)
|
||||
|
||||
try:
|
||||
decer.decode(98, [0, 1]) # first argument is not a sequence
|
||||
except TypeError, e:
|
||||
assert "First argument was not a sequence" in str(e), e
|
||||
else:
|
||||
raise "Should have gotten TypeError for wrong type of second argument."
|
||||
|
||||
try:
|
||||
decer.decode(["a", "b", ], ["c", "d",])
|
||||
except fec.Error, e:
|
||||
assert "econd argument is required to contain int" in str(e), e
|
||||
assert "Precondition violation: second argument is required to contain int" in str(e), e
|
||||
else:
|
||||
raise "Should have gotten fec.Error for wrong type of second argument."
|
||||
|
||||
try:
|
||||
decer.decode(["a", "b", ], 98) # not a sequence at all
|
||||
except TypeError, e:
|
||||
assert "Second argument was not a sequence" in str(e), e
|
||||
else:
|
||||
raise "Should have gotten TypeError for wrong type of second argument."
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user