Addendum: re the "last paragraph" (which begins with "Now, here's one thing"), it's not just m and loads(dumps(m)) that have different types, but also the factories that produce them. That certainly explains why m is not loads(dumps(m)), but isn't it a bug in the doctesting?
On Sunday, April 21, 2013 5:24:21 PM UTC-5, Rob H. wrote: > > Hi, > > (To begin, I'm running the following on sage 5.7 on Mac OS X 10.6.8). > (Also, maybe this is related to > http://trac.sagemath.org/sage_trac/ticket/12415). > > I'm trying to write some documentation for some code I've written and am > having trouble testing the pickling. My classes inherit from Module (and > the element classes inherit from ModuleElement) and they have associated > UniqueFactory objects that construct them. Without defining any __reduce__ > or __cmp__ methods for the parents, some of the pickling works and some of > it doesn't. Here's what I mean. > > I have a class, let's call it M with factory MFactory such that I get the > following in an instance of sage: > > sage: m = MFactory(whatever) > sage: loads(dumps(m)) is m > True > > Which would lead me to believe pickling works. However, if I add those > lines into a doctest, that doctest fails (and it fails with '==' instead of > 'is', as well). Similarly: > > sage: TestSuite(m).run() > > is fine, but if I put that in a doctest, it fails because the pickling > test fails. > > Also: > > sage: save(m, 'm.obj') > sage: m2 = load('m.obj') > sage: m2 is m > True > > This works (and I can even restart sage and the load statement works and > seems to give back the same object). But again, fails in the doctest. > > Now, one thing I did was write a separate function: > > def TESTER(): > from sage.structure.sage_object import loads, dumps > m = MFactory(whatever) > return loads(dumps(m)) is m > > And added the following to a doctest: > > sage: TESTER() > True > > And that worked! > > So, picklng the class in sage or in a function called from a doctest both > work, as well as running the TestSuite in sage, but doctesting directly or > using TestSuite in a doctest both don't work. So, it seems like the > doctests fail even though if anyone were to use this class in anything then > it would always work. I have another class that I've written for which all > this stuff does work, including the doctests. > > Now, here's one thing that I've noticed which is that the difference > between m and loads(dumps(m)) seems to be that they are not of the same > class. The latter is of the type I would expect whereas m is of type > "filename_somenumbers_orig.M". This is why I think this may be relate to > http://trac.sagemath.org/sage_trac/ticket/12415 . > > Does anyone know what's going on? > > Thanks! > > Rob > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.