[PATCH 1/2] tests: Don't use assertRaises as a context manager

Mathieu Bridon bochecha at fedoraproject.org
Thu Apr 16 08:38:17 UTC 2015


From: Mathieu Bridon <bochecha at daitauha.fr>

assertRaises can only be used as a context manager with Python >= 2.7,
but we still have 2.6 on EL6.
---
 test/test_sources.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/test/test_sources.py b/test/test_sources.py
index 747abe2..9464325 100644
--- a/test/test_sources.py
+++ b/test/test_sources.py
@@ -94,9 +94,11 @@ class SourcesFileTestCase(unittest.TestCase):
                  ]
 
         for line in lines:
-            with self.assertRaises(sources.MalformedLineError):
+            def raises():
                 s.parse_line(line)
 
+            self.assertRaises(sources.MalformedLineError, raises)
+
     def test_open_new_file(self):
         s = sources.SourcesFile(self.sourcesfile, 'bsd')
         self.assertEqual(len(s.entries), 0)
@@ -180,8 +182,10 @@ class SourcesFileTestCase(unittest.TestCase):
         with open(self.sourcesfile, 'w') as f:
             f.write(line)
 
-        with self.assertRaises(sources.MalformedLineError):
-            return sources.SourcesFile(self.sourcesfile, 'bsd')
+        def raises():
+            sources.SourcesFile(self.sourcesfile, 'bsd')
+
+        self.assertRaises(sources.MalformedLineError, raises)
 
     def test_add_entry(self):
         s = sources.SourcesFile(self.sourcesfile, 'bsd')
@@ -214,9 +218,11 @@ class SourcesFileTestCase(unittest.TestCase):
         self.assertEqual(len(s.entries), 1)
         self.assertEqual(str(s.entries[-1]), 'MD5 (afile) = ahash\n')
 
-        with self.assertRaises(sources.HashtypeMixingError):
+        def raises():
             s.add_entry('sha512', 'anotherfile', 'anotherhash')
 
+        self.assertRaises(sources.HashtypeMixingError, raises)
+
     def test_write_new_file(self):
         s = sources.SourcesFile(self.sourcesfile, 'bsd')
         self.assertEqual(len(s.entries), 0)
-- 
2.1.0



More information about the buildsys mailing list