Apparently the problem here (what I should have thought of first) is that the directory containing foo.py is not in my sage python path. The surprising (to me) part, and the reason I didn't think of it, is that this breaks things even if the file I'm testing is foo.py and I try 'from foo import *'. So it seems the only remedy (for now, since I understand SAGE overrides my PYTHONPATH variable) is something like
sage: import sys sage: mypath= '/mydir/' sage: if mypath not in sys.path: sys.path.append(mypath) where /mydir/ is the path to foo.py. This works, but doesn't seem like a good solution, and is, I think, another good reason to allow the user to modify sage's startup pythonpath. -David On Aug 30, 8:32 pm, David Ketcheson <[EMAIL PROTECTED]> wrote: > Sorry for not being clear. myfoo.py is the file with the docstring > examples I want to test. foo.py is the file with the modules I need > to import. > > Let me add that sometimes they're the same file, and it doesn't work > in that case either. > > On Aug 30, 8:08 pm, Robert Bradshaw <[EMAIL PROTECTED]> > wrote: > > > On Aug 30, 2008, at 3:33 PM, David Ketcheson wrote: > > > > I'm developing a package and trying to use sage -t to automatically > > > test examples I've put in the docstrings. On the documentation page > > > athttp://www.sagemath.org/doc/prog/node29.htmlitsays I can do > > > something like > > > > """ > > > EXAMPLES: > > > > sage: from foo import * > > > """ > > > > where foo is not part of Sage. However, supposing the above is in the > > > file myfoo.py, if I type > > > > sage -t myfoo.py > > > > I get the error > > > > ********************************************************************** > > > File "/Applications/sage/tmp/myfoo.py", line 8: > > > sage: from foo import * > > > Exception raised: > > > Traceback (most recent call last): > > > File "/Applications/sage/local/lib/python/doctest.py", line > > > 1228, in __run > > > compileflags, 1) in test.globs > > > File "<doctest __main__.example_0[1]>", line 1, in <module> > > > from foo import *###line 8: > > > sage: from foo import * > > > ImportError: No module named foo > > > ********************************************************************** > > > > Also, the documentation says a .doctest directory is created and has a > > > file .doctest_myfoo.py that I can inspect, but I cannot find any such > > > thing. I'd be very grateful for any help. > > > If you file is named myfoo.py, you have to do "from myfoo imoprt *" > > > - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---