[IPython-user] problem with Ipython1 SAW and test library "py.test"

vincent vauchey v.vauchey@gmail....
Fri Jul 27 10:06:44 CDT 2007


Hello,
I'm used Ipython1 SAW since some months , but now I obtain an error between
Ipython1 and test library "py.test" under Linux (and Windows also).


 When I write in a python command prompt:

">>> import ipython1.kernel.api as kernel"

I have no error and I can use Ipython1 without error : )


 But, I create a python test file test_WS_SessionManager.py which begin by

"import ipython1.kernel.api as kernel"

I write in a command prompt : "py.test test_WS_SessionManager.py", I obtain
the error message that you can read in attached file: "error.txt"

(the error append with line: "from IPython.genutils import get_home_dir")


 I also try to use Doctest, and to update my Ipython1 version, but I have
also an error at these line :(


 Although I search on internet, I don't solve this problem, so I need your
help please.


 Regards.


 Vincent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20070727/178ec864/attachment.html 
-------------- next part --------------

    # Make it easy to import extensions - they are always directly on pythonpath.
    # Therefore, non-IPython modules can be added to Extensions directory
    import os
    sys.path.append(os.path.dirname(__file__) + "/Extensions")

    # Define what gets imported with a 'from IPython import *'
    __all__ = ['deep_reload','genutils','ipstruct','ultraTB','DPyGetOpt',
               'Itpl','hooks','ConfigLoader','OutputTrap','Release','Shell',
               'platutils','platutils_win32','platutils_posix','platutils_dummy',
               'ipapi','rlineimpl', 'strdispatch']

    # Load __all__ in IPython namespace so that a simple 'import IPython' gives
    # access to them via IPython.<name>
    glob,loc = globals(),locals()
    for name in __all__:
>       __import__(name,glob,loc,[])

[/usr/lib/python2.5/site-packages/IPython/__init__.py:60]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    $Id: genutils.py 2190 2007-03-30 18:35:46Z fperez $"""

    #*****************************************************************************
    #       Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
    #
    #  Distributed under the terms of the BSD License.  The full license is in
    #  the file COPYING, distributed as part of this software.
    #*****************************************************************************

    from IPython import Release
    __author__  = '%s <%s>' % Release.authors['Fernando']
    __license__ = Release.license

    #****************************************************************************
    # required modules from the Python standard library
    import __main__
    import commands
    import os
    import re
    import shlex
    import shutil
    import sys
    import tempfile
    import time
    import types
    import warnings

    # Other IPython utilities
    from IPython.Itpl import Itpl,itpl,printpl
    from IPython import DPyGetOpt
    from path import path
    if os.name == "nt":
        from IPython.winconsole import get_console_size

    #****************************************************************************
    # Exceptions
    class Error(Exception):
        """Base class for exceptions in this module."""
        pass

    #----------------------------------------------------------------------------
    class IOStream:
        def __init__(self,stream,fallback):
            if not hasattr(stream,'write') or not hasattr(stream,'flush'):
                stream = fallback
            self.stream = stream
            self._swrite = stream.write
            self.flush = stream.flush

        def write(self,data):
            try:
                self._swrite(data)
            except:
                try:
                    # print handles some unicode issues which may trip a plain
                    # write() call.  Attempt to emulate write() by using a
                    # trailing comma
                    print >> self.stream, data,
                except:
                    # if we get here, something is seriously broken.
                    print >> sys.stderr, \
                          'ERROR - failed to write data to stream:', self.stream

        def close(self):
            pass


    class IOTerm:
        """ Term holds the file or file-like objects for handling I/O operations.

        These are normally just sys.stdin, sys.stdout and sys.stderr but for
        Windows they can can replaced to allow editing the strings before they are
        displayed."""

        # In the future, having IPython channel all its I/O operations through
        # this class will make it easier to embed it into other environments which
        # are not a normal terminal (such as a GUI-based shell)
        def __init__(self,cin=None,cout=None,cerr=None):
            self.cin  = IOStream(cin,sys.stdin)
            self.cout = IOStream(cout,sys.stdout)
            self.cerr = IOStream(cerr,sys.stderr)

    # Global variable to be used for all I/O
>   Term = IOTerm()

[/usr/lib/python2.5/site-packages/IPython/genutils.py:91]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __init__(self,cin=None,cout=None,cerr=None):
>       self.cin  = IOStream(cin,sys.stdin)

[/usr/lib/python2.5/site-packages/IPython/genutils.py:86]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def __init__(self,stream,fallback):
        if not hasattr(stream,'write') or not hasattr(stream,'flush'):
            stream = fallback
        self.stream = stream
E       self._swrite = stream.write
>       AttributeError: DontReadFromInput instance has no attribute 'write'

[/usr/lib/python2.5/site-packages/IPython/genutils.py:54]
________________________________________________________________________________________
======================= tests finished: 1 failed in 0.05 seconds =======================
[root@localhost python]# clear
[root@localhost python]# py.test
================================= test process starts ==================================
executable:   /usr/bin/python2.5  (2.5.0-final-0)
using py lib: /usr/lib/python2.5/site-packages/py <rev unknown>

test_WS_SessionManager.py - FAILED TO LOAD MODULE

________________________________________________________________________________________
_____________________________________ entrypoint:  _____________________________________

    def runtraced(self, colitem):
        if self.shouldclose():
            raise Exit, "received external close signal"

        outcome = None
        colitem.startcapture()
        try:
            self.start(colitem)
            try:
                try:
                    if colitem._stickyfailure:
                        raise colitem._stickyfailure
>                   outcome = self.run(colitem)

[/usr/lib/python2.5/site-packages/py/test/session.py:83]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def run(self, colitem):
        if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item):
            return
        if isinstance(colitem, py.test.collect.Item):
            colitem._skipbykeyword(self.config.option.keyword)
>       res = colitem.run()

[/usr/lib/python2.5/site-packages/py/test/session.py:106]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def run(self):
>       if getattr(self.obj, 'disabled', 0):

[/usr/lib/python2.5/site-packages/py/test/collect.py:351]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def obj(self):
        try:
            return self._obj
        except AttributeError:
            failure = getattr(self, '_stickyfailure', None)
            if failure is not None:
                raise failure[0], failure[1], failure[2]
            try:
>               self._obj = obj = self.fspath.pyimport()

[/usr/lib/python2.5/site-packages/py/test/collect.py:380]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def pyimport(self, modname=None, ensuresyspath=True):
        """ return path as an imported python module.
                if modname is None, look for the containing package
                and construct an according module name.
                The module will be put/looked up in sys.modules.
            """
        if not self.check():
            raise py.error.ENOENT(self)
        #print "trying to import", self
        pkgpath = None
        if modname is None:
            #try:
            #    return self._module
            #except AttributeError:
            #    pass
            pkgpath = self.pypkgpath()
            if pkgpath is not None:
                if ensuresyspath:
                    self._prependsyspath(pkgpath.dirpath())
                pkg = __import__(pkgpath.basename, None, None, [])

                if hasattr(pkg, '__package__'):
                    modname = pkg.__package__.getimportname(self)
                    assert modname is not None, "package %s doesn't know %s" % (
                                                pkg.__name__, self)

                else:
                    names = self.new(ext='').relto(pkgpath.dirpath())
                    names = names.split(self.sep)
                    modname = ".".join(names)
            else:
                # no package scope, still make it possible
                if ensuresyspath:
                    self._prependsyspath(self.dirpath())
                modname = self.purebasename
E           mod = __import__(modname, None, None, ['__doc__'])
>             File "/usr/share/python/test_WS_SessionManager.py", line 3
                import ipythomport ipython1.kernel.api as kernel
                                           ^
            SyntaxError: invalid syntax

[/usr/lib/python2.5/site-packages/py/path/local/local.py:418]
________________________________________________________________________________________
======================= tests finished: 1 failed in 0.03 seconds =======================
[root@localhost python]#


More information about the IPython-user mailing list