Ezio Melotti <ezio.melo...@gmail.com> added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5723>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to