Parallel package hierarchies/directories

2009-01-15 Thread atleta
  Hi,

I'd need a logical way to organize my unit tests into packages, but I
don't know how to do it in python. I'd like to separate my test
sources (modules) from the code. The problem is that it seems that
python does not allow a package to spread through multiple
directories. I'd like to have the following layout (which is the usual
way we do it e.g. in java):

+-project_root/
|
+-src/
|   |
|   +-soap
|
+-test/
|
+-soap

'soap' is a package under the source tree. I.e. I'd like my test
source tree to mirror the source tree and have package specific tests
in the same package as the code they excersize. However I found that
this is not possible, at least not the way I wanted, not without
moving files. I tried to place a script that would run all tests under
the 'test' directory. It added 'src' to the sys.path, but then it was
only able to import packages from test/soap and not src/soap.

Is there a way I can have python look for soap package modules in both
places? If not, then could someone tell me what is the usual way to
layout test code?

  Thanks,
atleta
--
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel package hierarchies/directories

2009-01-16 Thread atleta
OK, I'm answering my own question, it might be of some help for
someone in the future: yes, it's possible to have parts of the same
package in multiple directories, it's just not enabled by default. To
make it work each such package should have the following code in their
__init__.py:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

Actually pkgutil's documentation explains this quite clearly:
http://docs.python.org/library/pkgutil.html (It's easy if you know
where to look ;) )

  Laszlo
--
http://mail.python.org/mailman/listinfo/python-list


Adding a field to a 'foreign' object from the outside

2009-01-22 Thread atleta
  Hi,

I'm working with a callback API (a DBus one) and I'd need to store
some state between the calls somewhere. I know that it's possible to
extend an object with fields after creation, so I could just store my
data in the session object that is passed in with every callback.
However it stinks from OO perspective, at least to me. The other
option, something that I'd do in java for example, would be to set up
a mapping (a dict) using the session object as a key. Which one is the
'pythonic' way? Do you use the first method (modifying an object that
you don't even control the source of) or do you write a bit more code
and go with the second one?

  Thanks,
Laszlo
--
http://mail.python.org/mailman/listinfo/python-list