view tests/doctest.txt @ 22:9c710f06e51d

add virtualenv to the virtualenv(!)
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 08 Jul 2011 18:11:09 -0700
parents e2c9a9a4d524
children bb19d3dac4c5
line wrap: on
line source

Test carton
===========

The obligatory imports:

    >>> import carton
    >>> import os

Make a temporary directory::

    >>> import tempfile
    >>> directory = tempfile.mkdtemp()

Invoke carton::

    >>> os.chdir(directory)
    >>> packages = [os.path.join(here, i) for i in 'packageC.tar.gz', 'packageB', 'packageA']
    >>> carton.main(['foo'] + packages)
    >>> os.listdir('.')
    ['foo.py']

Invoke the foo.py it creates::

    >>> import subprocess
    >>> subprocess.call([python, 'foo.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    0
    >>> sorted(os.listdir('.'))
    ['foo', 'foo.py']
    >>> os.path.isdir('foo')
    True
    >>> sorted(os.listdir(os.path.join('foo', 'src')))
    ['packageA', 'packageB', 'packageC']

Find a console script. This shows installation went well::

    >>> bin = [os.path.join('foo', i) for i in ('bin', 'Scripts) if os.path.exists(os.path.join('foo', i))][0]
    >>> os.path.exists(bin) # just to make sure
    >>> os.path.exists(os.path.join(bin, 'packageA')) or os.path.exists(os.path.join(bin, 'packageA.exe'))
    True

Show that non-package files get carried along too::

    >>> os.path.exists(os.path.join('foo', 'src', 'packageA', 'foo.txt'))
    True

Invoke carton again.  This time, package the source so that
stragglers don't come along::

    >>> carton.main(['bar', '--package'] + packages)
    >>> 'bar.py' in os.listdir('.')
    True
    >>> subprocess.call([python, 'bar.py', '--env', 'fleem'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    0
    >>> os.path.exists('fleem') and os.path.isdir('fleem')
    True
    >>> srcdir = os.path.join('fleem', 'src')
    >>> packageA = os.path.join(srcdir, [i for i in os.listdir(srcdir) if i.startswith('packageA')][0])    
    >>> os.path.exists(os.path.join(packageA 'foo.txt'))
    False

Clean up::

    >>> import shutil
    >>> shutil.rmtree(directory)