mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-25 09:32:29 +00:00
Fixed pickling error in py2.7
This commit is contained in:
parent
ea91e3e4a4
commit
0f89b92457
@ -98,7 +98,7 @@ class ShelfMixin(object):
|
|||||||
if os.path.isfile(self.shelf_file):
|
if os.path.isfile(self.shelf_file):
|
||||||
try:
|
try:
|
||||||
self.__dict__['_sh'] = pickle.load(open(self.shelf_file, 'rb'))
|
self.__dict__['_sh'] = pickle.load(open(self.shelf_file, 'rb'))
|
||||||
except (EOFError, pickle.UnpicklingError):
|
except (IndexError, EOFError, pickle.UnpicklingError):
|
||||||
logger.warning('{} has a corrupted shelf file!'.format(self.id))
|
logger.warning('{} has a corrupted shelf file!'.format(self.id))
|
||||||
if not self.get('force_shelf', False):
|
if not self.get('force_shelf', False):
|
||||||
raise
|
raise
|
||||||
|
@ -91,8 +91,8 @@ class PluginsTest(TestCase):
|
|||||||
with open(emptyfile, 'w+b'), open(invalidfile, 'w+b') as inf:
|
with open(emptyfile, 'w+b'), open(invalidfile, 'w+b') as inf:
|
||||||
inf.write(b'ohno')
|
inf.write(b'ohno')
|
||||||
|
|
||||||
files = {emptyfile: ['empty file', EOFError],
|
files = {emptyfile: ['empty file', (EOFError, IndexError)],
|
||||||
invalidfile: ['invalid file', pickle.UnpicklingError]}
|
invalidfile: ['invalid file', (pickle.UnpicklingError, IndexError)]}
|
||||||
|
|
||||||
for fn in files:
|
for fn in files:
|
||||||
with open(fn, 'rb') as f:
|
with open(fn, 'rb') as f:
|
||||||
@ -105,7 +105,6 @@ class PluginsTest(TestCase):
|
|||||||
assert os.path.isfile(a.shelf_file)
|
assert os.path.isfile(a.shelf_file)
|
||||||
print('Shelf file: %s' % a.shelf_file)
|
print('Shelf file: %s' % a.shelf_file)
|
||||||
with self.assertRaises(error):
|
with self.assertRaises(error):
|
||||||
# By default, raise an error
|
|
||||||
a.sh['a'] = 'fromA'
|
a.sh['a'] = 'fromA'
|
||||||
a.save()
|
a.save()
|
||||||
del a._sh
|
del a._sh
|
||||||
|
Loading…
Reference in New Issue
Block a user