Importing modules in tests

Hi all,

I’m having difficulty working out how to import modules when doings
tests, since for the tests the python code that is used is the
non-installed version, and so the package/subpackage hierarchy of the
various python folders is not in place.

For example if I am creating a test for gr-trellis, but I want to
import features from gr-digital, I cannot simply use “from
gnuradio.digital import xxx”.

Is there a good reason why the tests can’t simply use the installed
version of gnuradio? It seems like this would make everything
simpler.

Cheers,
Ben

On Tue, Jun 21, 2011 at 8:13 PM, Ben R. [email protected] wrote:

Is there a good reason why the tests can’t simply use the installed
version of gnuradio? It seems like this would make everything
simpler.

Cheers,
Ben

It’s because you really want to test off of what you are about to
install,
not what’s already installed. This is especially problematic if you
haven’t
done a ‘make install,’ yet.

The QA code in various packages in GNU Radio should show you how to grab
the
stuff locally.

Let me know if you need more specific help. I haven’t done anything with
the
QA code in gr-trellis, but I’ve worked on it elsewhere.

Tom

On Tue, Jun 21, 2011 at 5:53 PM, Tom R. [email protected]
wrote:

import features from gr-digital, I cannot simply use "from
not what’s already installed. This is especially problematic if you haven’t
done a ‘make install,’ yet.
The QA code in various packages in GNU Radio should show you how to grab the
stuff locally.
Let me know if you need more specific help. I haven’t done anything with the
QA code in gr-trellis, but I’ve worked on it elsewhere.
Tom

For a test in gr-trellis, I can access the trellis and gnuradio.gr
subpackages fine since they have been added to PYTHONPATH by
run_tests.sh. To get access to gnuradio.digital I would need to
modify run_tests.sh.

I think a slightly more elegant solution would be to have a
testing_pydir/gnuradio/init.py file somewhere. This init.py
file would then point to the locations of the folders corresponding to
the various subpackages. When doing testing PYTHONPATH could simply
point to testing_pydir and then “from gnuradio import gr, trellis,
digital” would work without any problems. We would have two versions
of the top level init.py file: one in
gnuadio-core/src/python/gnuradio which is installed, and one in
testing_pydir/gnuradio which is used when testing.

An advantage of this would be that the qa tests would work when tested
through “make check”, and would also work if run as stand-alone
scripts e.g. “python qa_xxx.py”.

Ben

On Tue, Jun 21, 2011 at 10:01 PM, Ben R. [email protected] wrote:

For example if I am creating a test for gr-trellis, but I want to
It’s because you really want to test off of what you are about to install,
subpackages fine since they have been added to PYTHONPATH by
gnuadio-core/src/python/gnuradio which is installed, and one in
testing_pydir/gnuradio which is used when testing.

An advantage of this would be that the qa tests would work when tested
through “make check”, and would also work if run as stand-alone
scripts e.g. “python qa_xxx.py”.

Ben

I’ve had a first crack at creating at alternative gnuradio/init.py
to be used during testing.

https://github.com/benreynwar/gnuradio/commit/03901a6a35b11154d5bcd3dcd923ad6afb2f8d02

At the moment it only populates the gnuradio package with the
gnuradio-core, and gr-trellis subpackages but it would be easy to
extend.