0002-formdef-prevent-hiding-of-EOFError-on-new-style-pick.patch
tests/test_formdef.py | ||
---|---|---|
259 | 259 |
formdef.fields = [] |
260 | 260 |
formdef.store() |
261 | 261 | |
262 |
obj = pickle.load(open(formdef.get_object_filename(), 'rb')) |
|
262 |
with open(formdef.get_object_filename(), 'rb') as fd: |
|
263 |
obj = FormDef.storage_load(fd) |
|
263 | 264 |
del obj.internal_identifier |
264 |
pickle.dump(obj, open(formdef.get_object_filename(), 'wb')) |
|
265 |
assert pickle.load(open(formdef.get_object_filename(), 'rb')).internal_identifier is None |
|
265 |
with open(formdef.get_object_filename(), 'wb') as fd: |
|
266 |
fd.write(FormDef.storage_dumps(obj)) |
|
267 |
with open(formdef.get_object_filename(), 'rb') as fd: |
|
268 |
assert pickle.load(fd).internal_identifier is None |
|
266 | 269 |
assert FormDef.get(formdef.id, ignore_migration=True).internal_identifier is None |
267 | 270 | |
268 | 271 |
formdef = FormDef.get(formdef.id) |
... | ... | |
621 | 624 |
assert formdef.fields[0].label == 'Test' |
622 | 625 |
assert formdef.workflow.possible_status[0].items[0].varname == 'blah' |
623 | 626 |
assert formdef.workflow.possible_status[0].items[0].formdef.fields[0].varname == 'str' |
627 | ||
628 | ||
629 |
def test_lightweight(pub): |
|
630 |
FormDef.wipe() |
|
631 |
formdef = FormDef() |
|
632 |
formdef.name = 'basic formdef' |
|
633 |
formdef.fields = [ |
|
634 |
StringField(id='1', label='Test', type='string', varname='foo'), |
|
635 |
] |
|
636 |
formdef.store() |
|
637 | ||
638 |
# load works |
|
639 |
FormDef.get(formdef.id) |
|
640 | ||
641 |
# truncate the pickle, now load should fail |
|
642 |
with open(formdef.get_object_filename(), 'rb+') as fd: |
|
643 |
pickle.load(fd) |
|
644 |
fd.truncate(fd.tell()) |
|
645 |
with pytest.raises(KeyError): |
|
646 |
FormDef.get(formdef.id) |
wcs/formdef.py | ||
---|---|---|
1550 | 1550 |
try: |
1551 | 1551 |
o.fields = pickle.load(fd, **PICKLE_KWARGS) |
1552 | 1552 |
except EOFError: |
1553 |
pass # old format |
|
1553 |
if isinstance(getattr(o, 'fields', None), list): |
|
1554 |
pass # old format |
|
1555 |
elif isinstance(o.__dict__.get(b'fields'), list): |
|
1556 |
pass # old format |
|
1557 |
else: |
|
1558 |
raise |
|
1554 | 1559 |
return o |
1555 | 1560 | |
1556 | 1561 |
@classmethod |
1557 |
- |