view tests/doctest.txt @ 26:e6ee0410ceef

fix bug where os.path.sep is wrongly interpreted
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 10 Jul 2011 18:37:42 -0700
parents e2db2913123d
children dace84448c25
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.isdir(bin)
    True
    >>> os.path.exists(os.path.join(bin, 'packageA')) or os.path.exists(os.path.join(bin, 'packageA.exe'))
    True

Ensure you're bringing along virtualenv::

    >>> os.path.exists(os.path.join(bin, 'virtualenv')) or os.path.exists(os.path.join(bin, 'virtualenv.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)