On Tue, Jan 24, 2012 at 12:07 AM, Simon King <[email protected]> wrote: > Hi! > > On 24 Jan., 08:22, tvn <[email protected]> wrote: >> I have this file 'myclass.py' that contains the following >> >> class MyClass(object): >> @staticmethod >> def myt(l): >> """ >> sage: from myclass import MyClass >> ... >> when run sage -t myclass.py , it gives errors about no module named >> myclass. (details below) > > It is known that the doctests won't find modules that are only present > in the "current" directory. > > "sage -t myclass.py" first takes myclass.py, extracts the tests, > transforms them into Python format (e.g., replace the "sage:" prompt > by Python's ">>>"), adds some stuff that Python needs to execute the > tests ("from sage import *" or so), and then puts the resulting > temporary file into a temporary directory and performs the tests > *there*. > > If I understand that correctly, when Python runs the tests on the > temporary file and executes "from myclass import MyClass" then it > would try to find the module "myclass" in that temporary directory, > but not in the directory in which you have put "myclass.py". In other > words, the "current" directory is not current when the actual tests > are performed on the temporary file.
WHY are the tests not current in the same directory? When I first wrote this testing system, I ran them in the current directory, which was why this example used to work fine. What was the big motivation to change things? I definitely consider it a serious regression that the original poster's example no longer works. But there must be some good reason behind why it doesn't, which I would like to understand. The ticket John posted to looks like it might fix this example, but still the tests are run elsewhere, so it's only a half-broken fix. If you had *two* .py files, and one imports the other, then everything would be broken again. > > So, you should provide a fully qualified path in your test, or should > put myclass.py into the Sage library. > > Question (perhaps better to sage-devel): It should be possible that > "sage -t myclass.py" finds out the location of myclass.py and adds it > to the Python path - which would probably be enough to solve the > problem. Would that be a reasonable addition to the test framework? > > Cheers, > Simon > > -- > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org -- William Stein Professor of Mathematics University of Washington http://wstein.org -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
