view tests/doctest.txt @ 19:996d579f0dc3

test for --package and --env
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 08 Jul 2011 17:59:20 -0700
parents f522620c6a78
children e2c9a9a4d524
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'))
    True

Clean up::

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