]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/build_helpers/test-dont-install-newer-dep-when-you-already-have-sufficiently-new-one.py
Don't call time.tzset() if the platform doesn't have it. fixes ticket:2723
[tahoe-lafs/tahoe-lafs.git] / misc / build_helpers / test-dont-install-newer-dep-when-you-already-have-sufficiently-new-one.py
1 #!/usr/bin/env python
2
3 import StringIO, os, platform, shutil, subprocess, sys, tarfile, zipfile
4 import pkg_resources
5
6 def test():
7     # We put a "fakedependency-1.0.0.egg" package and a
8     # "fakedependency-9.9.99.tar.gz" into a directory, but the latter is
9     # booby-trapped so it will raise an exception when you try to build it.
10     #
11     # Then we run
12     #
13     #   python setup.py --fakedependency -v test -s buildtest.test_build_with_fake_dist
14     #
15     # which requires "fakedependency >= 1.0.0", imports fakedependency
16     # and passes if fakedependency.__version__ == '1.0.0'.
17     #
18     # The goal is to turn red if the build system tries to build the
19     # source dist when it could have used the binary dist.
20     #
21     # Note that for this test to make sense, Tahoe-LAFS needs to be asking
22     # for a version of fakedependency which can be satisfied by 1.0.0.
23     # The --fakedependency option to setup.py arranges that.
24
25     fake_distdir = 'tahoe-deps'
26     fake_distname = "fakedependency"
27     fake_sdistversion = "9.9.99"
28     fake_bdistversion = "1.0.0"
29     sdist_setup = "raise Exception('Aha I caught you trying to build me. I am a fakedependency 9.9.99 sdist and you should be satisfied with a bdist.')"
30
31     testsuite = "buildtest.test_build_with_fake_dist"
32
33     dist_dirname = os.path.join(os.getcwd(), fake_distdir)
34
35     try:
36         os.makedirs(dist_dirname)
37     except OSError:
38         # probably already exists
39         pass
40
41     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()))
42     try:
43         bdist_egg = zipfile.ZipFile(bdist_egg_name, 'w')
44         bdist_egg.writestr('fakedependency/__init__.py', '__version__ = "%s"\n' % (fake_bdistversion,))
45         bdist_egg.close()
46
47         sdist_name = os.path.join(dist_dirname, '%s-%s.tar' % (fake_distname, fake_sdistversion))
48         sdist = tarfile.open(sdist_name, 'w:gz')
49         sdist.errorlevel = 2
50         tarinfo = tarfile.TarInfo('setup.py')
51         tarinfo.errorlevel = 2
52         tarinfo.size = len(sdist_setup)
53         sdist.addfile(tarinfo, StringIO.StringIO(sdist_setup))
54         sdist.close()
55
56         sys.exit(subprocess.call([sys.executable, "setup.py", "--fakedependency", "-v", "test", "-s", testsuite],
57                                  env=os.environ))
58     finally:
59         os.remove(bdist_egg_name)
60         os.remove(sdist_name)
61         cleanup()
62
63 def cleanup():
64     egg_info = os.path.join('src', 'allmydata_tahoe.egg-info')
65     bin_tahoe = os.path.join('bin', 'tahoe')
66     bin_tahoe_pyscript = os.path.join('bin', 'tahoe.pyscript')
67
68     if os.path.exists('build'):
69         shutil.rmtree('build')
70     if os.path.exists('support'):
71         shutil.rmtree('support')
72     if os.path.exists(egg_info):
73         shutil.rmtree(egg_info)
74     if os.path.exists(bin_tahoe):
75         os.remove(bin_tahoe)
76     if os.path.exists(bin_tahoe_pyscript):
77         os.remove(bin_tahoe_pyscript)
78
79 if __name__ == '__main__':
80     test()