Mercurial > hg > carton
view tests/doctest.txt @ 34:261e2d2d26ad
update documentation
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 11 Jul 2011 15:03:50 -0700 |
parents | dace84448c25 |
children |
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 Ensure you're bringing along carton:: >>> packaged_carton = os.path.join(bin, 'carton.py') >>> os.path.exists(packaged_carton) True >>> carton_module = carton.__file__.rstrip('c') >>> os.path.exists(carton_module) True >>> file(packaged_carton).read() == file(carton_module).read() 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)