| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2001-2008 Twisted Matrix Laboratories. | |
| 2 # See LICENSE for details. | |
| 3 | |
| 4 """ | |
| 5 Tests for parts of our release automation system. | |
| 6 """ | |
| 7 | |
| 8 | |
| 9 import os | |
| 10 | |
| 11 from distutils.core import Distribution | |
| 12 | |
| 13 from twisted.trial.unittest import TestCase | |
| 14 | |
| 15 from twisted.python import dist | |
| 16 from twisted.python.dist import get_setup_args, ConditionalExtension | |
| 17 from twisted.python.filepath import FilePath | |
| 18 | |
| 19 | |
| 20 class SetupTest(TestCase): | |
| 21 """ | |
| 22 Tests for L{get_setup_args}. | |
| 23 """ | |
| 24 def test_conditionalExtensions(self): | |
| 25 """ | |
| 26 Passing C{conditionalExtensions} as a list of L{ConditionalExtension} | |
| 27 objects to get_setup_args inserts a custom build_ext into the result | |
| 28 which knows how to check whether they should be | |
| 29 """ | |
| 30 good_ext = ConditionalExtension("whatever", ["whatever.c"], | |
| 31 condition=lambda b: True) | |
| 32 bad_ext = ConditionalExtension("whatever", ["whatever.c"], | |
| 33 condition=lambda b: False) | |
| 34 args = get_setup_args(conditionalExtensions=[good_ext, bad_ext]) | |
| 35 # ext_modules should be set even though it's not used. See comment | |
| 36 # in get_setup_args | |
| 37 self.assertEquals(args["ext_modules"], [good_ext, bad_ext]) | |
| 38 cmdclass = args["cmdclass"] | |
| 39 build_ext = cmdclass["build_ext"] | |
| 40 builder = build_ext(Distribution()) | |
| 41 builder.prepare_extensions() | |
| 42 self.assertEquals(builder.extensions, [good_ext]) | |
| 43 | |
| 44 | |
| 45 def test_win32Definition(self): | |
| 46 """ | |
| 47 When building on Windows NT, the WIN32 macro will be defined as 1. | |
| 48 """ | |
| 49 ext = ConditionalExtension("whatever", ["whatever.c"], | |
| 50 define_macros=[("whatever", 2)]) | |
| 51 args = get_setup_args(conditionalExtensions=[ext]) | |
| 52 builder = args["cmdclass"]["build_ext"](Distribution()) | |
| 53 self.patch(os, "name", "nt") | |
| 54 builder.prepare_extensions() | |
| 55 self.assertEquals(ext.define_macros, [("whatever", 2), ("WIN32", 1)]) | |
| 56 | |
| 57 | |
| 58 | |
| 59 class GetVersionTest(TestCase): | |
| 60 """ | |
| 61 Tests for L{dist.getVersion}. | |
| 62 """ | |
| 63 | |
| 64 def setUp(self): | |
| 65 self.dirname = self.mktemp() | |
| 66 os.mkdir(self.dirname) | |
| 67 | |
| 68 def test_getVersionCore(self): | |
| 69 """ | |
| 70 Test that getting the version of core reads from the | |
| 71 [base]/_version.py file. | |
| 72 """ | |
| 73 f = open(os.path.join(self.dirname, "_version.py"), "w") | |
| 74 f.write(""" | |
| 75 from twisted.python import versions | |
| 76 version = versions.Version("twisted", 0, 1, 2) | |
| 77 """) | |
| 78 f.close() | |
| 79 self.assertEquals(dist.getVersion("core", base=self.dirname), "0.1.2") | |
| 80 | |
| 81 def test_getVersionOther(self): | |
| 82 """ | |
| 83 Test that getting the version of a non-core project reads from | |
| 84 the [base]/[projname]/_version.py file. | |
| 85 """ | |
| 86 os.mkdir(os.path.join(self.dirname, "blat")) | |
| 87 f = open(os.path.join(self.dirname, "blat", "_version.py"), "w") | |
| 88 f.write(""" | |
| 89 from twisted.python import versions | |
| 90 version = versions.Version("twisted.blat", 9, 8, 10) | |
| 91 """) | |
| 92 f.close() | |
| 93 self.assertEquals(dist.getVersion("blat", base=self.dirname), "9.8.10") | |
| 94 | |
| 95 | |
| 96 class GetScriptsTest(TestCase): | |
| 97 | |
| 98 def test_scriptsInSVN(self): | |
| 99 """ | |
| 100 getScripts should return the scripts associated with a project | |
| 101 in the context of Twisted SVN. | |
| 102 """ | |
| 103 basedir = self.mktemp() | |
| 104 os.mkdir(basedir) | |
| 105 os.mkdir(os.path.join(basedir, 'bin')) | |
| 106 os.mkdir(os.path.join(basedir, 'bin', 'proj')) | |
| 107 f = open(os.path.join(basedir, 'bin', 'proj', 'exy'), 'w') | |
| 108 f.write('yay') | |
| 109 f.close() | |
| 110 scripts = dist.getScripts('proj', basedir=basedir) | |
| 111 self.assertEquals(len(scripts), 1) | |
| 112 self.assertEquals(os.path.basename(scripts[0]), 'exy') | |
| 113 | |
| 114 | |
| 115 def test_scriptsInRelease(self): | |
| 116 """ | |
| 117 getScripts should return the scripts associated with a project | |
| 118 in the context of a released subproject tarball. | |
| 119 """ | |
| 120 basedir = self.mktemp() | |
| 121 os.mkdir(basedir) | |
| 122 os.mkdir(os.path.join(basedir, 'bin')) | |
| 123 f = open(os.path.join(basedir, 'bin', 'exy'), 'w') | |
| 124 f.write('yay') | |
| 125 f.close() | |
| 126 scripts = dist.getScripts('proj', basedir=basedir) | |
| 127 self.assertEquals(len(scripts), 1) | |
| 128 self.assertEquals(os.path.basename(scripts[0]), 'exy') | |
| 129 | |
| 130 | |
| 131 def test_noScriptsInSVN(self): | |
| 132 """ | |
| 133 When calling getScripts for a project which doesn't actually | |
| 134 have any scripts, in the context of an SVN checkout, an | |
| 135 empty list should be returned. | |
| 136 """ | |
| 137 basedir = self.mktemp() | |
| 138 os.mkdir(basedir) | |
| 139 os.mkdir(os.path.join(basedir, 'bin')) | |
| 140 os.mkdir(os.path.join(basedir, 'bin', 'otherproj')) | |
| 141 scripts = dist.getScripts('noscripts', basedir=basedir) | |
| 142 self.assertEquals(scripts, []) | |
| 143 | |
| 144 | |
| 145 def test_getScriptsTopLevel(self): | |
| 146 """ | |
| 147 Passing the empty string to getScripts returns scripts that are (only) | |
| 148 in the top level bin directory. | |
| 149 """ | |
| 150 basedir = FilePath(self.mktemp()) | |
| 151 basedir.createDirectory() | |
| 152 bindir = basedir.child("bin") | |
| 153 bindir.createDirectory() | |
| 154 included = bindir.child("included") | |
| 155 included.setContent("yay included") | |
| 156 subdir = bindir.child("subdir") | |
| 157 subdir.createDirectory() | |
| 158 subdir.child("not-included").setContent("not included") | |
| 159 | |
| 160 scripts = dist.getScripts("", basedir=basedir.path) | |
| 161 self.assertEquals(scripts, [included.path]) | |
| 162 | |
| 163 | |
| 164 def test_noScriptsInSubproject(self): | |
| 165 """ | |
| 166 When calling getScripts for a project which doesn't actually | |
| 167 have any scripts in the context of that project's individual | |
| 168 project structure, an empty list should be returned. | |
| 169 """ | |
| 170 basedir = self.mktemp() | |
| 171 os.mkdir(basedir) | |
| 172 scripts = dist.getScripts('noscripts', basedir=basedir) | |
| 173 self.assertEquals(scripts, []) | |
| OLD | NEW |