]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/build_helpers/test-with-fake-dists.py
tests: test-with-fake-dists.py has the side-effect of injecting a fake package into...
[tahoe-lafs/tahoe-lafs.git] / misc / build_helpers / test-with-fake-dists.py
1 #!/usr/bin/env python
2
3 # We put a fake "pycryptopp-0.5.24.egg" package and a fake
4 # "pycryptopp-9.9.99.tar.gz" into a directory, but the latter is
5 # booby-trapped so it will raise an exception when you try to build
6 # it.
7
8 # Then we run "python setup.py test -s
9 # buildtest.test_with_fake_dist", which imports pycryptopp
10 # and passes if pycryptopp.__version__ == '0.5.24'.
11
12 # (If building succeeded -- meaning that you didn't try to build the
13 # booby-trapped 9.9.99 -- but pycryptopp.__version__ != '0.5.24' then
14 # that means a different version of pycryptopp was already installed
15 # so neither of the two fake pycryptopp packages were needed. In that
16 # case this test should be treated as a "skip" -- the functionality
17 # under test can't be exercised on the current system.)
18
19 # The goal is to turn red if the build system tries to build the
20 # source dist when it could have used the binary dist.
21
22 # (Note that for this test to make sense, tahoe-lafs needs to be
23 # asking for a version of pycryptopp which can be satisfied by either
24 # 0.5.24 or 0.5.25. At the time of this writing it requires >= 0.5.20
25 # on x86 and >= 0.5.14 on other architectures.)
26
27 import StringIO, glob, os, platform, shutil, subprocess, sys, tarfile, zipfile
28 import pkg_resources
29
30 fake_distdir = 'tahoe-deps'
31 fake_distname = "pycryptopp"
32 fake_sdistversion = "9.9.99"
33 fake_bdistversion = "0.5.24"
34 sdist_setup = "raise Exception('Aha I caught you trying to build me. I am a fake pycryptopp 9.9.99 sdist and you should be satisfied with a bdist.')"
35
36 testsuite = "buildtest.test_build_with_fake_dist"
37
38 dist_dirname = os.path.join(os.getcwd(), fake_distdir)
39
40 try:
41     os.makedirs(dist_dirname)
42 except OSError:
43     # probably already exists
44     pass
45
46 bdist_egg_name = os.path.join(dist_dirname, '%s-%s-py%s.%s-%s.egg' % (fake_distname, fake_bdistversion, platform.python_version_tuple()[0], platform.python_version_tuple()[1], pkg_resources.get_supported_platform()))
47 try:
48     bdist_egg = zipfile.ZipFile(bdist_egg_name, 'w')
49     bdist_egg.writestr('pycryptopp/__init__.py', '__version__ = "%s"\n' % (fake_bdistversion,))
50     bdist_egg.close()
51
52     sdist_name = os.path.join(dist_dirname, '%s-%s.tar' % (fake_distname, fake_sdistversion))
53     sdist = tarfile.open(sdist_name, 'w:gz')
54     sdist.errorlevel =2
55     tarinfo = tarfile.TarInfo('setup.py')
56     tarinfo.errorlevel =2
57     tarinfo.size = len(sdist_setup)
58     sdist.addfile(tarinfo, StringIO.StringIO(sdist_setup))
59     sdist.close()
60
61     setuppy="setup.py"
62     os.environ['PATH']=os.path.join(os.getcwd(), 'src')+os.pathsep+os.environ['PATH']
63     eggs = [os.path.realpath(p) for p in glob.glob(os.path.join('..', '*.egg')) if not 'pycryptopp' in p]
64     os.environ['PYTHONPATH']=os.pathsep+os.pathsep.join(eggs)+os.pathsep+os.environ.get('PYTHONPATH','')
65     sys.exit(subprocess.call([sys.executable, setuppy, "-v", "test", "-s", testsuite], env=os.environ))
66 finally:
67     os.remove(bdist_egg_name)
68     os.remove(sdist_name)
69     shutil.rmtree('support')
70     [shutil.rmtree(p) for p in glob.glob('pycryptopp*.egg')]