[Tutor] composing one test suite from two test cases
How to create a single unittest test suite class that runs all methods from multiple TestCase classes? Why I ask: I'm trying to relearn TDD and learn Python by coding a simple app. Currently the app has 2 simple functional classes, Pid and TallyPid, and 2 very simple testcases, PidTests and TallyPidTests: http://www.unc.edu/~tr/courses/ENVR400/Pid.py http://www.unc.edu/~tr/courses/ENVR400/PidTests.py http://www.unc.edu/~tr/courses/ENVR400/Tally.py http://www.unc.edu/~tr/courses/ENVR400/TallyPidTests.py I can run both testcases > >python PidTests.py > > -- > Ran 20 tests in 0.000s > OK > >python TallyPidTests.py > . > -- > Ran 1 test in 0.563s > OK Before I continue, I'd like to create a single suite, in a separate cfile file/module (e.g. AllTests.py), that will run both testcases (PidTests.py and TallyPidTests.py). Unfortunately I have not been able to do this! which surprises me, since creating such a suite in JUnit is trivial. Can someone show me how to create this suite in python? (FWIW the python version=2.5.2: downlevel, I know, but the box also needs to run ArcGIS.) TIA, Tom Roche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] composing one test suite from two test cases
Tom Roche Sun, Jan 10, 2010 at 10:44 PM >> How to create a single unittest test suite class that runs all >> methods from multiple TestCase classes? Kent Johnson Mon, 11 Jan 2010 06:42:39 -0500 > The supported way to do this is to create a test suite. There is an > example here: > http://docs.python.org/library/unittest.html#organizing-test-code Yes, I saw that, in particular http://docs.python.org/library/unittest.html#organizing-test-code >>> unittest provides a TestLoader class that can be used to automate >>> the process of creating a test suite and populating it with >>> individual tests. For example, >>> suite = unittest.TestLoader().loadTestsFromTestCase(WidgetTestCase) >>> will create a test suite that will run >>> WidgetTestCase.testDefaultSize() and WidgetTestCase.testResize. ... >>> TestSuite instances can be added to a TestSuite just as TestCase >>> instances can be added to a TestSuite: >>> suite1 = module1.TheTestSuite() >>> suite2 = module2.TheTestSuite() >>> alltests = unittest.TestSuite([suite1, suite2]) but I couldn't get AllTests.py to run: I kept getting errors about "unbound method", "no such test method", class/instance problems, etc. Thanks to your assistance, I suspect my key faults were: * namespace: I was doing - import PidTests - import TallyPidTests instead of + from PidTests import PidTests + from TallyPidTests import TallyPidTests * not encapsulating the TestSuite-adding code in another suite() The only thing your code was missing was the main(), but that was easy to add. (The complete AllTests.py that runs for me follows my .sig) > However I don't recommend this style of organizing tests. I prefer > using nose for test discovery, it saves the work of creating all the > aggregating suites. I've heard of Nose and am planning to try it, but for now I thought I'd "do the simplest thing that could possibly work." > I think py.test also has a test discovery component. In Python 2.7 > the unittest module will finally have it's own test discovery. > http://somethingaboutorange.com/mrl/projects/nose/0.11.1/finding_tests.html > http://docs.python.org/dev/library/unittest.html#test-discovery Thanks again, Tom Roche ---AllTests.py follows--- import unittest from PidTests import PidTests from TallyPidTests import TallyPidTests class AllTests(unittest.TestCase): def suite(): suite1 = unittest.TestLoader().loadTestsFromTestCase(PidTests) suite2 = unittest.TestLoader().loadTestsFromTestCase(TallyPidTests) return unittest.TestSuite([suite1, suite2]) def main(): unittest.main() if __name__ == '__main__': main() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] bind line-oriented device output?
I'd like to learn to pythonically redirect the output from a line-oriented character device to a particular file or process, regardless of focus, on a generic graphical OS. But I don't want to redirect stdin entirely. Here's the usecase: My school has a seminar for which we record attendance by scanning the student ID card, or rather the barcode on its back, with a handheld USB scanner. This is pretty straightforward, except that the barcode scanner is like a keyboard writing the ASCII equivalent of the barcode (== the student's ID#) to stdin. FWIW, the scanner writes lines: I'm not sure if EOL is \r, \n, or \r\n, but I suspect the latter. Since the scanner is connected to an ordinary multiprocessing laptop on which one will likely be doing other things while scanning (notably setting up to record the presenter), it sometimes happens (especially until one learns to pay attention to this) that one writes to a frame other than the text file into which we want record attendee ID#s. This semester recurs every {fall, spring}, so someone faces this {pitfall, learning curve} at regular intervals. How to prevent writing the wrong target? One trivial solution--shlep a dedicated USB host for the scanner--is deprecated. An OS-specific solution (e.g. relying on a linux raw device) is also undesirable: I use ubuntu, but others will probably use mac or windows. Rather, It Would Be Nice, and useful for this seminar's mechanics, to be able to run some code to which one could say, see this device? and this file? Make the device's output go only to that file. For extra credit, don't let anything else write that file while this code is running. Can python do that? Or does one need to get closer to the metal? TIA, Tom Roche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] bind line-oriented device output?
http://mail.python.org/pipermail/tutor/2010-March/075438.html >> I'd like to learn to pythonically redirect the output from a >> line-oriented character device to a particular file or process, >> regardless of focus, on a generic graphical OS. But I don't want to >> redirect stdin entirely. ... >> It Would Be Nice, and useful for this seminar's mechanics, to be >> able to run some code to which one could say, see this device? and >> this file? Make the device's output go only to that file. For extra >> credit, don't let anything else write that file while this code is >> running. http://mail.python.org/pipermail/tutor/2010-March/075443.html > if you can assure that the target computer will be running a certain > set of python features (i.e. Tkinter/pyGTK+/wxPython, etc) Presuming they're available on the user's platform and not too onerous to install, I can definitely say, "if you want , you need to install ." > you can fairly easily write a program that will run fullscreen and > continually grab focus to whatever widget (in this case a text entry > field) you want. *Continually* grabbing focus to a UI is functionally (from the user's point of view) equivalent to redirecting stdin, no? The user is made unable to do anything but take attendance for the duration of the task. In fact, for this usecase, continually grabbing focus is worse, since the user would be unable to, e.g., read the directions for setting up the audio. To clarify the usecase: The barcode scanner (here, a Wasp WLS9500) is connected to an ordinary multiprocessing laptop (which may be linux, mac, or windows) on which the user will want to do other things while taking attendance: the attendees don't come in all at once, and the user must accomplish other tasks while taking attendance (notably setting up to record the seminar audio). Hence the desired application 0 is portable. 1 does not redirect all of stdin, only the output from the scanner. The user is allowed to continue to work on other tasks (e.g. with output from the laptop's keyboard going to whatever frame), with only the output from the scanner being bound to a particular file or process. 2 does not continually grab focus. The user is allowed to continue to work on other tasks (e.g. with output from the laptop's keyboard going to whatever frame), with only scanner events being bound to a particular frame or widget. But what might satisfy the usecase is > if the device is something like the CueCat and reports a control > character (I think it's alt+f7 for the cuecat), then at least on > linux/windows I think it's much more trivial. You just have to > register a global hotkey handler that will send the focus to that > particular window. I'll read the Product Reference Guide and hope it tells me that the Wasp WLS9500 "reports a control character." Unfortunately when I search the PDF http://tinyurl.com/waspWLS9500manual for "control character" I get no hits. Are there synonyms for that term in this context? TIA, Tom Roche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] extending a VS python with cygwin
summary: how to fix ... m...@cygwinbox ~/bin/duplicity-0.6.09$ python setup.py install ... > error: Python was built with Visual Studio 2003; > extensions must be built with a compiler than can generate > compatible binaries. Visual Studio 2003 was not found on this > system. If you have Cygwin installed, you can try compiling with > MingW32, by passing "-c mingw32" to setup.py. m...@cygwinbox ~/bin/duplicity-0.6.09$ python -c mingw32 setup.py install > Traceback (most recent call last): > File "", line 1, in > NameError: name 'mingw32' is not defined m...@cygwinbox ~/bin/duplicity-0.6.09$ python setup.py -c mingw32 install > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] >or: setup.py --help [cmd1 cmd2 ...] >or: setup.py --help-commands >or: setup.py cmd --help > error: option -c not recognized m...@cygwinbox ~/bin/duplicity-0.6.09$ python setup.py install -c mingw32 > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] >or: setup.py --help [cmd1 cmd2 ...] >or: setup.py --help-commands >or: setup.py cmd --help > error: invalid command 'mingw32' details: What's the appropriate syntax to solve the above python build problem? Why I ask: I mostly run linux, and I've been using python-based `duplicity` http://duplicity.nongnu.org/ to back that up. I've got an older winxp box (SP3, uptodate with WU) which I keep mostly to run ArcGIS, which has happily run many versions of cygwin (which I keep uptodate) over the years. I'd like to be able to restore my linux home to my cygwin home for the rare occasions when I need to use the winxp box. To do that, I'd like to install duplicity on the cygwin box. That install process (best described by the somewhat downlevel http://blog.khorun.com/2008/09/using-duplicity-on-windows-under-cygwin.html ) works for the install of the prerequisite GnuPGInterface and boto python modules (process=[download tarball, tar xfz, python setup.py install]) but fails for the install of duplicity itself, with the error above: m...@cygwinbox ~/bin/duplicity-0.6.09$ python setup.py install ... > error: Python was built with Visual Studio 2003; Note that I'd cheerfully replace that version of python (the 2.5.2 that shipped with my ArcGIS 9.3), except that I use some ArcGIS extensions which seem to choke on other pythons :-( so I'd prefer to build against that if at all possible. > extensions must be built with a compiler than can generate > compatible binaries. Visual Studio 2003 was not found on this > system. If you have Cygwin installed, you can try compiling with > MingW32, by passing "-c mingw32" to setup.py. I try to take the advice offered, but either it's wrong or I'm missing something: m...@cygwinbox ~/bin/duplicity-0.6.09$ python -c mingw32 setup.py install > Traceback (most recent call last): > File "", line 1, in > NameError: name 'mingw32' is not defined m...@cygwinbox ~/bin/duplicity-0.6.09$ python setup.py -c mingw32 install > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] >or: setup.py --help [cmd1 cmd2 ...] >or: setup.py --help-commands >or: setup.py cmd --help > error: option -c not recognized m...@cygwinbox ~/bin/duplicity-0.6.09$ python setup.py install -c mingw32 > usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] >or: setup.py --help [cmd1 cmd2 ...] >or: setup.py --help-commands >or: setup.py cmd --help > error: invalid command 'mingw32' What's the appropriate syntax here? Or how else should I fix this? Apologies if this is a FAQ. If this is the wrong list/forum/whatever for this query, please direct me appropriately. Note that the duplicity list is apparently not the place, though :-( TIA, Tom Roche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] newbie needs pypy setup tips
I need advice about configuring pypy to run other python code. Why I ask: I'm running a model implemented in python. Unfortunately a run on "straight" python 2.6.x or 2.7.x requires - 130 min on my ubuntu laptop (on which working would be more convenient) - 55 min on a better build machine on which I currently have access However I have read that this model runs 5x faster under pypy, so I wanna get me that, but I'm finding the pypy docs pretty inscrutable. Nevertheless, I have managed to do me@it:~$ uname -rv > 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:13:52 UTC 2011 me@it:~$ which pypy > /usr/local/bin/pypy me@it:~$ ls -al $(which pypy) > lrwxrwxrwx 1 root root 37 2011-07-30 16:06 /usr/local/bin/pypy -> > /opt/pypy-c-jit-1.5.0-alpha0/bin/pypy me@it:~$ pypy --version > Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34) > [PyPy 1.5.0-alpha0 with GCC 4.4.3] However, when I try to *really* run the @#$%^&! thing, it spews: me@it:~$ pypy > debug: WARNING: library path not found, using compiled-in sys.path and > sys.prefix will be unset > 'import site' failed > Python 2.7.1 (b590cf6de419, Apr 30 2011, 02:00:34) > [PyPy 1.5.0-alpha0 with GCC 4.4.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > debug: OperationError: > debug: operror-type: ImportError > debug: operror-value: No module named _pypy_interact What do I need to do to fix its library path? TIA, Tom Roche ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] howto create virtual environment for Enthought Training on Debian?
I'm running a 64-bit flavor of Debian (LMDE) with GNOME, which includes a system python and various python-using applets and applications. I have a long-standing interest in scientific software, but only recently acquired some spare time and an Enthought Training license. So I'd like to get setup to work the Enthought Training exercises, which apparently means installing Canopy (formerly EPD), possibly et al. However, the last time I tried to do something similar (2 years ago? installing EPD), using the provided installer, it whacked some system-python-dependent appss. I therefore want to install Canopy (and whatever else I need to do the Enthought Training that is not independently available via debian packages) into a virtual environment (so as not to cause problems with dependencies of my system python). How to do this? conda? venv? virtualenv? Unfortunately I'm not seeing any howto's on Enthought's site[1]. Please reply to me as well as the list: I'm on the digest, which gets huge. Alternatively, add your answer to this StackOverflow[2] (which I setup at Enthought's apparent recommendation[1]). TIA, Tom Roche [1]: https://support.enthought.com/home [2]: http://stackoverflow.com/questions/25375171/create-virtual-environment-for-enthought-training-on-debian ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor