From fb6ed63cb44a4795abe296e07791219e532ecdfe 2010-01-15 10:00:11
From: Fernando Perez <Fernando.Perez@berkeley.edu>
Date: 2010-01-15 10:00:11
Subject: [PATCH] Make it possible to run the tests from the source dir without installation.

Also clean up the handling of command-line options for iptest, so that all
options given at the top-level are correctly passed to nose.

Fixes: https://bugs.launchpad.net/ipython/+bug/507079

---

diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py
index c3e3e07..90aa93e 100644
--- a/IPython/testing/iptest.py
+++ b/IPython/testing/iptest.py
@@ -30,6 +30,17 @@ import tempfile
 import time
 import warnings
 
+
+# Ugly,  but necessary hack to ensure the test suite finds our version of
+# IPython and not a possibly different one that may exist system-wide.
+# Note that this must be done here, so the imports that come next work
+# correctly even if IPython isn't installed yet.
+p = os.path
+ippath = p.abspath(p.join(p.dirname(__file__),'..','..'))
+sys.path.insert(0, ippath)
+#print 'ipp:',  ippath  # dbg
+#import IPython; print 'IP file:', IPython.__file__  # dbg
+
 # Note: monkeypatch!
 # We need to monkeypatch a small problem in nose itself first, before importing
 # it for actual use.  This should get into nose upstream, but its release cycle
@@ -101,6 +112,10 @@ def make_exclude():
     
     exclusions = [ipjoin('external'),
                   ipjoin('frontend', 'process', 'winprocess.py'),
+                  # Deprecated old Shell and iplib modules, skip to avoid
+                  # warnings
+                  ipjoin('Shell'),
+                  ipjoin('iplib'),
                   pjoin('IPython_doctest_plugin'),
                   ipjoin('quarantine'),
                   ipjoin('deathrow'),
@@ -193,7 +208,8 @@ class IPTester(object):
             # Find our own 'iptest' script OS-level entry point.  Don't look
             # system-wide, so we are sure we pick up *this one*.  And pass
             # through to subprocess call our own sys.argv
-            self.runner = tools.cmd2argv(__file__) + sys.argv[1:]
+            self.runner = tools.cmd2argv(os.path.abspath(__file__)) + \
+                          sys.argv[1:]
         else:
             self.runner = tools.cmd2argv(os.path.abspath(find_cmd('trial')))
         if params is None:
@@ -388,8 +404,10 @@ def run_iptestall():
 def main():
     for arg in sys.argv[1:]:
         if arg.startswith('IPython'):
+            # This is in-process
             run_iptest()
     else:
+        # This starts subprocesses
         run_iptestall()
 
 
diff --git a/IPython/testing/tools.py b/IPython/testing/tools.py
index f6762c3..7a89c32 100644
--- a/IPython/testing/tools.py
+++ b/IPython/testing/tools.py
@@ -244,13 +244,15 @@ def ipexec(fname, options=None):
     
     _ip = get_ipython()
     test_dir = os.path.dirname(__file__)
+
     # Find the ipython script from the package we're using, so that the test
     # suite can be run from the source tree without an installed IPython
-    ipython_package_dir = genutils.get_ipython_package_dir()
-    ipython_script = os.path.join(ipython_package_dir,'scripts','ipython')
+    p = os.path
+    ippath = p.abspath(p.join(p.dirname(__file__),'..','..'))
+    ipython_script = p.join(ippath, 'ipython.py')
     ipython_cmd = 'python "%s"' % ipython_script
     # Absolute path for filename
-    full_fname = os.path.join(test_dir, fname)
+    full_fname = p.join(test_dir, fname)
     full_cmd = '%s %s "%s"' % (ipython_cmd, cmdargs, full_fname)
     return genutils.getoutputerror(full_cmd)
 
diff --git a/README.txt b/README.txt
index dcda9ef..dc6d10e 100644
--- a/README.txt
+++ b/README.txt
@@ -5,7 +5,25 @@ IPython README
 Overview
 ========
 
-Welcome to IPython. Our documentation can be found in the docs/source
-subdirectory. We also have ``.html`` and ``.pdf`` versions of this
-documentation available on the IPython `website <http://ipython.scipy.org>`_.
+Welcome to IPython. Our full documentation can be found in the ``docs/dist``
+subdirectory in ``.html`` and ``.pdf`` formats, also available online at our
+`website <http://ipython.scipy.org>`_.  The ``docs/source`` directory contains
+the plaintext version of these manuals.
 
+
+Instant running and testing
+===========================
+
+You can run IPython from this directory without even installing it system-wide
+by typing at the terminal:
+
+.. code-block:: bash
+
+   python ipython.py
+
+and similarly, you can execute the built-in test suite with:
+   
+.. code-block:: bash
+
+   python iptest.py
+   
\ No newline at end of file
diff --git a/docs/source/development/testing.txt b/docs/source/development/testing.txt
index 8d496cd..440ff7c 100644
--- a/docs/source/development/testing.txt
+++ b/docs/source/development/testing.txt
@@ -42,7 +42,22 @@ manages the Twisted reactor correctly.
 For the impatient: running the tests
 ====================================
 
-The simplest way to test IPython is to type at the command line:
+You can run IPython from the source download directory without even installing
+it system-wide or having configure anything, by typing at the terminal:
+
+.. code-block:: bash
+
+   python ipython.py
+
+and similarly, you can execute the built-in test suite with:
+   
+.. code-block:: bash
+
+   python iptest.py
+
+
+Once you have either installed it or at least configured your system to be
+able to import IPython, you can run the tests with:
 
 .. code-block:: bash
 
@@ -50,7 +65,9 @@ The simplest way to test IPython is to type at the command line:
 
 This should work as long as IPython can be imported, even if you haven't fully
 installed the user-facing scripts yet (common in a development environment).
-After a lot of output, you should see something like:
+
+
+Regardless of how you run things, you should eventually see something like:
 
 .. code-block:: bash
   
diff --git a/iptest.py b/iptest.py
new file mode 100755
index 0000000..7c22381
--- /dev/null
+++ b/iptest.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+"""Test script for IPython.
+
+The actual ipython test script to be installed with 'python setup.py install'
+is in './scripts' directory. This file is here (ipython source root directory)
+to facilitate non-root 'zero-installation testing' (just copy the source tree
+somewhere and run ipython.py) and development.
+
+You can run this script directly, type -h to see all options."""
+
+# Ensure that the imported IPython is the local one, not a system-wide one
+import os, sys
+this_dir = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, this_dir)
+
+# Now proceed with execution
+execfile(os.path.join(this_dir, 'IPython', 'scripts', 'iptest'))
diff --git a/ipython.py b/ipython.py
index 0185eeb..ae5c5ea 100755
--- a/ipython.py
+++ b/ipython.py
@@ -7,6 +7,10 @@ in './scripts' directory. This file is here (ipython source root directory)
 to facilitate non-root 'zero-installation' (just copy the source tree
 somewhere and run ipython.py) and development. """
 
-from IPython.core.ipapp import launch_new_instance
+# Ensure that the imported IPython is the local one, not a system-wide one
+import os, sys
+this_dir = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, this_dir)
 
-launch_new_instance()
+# Now proceed with execution
+execfile(os.path.join(this_dir, 'IPython', 'scripts', 'ipython'))