summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-11-12 17:48:03 +0100
committerGuido Günther <agx@sigxcpu.org>2017-11-12 17:48:03 +0100
commitdcf3e4f704285c7df84c425eb0fd8c3fecbc98c2 (patch)
tree85e09f927a33acccff32492b4aafdfc6a911a012
parent57c671b7f2050edfb5a6e01330c2391bde04dbb5 (diff)
Use assertRaises as context manager
for better readability Gbp-Dch: Ignore
-rw-r--r--tests/01_test_help.py5
-rw-r--r--tests/05_test_detection.py9
-rw-r--r--tests/09_test_write_tree.py12
-rw-r--r--tests/10_test_get_upstream_tree.py21
-rw-r--r--tests/11_test_dch_main.py3
-rw-r--r--tests/12_test_deb.py3
-rw-r--r--tests/15_test_DebianSource.py8
-rw-r--r--tests/16_test_supercommand.py15
8 files changed, 28 insertions, 48 deletions
diff --git a/tests/01_test_help.py b/tests/01_test_help.py
index c4cc34ea..ed085ba7 100644
--- a/tests/01_test_help.py
+++ b/tests/01_test_help.py
@@ -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\:·:
diff --git a/tests/05_test_detection.py b/tests/05_test_detection.py
index b72aa943..d2579dfa 100644
--- a/tests/05_test_detection.py
+++ b/tests/05_test_detection.py
@@ -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'
diff --git a/tests/09_test_write_tree.py b/tests/09_test_write_tree.py
index 0ec0ccb2..d95440b1 100644
--- a/tests/09_test_write_tree.py
+++ b/tests/09_test_write_tree.py
@@ -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\:·:
diff --git a/tests/10_test_get_upstream_tree.py b/tests/10_test_get_upstream_tree.py
index 8ee762b5..cd650576 100644
--- a/tests/10_test_get_upstream_tree.py
+++ b/tests/10_test_get_upstream_tree.py
@@ -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\:·:
diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py
index f0f4560e..bebb1e4c 100644
--- a/tests/11_test_dch_main.py
+++ b/tests/11_test_dch_main.py
@@ -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):
diff --git a/tests/12_test_deb.py b/tests/12_test_deb.py
index 669896a4..d06bc432 100644
--- a/tests/12_test_deb.py
+++ b/tests/12_test_deb.py
@@ -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')
diff --git a/tests/15_test_DebianSource.py b/tests/15_test_DebianSource.py
index 98d5f706..f7f333b6 100644
--- a/tests/15_test_DebianSource.py
+++ b/tests/15_test_DebianSource.py
@@ -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
diff --git a/tests/16_test_supercommand.py b/tests/16_test_supercommand.py
index d15ec797..f9172df7 100644
--- a/tests/16_test_supercommand.py
+++ b/tests/16_test_supercommand.py
@@ -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):