Skip to content

Commit

Permalink
trac #6233 -- remove the explain_picklejar function, since it is self…
Browse files Browse the repository at this point in the history
… contained and its test fails on all platforms
  • Loading branch information
williamstein committed Jun 6, 2009
1 parent fdc3e2e commit f1ea7b0
Showing 1 changed file with 92 additions and 92 deletions.
184 changes: 92 additions & 92 deletions src/sage/misc/explain_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2381,98 +2381,98 @@ def UNICODE(self, s):
"""
self.push_and_share(self.sib(s))

def explain_picklejar(dir, catch_exceptions=True):
r"""
Given a directory or a .tar.bz2 of pickles, we unpickle each of
them three times: once with cPickle, once with explain_pickle
with in_current_sage=True, and once with explain_pickle
with in_current_sage=False.
We verify that each of these gives the same answer (where we check
using repr(a)==repr(b), in case equality is not defined on all
of these objects).
INPUT::
dir -- string; a directory or name of a .tar.bz2 file that
decompresses to give a directory full of pickles.
catch_exceptions -- boolean; default True: if True, then
unpickling exceptions will be caught (and if all three
unpicklers raise an exception, then that will be counted
as a match). If False, then exceptions will not be caught,
and will terminate this function.
EXAMPLES:
sage: std = os.environ['SAGE_DATA'] + '/extcode/pickle_jar/pickle_jar.tar.bz2'
sage: from sage.misc.explain_pickle import *
sage: explain_picklejar(std) # long time (~45s on my computer)
doctest:...: DeprecationWarning: Your data is stored in an old format. Please use the save() function to store your data in a more recent format.
doctest:...: DeprecationWarning: Your data is stored in an old format. Please use the save() function to store your data in a more recent format.
doctest:...: DeprecationWarning: RQDF is deprecated; use RealField(212) instead.
doctest:...: DeprecationWarning: RQDF is deprecated; use RealField(212) instead.
doctest:...: DeprecationWarning: RQDF is deprecated; use RealField(212) instead.
4... matches; 0 mismatches
"""
# Largely copied from unpickle_all in sage_object.pyx

from sage.structure.sage_object import load

obj_at = re.compile('object at 0x[0-9a-f]+')

n_success = 0
failed = []
if dir.endswith('.tar.bz2'):
# create a temporary directory
from sage.misc.all import tmp_dir
T = tmp_dir()
# extract tarball to it
os.system('cd "%s"; bunzip2 -c "%s" | tar fx - '%(T, os.path.abspath(dir)))
# Now use the directory in the tarball instead of dir
dir = T + "/" + os.listdir(T)[0]

for A in os.listdir(dir):
if A.endswith('.sobj'):
fn = dir + '/' + A
try:
v1 = load(fn)
v1r = repr(v1)
except Exception, msg:
# if not catch_exceptions: raise
v1r = 'error'

try:
exp_current = explain_pickle(file=fn, in_current_sage=True)
import sys
sys.stderr.write(exp_current)
v2 = sage_eval(exp_current)
v2r = repr(v2)
except Exception, msg:
if not catch_exceptions: raise
v2r = 'error'

try:
exp_generic = explain_pickle(file=fn)
import sys
sys.stderr.write(exp_generic)
v3 = sage_eval(exp_generic)
v3r = repr(v3)
except Exception, msg:
if not catch_exceptions: raise
v3r = 'error'

v1r = obj_at.sub('object at 0x...', v1r)
v2r = obj_at.sub('object at 0x...', v2r)
v3r = obj_at.sub('object at 0x...', v3r)

if v1r == v2r == v3r:
n_success += 1
else:
print "Mismatch on %s" % fn
print v1r, v2r, v3r
failed.append(A)

print "%d matches; %d mismatches" % (n_success, len(failed))
print '\n'.join(failed)
# def explain_picklejar(dir, catch_exceptions=True):
# r"""
# Given a directory or a .tar.bz2 of pickles, we unpickle each of
# them three times: once with cPickle, once with explain_pickle
# with in_current_sage=True, and once with explain_pickle
# with in_current_sage=False.

# We verify that each of these gives the same answer (where we check
# using repr(a)==repr(b), in case equality is not defined on all
# of these objects).

# INPUT::

# dir -- string; a directory or name of a .tar.bz2 file that
# decompresses to give a directory full of pickles.
# catch_exceptions -- boolean; default True: if True, then
# unpickling exceptions will be caught (and if all three
# unpicklers raise an exception, then that will be counted
# as a match). If False, then exceptions will not be caught,
# and will terminate this function.

# EXAMPLES:
# sage: std = os.environ['SAGE_DATA'] + '/extcode/pickle_jar/pickle_jar.tar.bz2'
# sage: from sage.misc.explain_pickle import *
# sage: explain_picklejar(std) # long time (~45s on my computer)
# doctest:...: DeprecationWarning: Your data is stored in an old format. Please use the save() function to store your data in a more recent format.
# doctest:...: DeprecationWarning: Your data is stored in an old format. Please use the save() function to store your data in a more recent format.
# doctest:...: DeprecationWarning: RQDF is deprecated; use RealField(212) instead.
# doctest:...: DeprecationWarning: RQDF is deprecated; use RealField(212) instead.
# doctest:...: DeprecationWarning: RQDF is deprecated; use RealField(212) instead.
# 4... matches; 0 mismatches
# """
# # Largely copied from unpickle_all in sage_object.pyx

# from sage.structure.sage_object import load

# obj_at = re.compile('object at 0x[0-9a-f]+')

# n_success = 0
# failed = []
# if dir.endswith('.tar.bz2'):
# # create a temporary directory
# from sage.misc.all import tmp_dir
# T = tmp_dir()
# # extract tarball to it
# os.system('cd "%s"; bunzip2 -c "%s" | tar fx - '%(T, os.path.abspath(dir)))
# # Now use the directory in the tarball instead of dir
# dir = T + "/" + os.listdir(T)[0]

# for A in os.listdir(dir):
# if A.endswith('.sobj'):
# fn = dir + '/' + A
# try:
# v1 = load(fn)
# v1r = repr(v1)
# except Exception, msg:
# # if not catch_exceptions: raise
# v1r = 'error'

# try:
# exp_current = explain_pickle(file=fn, in_current_sage=True)
# import sys
# sys.stderr.write(exp_current)
# v2 = sage_eval(exp_current)
# v2r = repr(v2)
# except Exception, msg:
# if not catch_exceptions: raise
# v2r = 'error'

# try:
# exp_generic = explain_pickle(file=fn)
# import sys
# sys.stderr.write(exp_generic)
# v3 = sage_eval(exp_generic)
# v3r = repr(v3)
# except Exception, msg:
# if not catch_exceptions: raise
# v3r = 'error'

# v1r = obj_at.sub('object at 0x...', v1r)
# v2r = obj_at.sub('object at 0x...', v2r)
# v3r = obj_at.sub('object at 0x...', v3r)

# if v1r == v2r == v3r:
# n_success += 1
# else:
# print "Mismatch on %s" % fn
# print v1r, v2r, v3r
# failed.append(A)

# print "%d matches; %d mismatches" % (n_success, len(failed))
# print '\n'.join(failed)

# Helper routines for explain_pickle

Expand Down

0 comments on commit f1ea7b0

Please sign in to comment.