RE: [pypy-dev] Objects and types in the stdobjspace

Michael Hudson <mwh@python.net> wrote:
I've had another idea: give unittest_w.TestCase_w a metaclass that looks for methods called 'test_app_whatever' and arrange for such methods to be called as objectspace methods.
Sounds like a wonderful solution, but I have to confess that my eyes glaze over when trying to understand metaclasses - I probably should put more of an effort into learning about them one of these days... Is using metaclasses really nessasary? Before I realized that metaclasses were involved, I first thought of using a special subclass of TestCase - probably by overloading TestCase.__call__() to appropriately wrap the function before it is run. If we can use the subclass approach, we could potentially simplify things by having two seperate TestCase subclasses, one for interpreter level and one for application level tests. This would potentially require splitting of a single test case into two, one each for application and interpreter levels, whereas your implementation appears to allow both types of tests in the same class definition. But feel free to ignore this as I haven't tried putting it into code and have no clue what the problems with it may be. -Rocco __________________________________________________________________ McAfee VirusScan Online from the Netscape Network. Comprehensive protection for your entire computer. Get your free trial today! http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397 Get AOL Instant Messenger 5.1 free of charge. Download Now! http://aim.aol.com/aimnew/Aim/register.adp?promo=380455

roccomoretti@netscape.net (Rocco Moretti) writes:
Michael Hudson <mwh@python.net> wrote:
I've had another idea: give unittest_w.TestCase_w a metaclass that looks for methods called 'test_app_whatever' and arrange for such methods to be called as objectspace methods.
Sounds like a wonderful solution, but I have to confess that my eyes glaze over when trying to understand metaclasses - I probably should put more of an effort into learning about them one of these days...
I should probably be worried at the willingness with which I now reach for them.
Is using metaclasses really nessasary?
Heh. No, probably not.
Before I realized that metaclasses were involved, I first thought of using a special subclass of TestCase - probably by overloading TestCase.__call__() to appropriately wrap the function before it is run.
Yes, that would probably work. It would also mean that we wouldn't have to make testsupport.TestCase new-style which would mean we wouldn't have to steal 2.3's TestLoader, which would be a good thing.
If we can use the subclass approach, we could potentially simplify things by having two seperate TestCase subclasses, one for interpreter level and one for application level tests.
Yes, that would be one approach.
This would potentially require splitting of a single test case into two, one each for application and interpreter levels, whereas your implementation appears to allow both types of tests in the same class definition.
Yes it does. The subclassing approach could allow that, but doesn't have to. I don't feel that splitting the tests up would necessarily be a bad thing, either.
But feel free to ignore this as I haven't tried putting it into code and have no clue what the problems with it may be.
No, you've probably done a sensible job of restraining my obfuscatory tendencies! Cheers, M. -- Or here's an even simpler indicator of how much C++ sucks: Print out the C++ Public Review Document. Have someone hold it about three feet above your head and then drop it. Thus you will be enlightened. -- Thant Tessman

Michael Hudson <mwh@python.net> writes:
roccomoretti@netscape.net (Rocco Moretti) writes:
Michael Hudson <mwh@python.net> wrote:
I've had another idea: give unittest_w.TestCase_w a metaclass that looks for methods called 'test_app_whatever' and arrange for such methods to be called as objectspace methods.
Sounds like a wonderful solution, but I have to confess that my eyes glaze over when trying to understand metaclasses - I probably should put more of an effort into learning about them one of these days...
I should probably be worried at the willingness with which I now reach for them.
Is using metaclasses really nessasary?
Heh. No, probably not.
Before I realized that metaclasses were involved, I first thought of using a special subclass of TestCase - probably by overloading TestCase.__call__() to appropriately wrap the function before it is run.
Yes, that would probably work.
And it does, after a fashion. Well, it works fine as far as I can tell, it's just that running the assertFoo methods in app-space *too* (what the attached does) isn't ideal. OTOH, the fact that doing so *works* is something we can be proud of. The only decision to be made is: do we distinguish between app-space tests by a naming convention (as attached: any test starting test_app_ runs in app space) or by inheriting from a different TestCase subclass? I can't make my mind up which I prefer. In either case, I want to check something like this in, soon. The implementation can be made more elegant/faster in due course. Cheers, M. -- Just point your web browser at http://www.python.org/search/ and look for "program", "doesn't", "work", or "my". Whenever you find someone else whose program didn't work, don't do what they did. Repeat as needed. -- Tim Peters, on python-help, 16 Jun 1998
participants (2)
-
Michael Hudson
-
roccomoretti@netscape.net