| | 201 | class GetAllScriptsTest(TestCase): |
| | 202 | """ |
| | 203 | Tests for L{dist.getAllScripts} which returns all the scripts that should be |
| | 204 | included in a complete distribution of Twisted, with its subprojects. |
| | 205 | """ |
| | 206 | |
| | 207 | # getAllScripts relies on the list twisted.python.dist.twisted_subprojects |
| | 208 | # to tell it what subprojects might have scripts it needs to get. It |
| | 209 | # searches recursively in bin/, at the root of the Twisted distribution. |
| | 210 | # Thus testing it relies on manipulating the contents of that list and |
| | 211 | # directory. |
| | 212 | |
| | 213 | def setUp(self): |
| | 214 | # A mock up of twisted's root directory. |
| | 215 | basedir = self.mktemp() |
| | 216 | os.mkdir(basedir) |
| | 217 | os.mkdir(os.path.join(basedir, 'bin')) |
| | 218 | |
| | 219 | # getAllScripts uses a hardcoded relative path. |
| | 220 | self.old_cwd = os.getcwd() |
| | 221 | os.chdir(basedir) |
| | 222 | |
| | 223 | def tearDown(self): |
| | 224 | os.chdir(self.old_cwd) |
| | 225 | # The temporary directories will be deleted by Trial. |
| | 226 | |
| | 227 | def test_getsCorrectScripts(self): |
| | 228 | """ |
| | 229 | getAllScripts should return exactly the scripts in Twisted and its |
| | 230 | subprojects that should be included in a distribution. It may encounter |
| | 231 | additional scripts, but no script should be included unless it is part |
| | 232 | of a subproject listed in twisted_subprojects. |
| | 233 | """ |
| | 234 | import os |
| | 235 | from twisted.python import dist |
| | 236 | |
| | 237 | # Assuming getScripts works, all we need to test for is that |
| | 238 | # getAllScripts calls getScripts for every subproject and "" (bin/). |
| | 239 | directories_queried = list() |
| | 240 | def mock_getScripts(projname, basedir=''): |
| | 241 | directories_queried.append(projname) |
| | 242 | return ["dummy_script", "dummy_script_2"] |
| | 243 | self.patch(dist, "getScripts", mock_getScripts) |
| | 244 | |
| | 245 | # Create some dummy subprojects for getAllScripts to look at. |
| | 246 | dummy_subprojects = ["random", "project", "names", "kitty_kat"] |
| | 247 | # Also create some more directories that LOOK like subprojects but |
| | 248 | # aren't listed as subprojects. getAllScripts should ignore them. |
| | 249 | red_herrings = ["kitten", "cat"] |
| | 250 | for name in dummy_subprojects + red_herrings: |
| | 251 | os.mkdir(os.path.join("bin", name)) |
| | 252 | self.patch(dist, "twisted_subprojects", dummy_subprojects) |
| | 253 | |
| | 254 | scripts = dist.getAllScripts() |
| | 255 | |
| | 256 | # Order doesn't matter. Duplication does. |
| | 257 | self.assertEqual(sorted(directories_queried), |
| | 258 | sorted(dummy_subprojects + [''])) |
| | 259 | self.assertEqual(scripts, ["dummy_script", "dummy_script_2"]*5) |
| | 260 | |