Commit dcf3e4f7 authored by Guido Günther's avatar Guido Günther

Use assertRaises as context manager

for better readability

Gbp-Dch: Ignore
parent 57c671b7
......@@ -29,8 +29,7 @@ class TestHelp(TestCaseWithData):
def testHelp(self, script):
module = 'gbp.scripts.%s' % script
m = __import__(module, globals(), locals(), ['main'], 0)
self.assertRaises(SystemExit,
m.main,
['doesnotmatter', '--help'])
with self.assertRaises(SystemExit):
m.main(['doesnotmatter', '--help'])
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
......@@ -72,13 +72,8 @@ class TestDetection(unittest.TestCase):
open(self.tmpdir.join('source_1.2.orig.tar.gz'), "w").close()
open(self.tmpdir.join('source_1.2.orig.tar.xz'), "w").close()
repo = MockGitRepository(with_branch=False)
self.assertRaises(
GbpError,
export_orig.guess_comp_type,
'auto',
self.source,
repo,
str(self.tmpdir))
with self.assertRaises(GbpError):
export_orig.guess_comp_type('auto', self.source, repo, str(self.tmpdir))
def test_guess_comp_type_auto_bzip2(self):
subject = 'pristine-tar data for source_1.2-3.orig.tar.bz2'
......
......@@ -29,9 +29,8 @@ class TestWriteTree(testutils.DebianGitTestRepo):
"""Write out index file to non-existent dir"""
paths = self._write_testtree()
self.repo.add_files(paths)
self.assertRaises(gbp.git.GitRepositoryError,
self.repo.write_tree,
'/does/not/exist')
with self.assertRaises(gbp.git.GitRepositoryError):
self.repo.write_tree('/does/not/exist')
def test_write_tree(self):
"""Write out index file to alternate index file"""
......@@ -63,10 +62,7 @@ class TestWriteTree(testutils.DebianGitTestRepo):
# commit the same tree again using the previous commit as parent
self.repo.commit_tree(sha1, "second commit", parents=[commit])
# commit the same tree again using a non-existent parent
self.assertRaises(gbp.errors.GbpError,
self.repo.commit_tree,
sha1,
"failed commit",
['doesnotexist'])
with self.assertRaises(gbp.errors.GbpError):
self.repo.commit_tree(sha1, "failed commit", ['doesnotexist'])
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
......@@ -37,11 +37,8 @@ class TestGetUpstreamTree(testutils.DebianGitTestRepo):
self.add_file('foo')
options = MockOptions(upstream_tree='BRANCH',
upstream_branch='upstream')
self.assertRaises(gbp.errors.GbpError,
export_orig.git_archive_get_upstream_tree,
self.repo,
None,
options)
with self.assertRaises(gbp.errors.GbpError):
export_orig.git_archive_get_upstream_tree(self.repo, None, options)
def test_valid_tree(self):
"""Get upstream tree from a valid upstream tree"""
......@@ -55,11 +52,8 @@ class TestGetUpstreamTree(testutils.DebianGitTestRepo):
"""Getting upstream tree from an invalid tree must fail"""
self.add_file('foo')
options = MockOptions(upstream_tree='doesnotexist')
self.assertRaises(gbp.errors.GbpError,
export_orig.git_archive_get_upstream_tree,
self.repo,
None,
options)
with self.assertRaises(gbp.errors.GbpError):
export_orig.git_archive_get_upstream_tree(self.repo, None, options)
def test_valid_tag(self):
"""Get upstream tree from a valid tag"""
......@@ -76,10 +70,7 @@ class TestGetUpstreamTree(testutils.DebianGitTestRepo):
self.add_file('foo')
options = MockOptions(upstream_tree="TAG",
upstream_tag="upstream/%(version)s")
self.assertRaises(gbp.errors.GbpError,
export_orig.git_archive_get_upstream_tree,
self.repo,
self.source,
options)
with self.assertRaises(gbp.errors.GbpError):
export_orig.git_archive_get_upstream_tree(self.repo, self.source, options)
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
......@@ -184,7 +184,8 @@ class TestScriptDch(DebianGitTestRepo):
"""Test dch.py like gbp dch script does: new upstream version - snapshot - release"""
options = ["--snapshot", "--release"]
with capture_stderr() as c:
self.assertRaises(SystemExit, self.run_dch, options)
with self.assertRaises(SystemExit):
self.run_dch(options)
self.assertTrue("'--snapshot' and '--release' are incompatible options" in c.output())
def test_dch_main_new_upstream_version_with_distribution(self):
......
......@@ -156,7 +156,8 @@ class TestDpkgCompareVersions(unittest.TestCase):
self.assertEqual(ret, 0)
def testBadVersion(self):
self.assertRaises(CommandExecFailed, self.cmp, '_', '_ _')
with self.assertRaises(CommandExecFailed):
self.cmp('_', '_ _')
@unittest.skipIf(not os.path.exists('/usr/bin/dpkg'), 'Dpkg not found')
......
......@@ -36,8 +36,8 @@ class TestDebianSource(testutils.DebianGitTestRepo):
"""Test native package of format 3"""
source = DebianSource('.')
os.makedirs('debian/source')
self.assertRaises(DebianSourceError,
source.is_native)
with self.assertRaises(DebianSourceError):
source.is_native()
dsf = DebianSourceFormat.from_content("3.0", "native")
self.assertEqual(dsf.type, 'native')
......@@ -51,8 +51,8 @@ class TestDebianSource(testutils.DebianGitTestRepo):
"""Test native package without a debian/source/format file"""
source = DebianSource('.')
os.makedirs('debian/')
self.assertRaises(DebianSourceError,
source.is_native)
with self.assertRaises(DebianSourceError):
source.is_native()
with open('debian/changelog', 'w') as f:
f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low
......
......@@ -25,15 +25,12 @@ class TestSuperCommand(unittest.TestCase):
def test_import(self):
"""Test the importer itself"""
self.assertRaises(ImportError,
gbp.scripts.supercommand.import_command,
'not.allowed')
self.assertRaises(ImportError,
gbp.scripts.supercommand.import_command,
'not/allowed')
self.assertRaises(ImportError,
gbp.scripts.supercommand.import_command,
'0notallowed')
with self.assertRaises(ImportError):
gbp.scripts.supercommand.import_command('not.allowed')
with self.assertRaises(ImportError):
gbp.scripts.supercommand.import_command('not/allowed')
with self.assertRaises(ImportError):
gbp.scripts.supercommand.import_command('0notallowed')
self.assertIsNotNone(gbp.scripts.supercommand.import_command('pq'))
def test_invalid_command(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment