def _gitConfig(path): """ Set some config in the repo that Git requires to make commits. This isn't needed in real usage, just for tests. @param path: The path to the Git repository. @type path: L{FilePath} """ runCommand( [ "git", "config", "--file", path.child(".git").child("config").path, "user.name", '"someone"', ] ) runCommand( [ "git", "config", "--file", path.child(".git").child("config").path, "user.email", '"*****@*****.**"', ] )
def _buildMainDocumentation(self): """ Build main documentation with Sphinx. :rtype: `FilePath` :return: File path for HTML build output directory. """ self._setupTheme() logging.info("\tBuilding main documentation...") if self.examples: logging.info("\tIncluding examples...") html_output = self.docPath.child("_build").child('html') sphinx_build = ["sphinx-build", "-b", "html", self.docPath.path, html_output.path] logging.debug(" ".join(sphinx_build)) try: runCommand(sphinx_build) except CommandFailed, e: logging.info("") print("Error building main documentation with Sphinx:\n\n%s" % e[2]) sys.exit(1)
def _gitInit(path): """ Run a git init, and set some config that git requires. This isn't needed in real usage. @param path: The path to where the Git repo will be created. @type path: L{FilePath} """ runCommand(["git", "init", path.path]) _gitConfig(path)
def commitRepository(self, repository): """ Add and commit all the files from the Git repository specified. @type repository: L{FilePath} @params repository: The Git repository to commit into. """ runCommand(["git", "-C", repository.path, "add"] + glob.glob(repository.path + "/*")) runCommand(["git", "-C", repository.path, "commit", "-m", "hop"])
def _gitConfig(path): """ Set some config in the repo that Git requires to make commits. This isn't needed in real usage, just for tests. @param path: The path to the Git repository. @type path: L{FilePath} """ runCommand(["git", "config", "--file", path.child(".git").child("config").path, "user.name", '"someone"']) runCommand(["git", "config", "--file", path.child(".git").child("config").path, "user.email", '"*****@*****.**"'])
def test_noChangeFromTrunk(self): """ If there are no changes from trunk, then no need to check the topfiles """ runCommand(["git", "checkout", "-b", "mypatch"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckTopfileScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0, )) self.assertEqual( logs[-1], "On trunk or no diffs from trunk; no need to look at this.")
def test_noChangeFromTrunk(self): """ If there are no changes from trunk, then no need to check the topfiles """ runCommand(["git", "checkout", "-b", "mypatch"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckTopfileScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0,)) self.assertEqual( logs[-1], "On trunk or no diffs from trunk; no need to look at this.")
def setUp(self): self.origin = FilePath(self.mktemp()) _gitInit(self.origin) runCommand(["git", "checkout", "-b", "trunk"], cwd=self.origin.path) self.origin.child("test").setContent(b"test!") runCommand(["git", "add", self.origin.child("test").path], cwd=self.origin.path) runCommand(["git", "commit", "-m", "initial"], cwd=self.origin.path) self.repo = FilePath(self.mktemp()) runCommand(["git", "clone", self.origin.path, self.repo.path]) _gitConfig(self.repo)
def _createEgg(self): """ Helper method to create a Python .egg file. """ logging.info("\tBuilding egg...") build_dir = self.rootDirectory.child("build") build_dir.createDirectory() os.chdir(self.rootDirectory.path) egg_build = ["python", "setup.py", "bdist_egg", "--dist-dir", self.outputDirectory.path] logging.debug("\t\t" + " ".join(egg_build)) runCommand(egg_build) eggs = glob(os.path.join(self.outputDirectory.path, '*.egg')) egg = FilePath(eggs[0]) return egg
def test_onlyQuotes(self): """ Running it on a branch with only a quotefile change gives green. """ runCommand(["git", "checkout", "-b", "quotefile"], cwd=self.repo.path) fun = self.repo.child("docs").child("fun") fun.makedirs() quotes = fun.child("Twisted.Quotes") quotes.setContent(b"Beep boop") runCommand(["git", "add", quotes.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "quotes"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0,)) self.assertEqual(logs[-1], "Quotes change only; no newsfragment needed.")
def test_releaseWithNewsfragments(self): """ Running it on a release branch returns red if there are new newsfragments. """ runCommand(["git", "checkout", "-b", "release-16.11111-9001"], cwd=self.repo.path) newsfragments = self.repo.child("twisted").child("newsfragments") newsfragments.makedirs() fragment = newsfragments.child("1234.misc") fragment.setContent(b"") unrelated = self.repo.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", fragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "fragment"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1,)) self.assertEqual(logs[-1], "No newsfragments should be on the release branch.")
def test_preCommitAutoupdateWithNewsfragments(self): """ Running it on the autoupdate branch returns red if there are new newsfragments. """ runCommand(["git", "checkout", "-b", "pre-commit-ci-update-config"], cwd=self.repo.path) newsfragments = self.repo.child("twisted").child("newsfragments") newsfragments.makedirs() fragment = newsfragments.child("1234.misc") fragment.setContent(b"") unrelated = self.repo.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", fragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "fragment"], cwd=self.repo.path) logs = [] self.patch(os, "environ", PRECOMMIT_CI_ENVIRON) with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1, )) self.assertEqual( logs[-1], "No newsfragments should be present on an autoupdated branch.")
def test_newsfragmentAddedButWithOtherNewsfragments(self): """ Running it on a branch with a fragment in the topfiles dir added returns green, even if there are other files in the topfiles dir. """ runCommand(["git", "checkout", "-b", "quotefile"], cwd=self.repo.path) newsfragments = self.repo.child("twisted").child("newsfragments") newsfragments.makedirs() fragment = newsfragments.child("1234.misc") fragment.setContent(b"") unrelated = newsfragments.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", fragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "newsfragment"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0,)) self.assertEqual(logs[-1], "Found twisted/newsfragments/1234.misc")
def test_topfileButNotFragmentAdded(self): """ Running it on a branch with a non-fragment in the topfiles dir does not return green. """ runCommand(["git", "checkout", "-b", "quotefile"], cwd=self.repo.path) topfiles = self.repo.child("twisted").child("topfiles") topfiles.makedirs() notFragment = topfiles.child("1234.txt") notFragment.setContent(b"") unrelated = self.repo.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", notFragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "not topfile"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1,)) self.assertEqual(logs[-1], "No newsfragment found. Have you committed it?")
def test_topfileButNotFragmentAdded(self): """ Running it on a branch with a non-fragment in the topfiles dir does not return green. """ runCommand(["git", "checkout", "-b", "quotefile"], cwd=self.repo.path) topfiles = self.repo.child("twisted").child("topfiles") topfiles.makedirs() notFragment = topfiles.child("1234.txt") notFragment.setContent(b"") unrelated = self.repo.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", notFragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "not topfile"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1, )) self.assertEqual(logs[-1], "No newsfragment found. Have you committed it?")
def test_newsfragmentAddedButWithOtherNewsfragments(self): """ Running it on a branch with a fragment in the topfiles dir added returns green, even if there are other files in the topfiles dir. """ runCommand(["git", "checkout", "-b", "quotefile"], cwd=self.repo.path) newsfragments = self.repo.child("twisted").child("newsfragments") newsfragments.makedirs() fragment = newsfragments.child("1234.misc") fragment.setContent(b"") unrelated = newsfragments.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", fragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "newsfragment"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0, )) self.assertEqual(logs[-1], "Found twisted/newsfragments/1234.misc")
def test_releaseWithNewsfragments(self): """ Running it on a release branch returns red if there are new newsfragments. """ runCommand(["git", "checkout", "-b", "release-16.11111-9001"], cwd=self.repo.path) newsfragments = self.repo.child("twisted").child("newsfragments") newsfragments.makedirs() fragment = newsfragments.child("1234.misc") fragment.setContent(b"") unrelated = self.repo.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", fragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "fragment"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1, )) self.assertEqual(logs[-1], "No newsfragments should be on the release branch.")
def setUp(self): self.origin = FilePath(self.mktemp()) _gitInit(self.origin) runCommand(["git", "checkout", "-b", "trunk"], cwd=self.origin.path) self.origin.child("test").setContent(b"test!") runCommand(["git", "add", self.origin.child("test").path], cwd=self.origin.path) runCommand(["git", "commit", "-m", "initial"], cwd=self.origin.path) self.repo = FilePath(self.mktemp()) runCommand(["git", "clone", self.origin.path, self.repo.path]) _gitConfig(self.repo) # Inject a rigged environment to have full control over the test execution. self.patch(os, "environ", GENERIC_CI_ENVIRON)
def _buildAPIDocumentation(self): """ Build API documentation with Epydoc. :rtype: `FilePath` :return: File path for HTML build output directory. """ logging.info("\tBuilding API documentation...") html_output = self.docPath.child("_build").child('html').child('api') os.chdir(self.rootDirectory.path) epydoc_build = ["epydoc", "--config", "setup.cfg", "--debug", "--output", html_output.path, "--simple-term"] logging.debug(" ".join(epydoc_build)) try: runCommand(epydoc_build) except CommandFailed, e: print("\nError building API documentation with Epydoc:\n\n%s" % e[2]) logging.error("\tError building API documentation, check Epydoc output. Skipping...") logging.error("")
def test_diffFromTrunkNoNewsfragments(self): """ If there are changes from trunk, then there should also be a newsfragment. """ runCommand(["git", "checkout", "-b", "mypatch"], cwd=self.repo.path) somefile = self.repo.child("somefile") somefile.setContent(b"change") runCommand(["git", "add", somefile.path, somefile.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "some file"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1,)) self.assertEqual(logs[-1], "No newsfragment found. Have you committed it?")
def test_diffFromTrunkNoTopfiles(self): """ If there are changes from trunk, then there should also be a topfile. """ runCommand(["git", "checkout", "-b", "mypatch"], cwd=self.repo.path) somefile = self.repo.child("somefile") somefile.setContent(b"change") runCommand(["git", "add", somefile.path, somefile.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "some file"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckTopfileScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (1,)) self.assertEqual(logs[-1], "No newsfragment found. Have you committed it?")
def test_release(self): """ Running it on a release branch returns green if there is no newsfragments even if there are changes. """ runCommand( ["git", "checkout", "-b", "release-16.11111-9001"], cwd=self.repo.path ) somefile = self.repo.child("somefile") somefile.setContent(b"change") runCommand(["git", "add", somefile.path, somefile.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "some file"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0,)) self.assertEqual(logs[-1], "Release branch with no newsfragments, all good.")
def test_preCommitAutoupdate(self): """ Running it on the autoupdate branch returns green if there is no newsfragments even if there are changes. """ runCommand(["git", "checkout", "-b", "pre-commit-ci-update-config"], cwd=self.repo.path) somefile = self.repo.child("somefile") somefile.setContent(b"change") runCommand(["git", "add", somefile.path, somefile.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "some file"], cwd=self.repo.path) logs = [] self.patch(os, "environ", PRECOMMIT_CI_ENVIRON) with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0, )) self.assertEqual( logs[-1], "Autoupdated branch with no newsfragments, all good.")
def test_release(self): """ Running it on a release branch returns green if there is no newsfragments even if there are changes. """ runCommand(["git", "checkout", "-b", "release-16.11111-9001"], cwd=self.repo.path) somefile = self.repo.child("somefile") somefile.setContent(b"change") runCommand(["git", "add", somefile.path, somefile.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "some file"], cwd=self.repo.path) logs = [] with self.assertRaises(SystemExit) as e: CheckNewsfragmentScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0,)) self.assertEqual(logs[-1], "Release branch with no newsfragments, all good.")
pydoctorSkip = "Pydoctor is not present." else: if getattr(pydoctor, "version_info", (0,)) < (0, 1): pydoctorSkip = "Pydoctor is too old." else: pydoctorSkip = skip if not skip and which("sphinx-build"): sphinxSkip = None else: sphinxSkip = "Sphinx not available." if not skip and which("git"): gitVersion = runCommand(["git", "--version"]).split(b" ")[2].split(b".") # We want git 2.0 or above. if int(gitVersion[0]) >= 2: gitSkip = skip else: gitSkip = "old git is present" else: gitSkip = "git is not present." class ExternalTempdirTestCase(TestCase): """ A test case which has mkdir make directories outside of the usual spot, so that Git commands don't interfere with the Twisted checkout. """
pydoctorSkip = u"Pydoctor is not present." else: if getattr(pydoctor, u"version_info", (0,)) < (0, 1): pydoctorSkip = u"Pydoctor is too old." else: pydoctorSkip = skip if not skip and which(u"sphinx-build"): sphinxSkip = None else: sphinxSkip = u"Sphinx not available." if not skip and which("git"): gitVersion = runCommand(["git", "--version"]).split(b" ")[2].split(b".") # We want git 2.0 or above. if int(gitVersion[0]) >= 2: gitSkip = skip else: gitSkip = u"old git is present" else: gitSkip = u"git is not present." class ExternalTempdirTestCase(TestCase): """ A test case which has mkdir make directories outside of the usual spot, so that Git commands don't interfere with the Twisted checkout.