| | 202 | class GetAllScriptsTest(TestCase): |
| | 203 | """ |
| | 204 | Tests for L{dist.getAllScripts} which lists all the scripts that should be |
| | 205 | included in a complete distribution of Twisted, with its subprojects. |
| | 206 | """ |
| | 207 | |
| | 208 | |
| | 209 | # getAllScripts relies on a list in twisted.python.dist.twisted_subprojects |
| | 210 | # to tell it what subprojects might have scripts it needs to get. It |
| | 211 | # searches recursively in bin/, at the root of the Twisted distribution, for |
| | 212 | # directories that have the same name as a listed subproject. It then calls |
| | 213 | # getScripts on these directories to extract the scripts from them. It also |
| | 214 | # tries to extract scripts from bin/ itself, because Twisted core stores |
| | 215 | # scripts there. |
| | 216 | # |
| | 217 | # Thus testing it relies on manipulating the contents of that list and |
| | 218 | # directory. |
| | 219 | |
| | 220 | |
| | 221 | def setUp(self): |
| | 222 | # A mock up of Twisted's root directory. |
| | 223 | basedir = FilePath(self.mktemp()) |
| | 224 | self.script_directory = basedir.child("bin") |
| | 225 | self.script_directory.makedirs() |
| | 226 | # The temporary directories will be deleted by Trial. |
| | 227 | |
| | 228 | # getAllScripts uses a hardcoded relative path. |
| | 229 | self.addCleanup(os.chdir, os.getcwd()) |
| | 230 | os.chdir(basedir.path) |
| | 231 | |
| | 232 | |
| | 233 | def test_getsCorrectScripts(self): |
| | 234 | """ |
| | 235 | L{getAllScripts} lists exactly the scripts in Twisted and its |
| | 236 | subprojects that should be included in a distribution. It may encounter |
| | 237 | additional scripts, files, or directories, but it will not list them |
| | 238 | unless they are part of a Twisted subproject (see |
| | 239 | twisted.dist.twisted_subprojects) or Twisted core. |
| | 240 | """ |
| | 241 | # Replace getScripts with a stub that records its interactions |
| | 242 | # with getAllScripts. The real getScripts is tested separately. |
| | 243 | directoriesQueried = [] |
| | 244 | scriptsGiven = [] |
| | 245 | def stubGetScripts(projname, basedir=''): |
| | 246 | directoriesQueried.append(projname) |
| | 247 | scripts = ["dummyScript", "dummyScript2"] |
| | 248 | scriptsGiven.extend(scripts) |
| | 249 | return scripts |
| | 250 | self.patch(dist, "getScripts", stubGetScripts) |
| | 251 | |
| | 252 | # Create some directories that represent dummy subprojects for |
| | 253 | # getAllScripts to look at. Get all scripts should ask getScripts to |
| | 254 | # get scripts from these directories. |
| | 255 | dummySubprojects = ["random", "subproject", "names", "kitty_kat"] |
| | 256 | # Create some more directories in bin that aren't listed as |
| | 257 | # subprojects. getAllScripts should ignore them. |
| | 258 | redHerringDirectories = ["some", "directories", "meow"] |
| | 259 | # Create some files that match the names of subprojects. getAllScripts |
| | 260 | # should ignore these as well. |
| | 261 | redHerringFiles = ["a", "few", "files"] |
| | 262 | # Just for kicks: files that do NOT match the name of a subproject. |
| | 263 | # These should also be ignored. |
| | 264 | completelyUnrelatedFiles = ["unrelated", "file"] |
| | 265 | |
| | 266 | self.patch( |
| | 267 | dist, "twisted_subprojects", dummySubprojects + redHerringFiles) |
| | 268 | |
| | 269 | for name in dummySubprojects + redHerringDirectories: |
| | 270 | self.script_directory.child(name).makedirs() |
| | 271 | for name in redHerringFiles + completelyUnrelatedFiles: |
| | 272 | self.script_directory.child(name).touch() |
| | 273 | # These are in Trial's temp directory, so we don't have to worry about |
| | 274 | # deleting them. |
| | 275 | |
| | 276 | scriptsReturned = dist.getAllScripts() |
| | 277 | |
| | 278 | # getAllScripts should call getScripts once on each directory which |
| | 279 | # corresponds to a subproject, and also on the current directory (for |
| | 280 | # the core subproject). It may do this in any order. |
| | 281 | self.assertEqual(Counter(directoriesQueried), |
| | 282 | Counter(dummySubprojects + [''])) |
| | 283 | # getAllScripts should collect all the scripts returned by getScripts, |
| | 284 | # in any order. |
| | 285 | self.assertEqual(Counter(scriptsReturned), |
| | 286 | Counter(scriptsGiven)) |
| | 287 | |
| | 288 | |
| | 289 | |