homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients benjamin.peterson, bob.ippolito, doerwalter, ezio.melotti, fdrake, jowillia, pitrou, rhettinger, xuanji
Date 2011年05月12日.20:02:42
SpamBayes Score 1.110223e-16
Marked as misclassified No
Message-id <1305230563.62.0.550759975608.issue5723@psf.upfronthosting.co.za>
In-reply-to
Content
> Why can't you write something like:skip_unless_cjson = skipUnless(...)
This indeed works -- using unittest internals was just a temporary workaround because the example in the unittest doc didn't seem to work.
> - instead of "self.mod", "self.json" would be nicer
I thought about using self.json, but then opted for 'mod' because is what the other modules seem to use, but I will fix it.
> - you could also export "self.loads", "self.dumps" for easier access
Usually they are not called more than a couple of times for each test, and each test class usually has 1-2 tests methods, so I'm not sure it's worth it.
- you could also have two base classes exporting all this instead of repeating the attribute-setting for every test class
I considered this too, but since the C test classes currently inherit from the Python classes, the C base class would have to be a mixin that overrides the effect of the Python base class -- unless I move all the tests in separate base classes and create two separate subclasses for each C/Python test that inherit from the base test classes and either the C or Python base classes. So the two base test classes will be in __init__:
 class CTest(TestCase):
 self.json = cjson; self.loads = cjson.loads; ...
 class PyTest(TestCase):
 self.json = pyjson; self.loads = pyjson.loads; ...
and the other test files will use either:
 class TestPySomething(PyTest):
 def test_something(self): ...
 class TestCSomething(TestPySomething, CTest):
 pass
or:
 class TestSomething(TestCase):
 def test_something(self): ...
 class TestPySomething(TestSomething, PyTest): pass
 class TestCSomething(TestSomething, CTest): pass
Another option is to have a single base class that sets self.loads/dumps in the __init__ but that will still require the module to be set in the subclasses, something like:
 class JsonTestCase(TestCase):
 def __init__(self):
 self.loads = self.json.loads
 self.dumps = self.json.dumps
and then use:
 class TestPySomething(JsonTestCase):
 json = pyjson
 def test_something(self): ...
 class TestCSomething(TestPySomething):
 json = cjson
I'm not sure any of these options is better than what we have now though.
History
Date User Action Args
2011年05月12日 20:02:43ezio.melottisetrecipients: + ezio.melotti, fdrake, doerwalter, rhettinger, bob.ippolito, pitrou, benjamin.peterson, jowillia, xuanji
2011年05月12日 20:02:43ezio.melottisetmessageid: <1305230563.62.0.550759975608.issue5723@psf.upfronthosting.co.za>
2011年05月12日 20:02:42ezio.melottilinkissue5723 messages
2011年05月12日 20:02:42ezio.melotticreate

AltStyle によって変換されたページ (->オリジナル) /