discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] importing modules in tests


From: Ben Reynwar
Subject: Re: [Discuss-gnuradio] importing modules in tests
Date: Wed, 22 Jun 2011 22:19:16 -0700

On Tue, Jun 21, 2011 at 10:01 PM, Ben Reynwar <address@hidden> wrote:
> On Tue, Jun 21, 2011 at 5:53 PM, Tom Rondeau <address@hidden> wrote:
>> On Tue, Jun 21, 2011 at 8:13 PM, Ben Reynwar <address@hidden> wrote:
>>>
>>> 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
>>
>> 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
>>
>
> 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
>

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]