def test_topfileAddedButWithOtherTopfiles(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) topfiles = self.repo.child("twisted").child("newsfragments") topfiles.makedirs() fragment = topfiles.child("1234.misc") fragment.setContent(b"") unrelated = topfiles.child("somefile") unrelated.setContent(b"Boo") runCommand(["git", "add", fragment.path, unrelated.path], cwd=self.repo.path) runCommand(["git", "commit", "-m", "topfile"], 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], "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("newsfragments") 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: 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_releaseWithTopfiles(self): """ Running it on a release branch returns red if there are new topfiles. """ runCommand(["git", "checkout", "-b", "release-16.11111-9001"], cwd=self.repo.path) topfiles = self.repo.child("twisted").child("newsfragments") topfiles.makedirs() fragment = topfiles.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: CheckTopfileScript(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_noArgs(self): """ Too few arguments returns a failure. """ logs = [] with self.assertRaises(SystemExit) as e: CheckTopfileScript(logs.append).main([]) self.assertEqual(e.exception.args, ("Must specify one argument: the Twisted checkout", ))
def test_trunk(self): """ Running it on trunk always gives green. """ 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 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_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: CheckTopfileScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0, )) self.assertEqual(logs[-1], "Quotes change only; no newsfragment needed.")
def test_release(self): """ Running it on a release branch returns green if there is no topfiles 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: CheckTopfileScript(logs.append).main([self.repo.path]) self.assertEqual(e.exception.args, (0, )) self.assertEqual(logs[-1], "Release branch with no newsfragments, all good.")