"import rpy2.robjects.tests" breaks "import unittest" in 2.1.9

Issue #80 wontfix
Jon Olav Vik created an issue

As described below, running "import rpy2.robjects.tests" seems to break "import unittest". An easy workaround is to "import unittest" first, though it is possible that this bug may indicate more serious errors.

I installed the default rpy2 package 2.1.9 in a fresh 32-bit Ubuntu 11.04 inside VirtualBox 4.0.12 on Windows 7 64-bit, then try to run the tests mentioned on http://rpy.sourceforge.net/rpy2/doc-2.2/html/overview.html.

Testing rpy2.robjects from the command line fails with "SyntaxError: invalid syntax". [1]

Trying again from the standard Python prompt, it seems that importing rpy2.robjects.tests prevents me from importing unittest. [2] If I import unittest first, things work okay. [3]

A similar problem and workaround applies to rpy2.rinterface. [4-6]

(A note for the documentation: python -m packagename.modulename works fine without quotes.)

== [1] == {{{ jonvi@vbox:~$ python -m 'rpy2.robjects.tests.init' Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 151, in _run_module_as_main mod_name, loader, code, fname = _get_module_details(mod_name) File "/usr/lib/python2.7/runpy.py", line 113, in _get_module_details code = loader.get_code(mod_name) File "/usr/lib/python2.7/pkgutil.py", line 275, in get_code self.code = compile(source, self.filename, 'exec') File "/usr/lib/python2.7/dist-packages/rpy2/robjects/tests/init.py", line 1 import unittest ^ SyntaxError: invalid syntax }}}

== [2] == {{{ jonvi@vbox:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import rpy2.robjects.tests import unittest File "<stdin>", line 1 import unittest ^ SyntaxError: invalid syntax }}} == [3] == {{{ jonvi@vbox:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. import unittest import rpy2.robjects.tests

the verbosity level can be increased if needed

... tr = unittest.TextTestRunner(verbosity = 1) suite = rpy2.robjects.tests.suite() tr.run(suite) ..............................................................................................................


Ran 110 tests in 0.908s

OK <unittest.runner.TextTestResult run=110 errors=0 failures=0> }}} == [4] == {{{ jonvi@vbox:~$ python -m 'rpy2.rinterface.tests.init' Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 151, in _run_module_as_main mod_name, loader, code, fname = _get_module_details(mod_name) File "/usr/lib/python2.7/runpy.py", line 101, in _get_module_details loader = get_loader(mod_name) File "/usr/lib/python2.7/pkgutil.py", line 456, in get_loader return find_loader(fullname) File "/usr/lib/python2.7/pkgutil.py", line 466, in find_loader for importer in iter_importers(fullname): File "/usr/lib/python2.7/pkgutil.py", line 422, in iter_importers import(pkg) File "/usr/lib/python2.7/dist-packages/rpy2/rinterface/tests/init.py", line 7, in <module> import test_SexpVectorNumeric File "/usr/lib/python2.7/dist-packages/rpy2/rinterface/tests/test_SexpVectorNumeric.py", line 7, in <module> import numpy File "/usr/lib/pymodules/python2.7/numpy/init.py", line 152, in <module> import polynomial File "/usr/lib/pymodules/python2.7/numpy/polynomial/init.py", line 16, in <module> from polynomial import * File "/usr/lib/pymodules/python2.7/numpy/polynomial/polynomial.py", line 931, in <module> exec polytemplate.substitute(name='Polynomial', nick='poly', domain='[-1,1]') File "<string>", line 3 import polyutils as pu ^ SyntaxError: invalid syntax }}} == [5] == {{{ jonvi@vbox:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import rpy2.rinterface.tests Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/rpy2/rinterface/tests/init.py", line 7, in <module> import test_SexpVectorNumeric File "/usr/lib/python2.7/dist-packages/rpy2/rinterface/tests/test_SexpVectorNumeric.py", line 7, in <module> import numpy File "/usr/lib/pymodules/python2.7/numpy/init.py", line 152, in <module> import polynomial File "/usr/lib/pymodules/python2.7/numpy/polynomial/init.py", line 16, in <module> from polynomial import * File "/usr/lib/pymodules/python2.7/numpy/polynomial/polynomial.py", line 931, in <module> exec polytemplate.substitute(name='Polynomial', nick='poly', domain='[-1,1]') File "<string>", line 3 import polyutils as pu ^ SyntaxError: invalid syntax import unittest File "<stdin>", line 1 import unittest ^ SyntaxError: invalid syntax import unittest File "<stdin>", line 1 import unittest ^ SyntaxError: invalid syntax }}} == [6] == {{{ jonvi@vbox:~$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. import unittest import rpy2.rinterface.tests

the verbosity level can be increased if needed

... tr = unittest.TextTestRunner(verbosity = 1) suite = rpy2.rinterface.tests.suite() tr.run(suite) ................................................................................................................................/usr/lib/pymodules/python2.7/numpy/core/numeric.py:284: RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size. return array(a, dtype, copy=False, order=order) ...


Ran 131 tests in 2.350s

OK <unittest.runner.TextTestResult run=131 errors=0 failures=0> }}}

Comments (3)

  1. Laurent Gautier

    Hi,

    Thanks for your report.

    Could you try with the _current_ release 2.2.2 (not the 2.1.x series, 2.1.9 being the last of that series) ? I can't reproduce the problems you are reporting with a recent rpy2.

  2. Jon Olav Vik reporter

    No worries, I'll trust that it's fixed in 2.2.2. I'm just using 2.1.9 until the Ubuntu packages are updated, as I'm putting together installation instructions for the dependencies for some code I wrote.

  3. Log in to comment