A fix for running unittest tests on platforms without the audioop module (e.g. jython and IronPython)

This commit is contained in:
Michael Foord 2010-03-27 12:55:19 +00:00
parent 9588d998d5
commit ff889396a8
2 changed files with 7 additions and 14 deletions

View file

@ -0,0 +1 @@
# Empty module for testing the loading of modules

View file

@ -524,12 +524,8 @@ class Test_TestLoader(unittest.TestCase):
# We're going to try to load this module as a side-effect, so it # We're going to try to load this module as a side-effect, so it
# better not be loaded before we try. # better not be loaded before we try.
# #
# Why pick audioop? Google shows it isn't used very often, so there's module_name = 'unittest.test.dummy'
# a good chance that it won't be imported when this test is run sys.modules.pop(module_name, None)
module_name = 'audioop'
if module_name in sys.modules:
del sys.modules[module_name]
loader = unittest.TestLoader() loader = unittest.TestLoader()
try: try:
@ -538,7 +534,7 @@ class Test_TestLoader(unittest.TestCase):
self.assertIsInstance(suite, loader.suiteClass) self.assertIsInstance(suite, loader.suiteClass)
self.assertEqual(list(suite), []) self.assertEqual(list(suite), [])
# audioop should now be loaded, thanks to loadTestsFromName() # module should now be loaded, thanks to loadTestsFromName()
self.assertIn(module_name, sys.modules) self.assertIn(module_name, sys.modules)
finally: finally:
if module_name in sys.modules: if module_name in sys.modules:
@ -911,12 +907,8 @@ class Test_TestLoader(unittest.TestCase):
# We're going to try to load this module as a side-effect, so it # We're going to try to load this module as a side-effect, so it
# better not be loaded before we try. # better not be loaded before we try.
# #
# Why pick audioop? Google shows it isn't used very often, so there's module_name = 'unittest.test.dummy'
# a good chance that it won't be imported when this test is run sys.modules.pop(module_name, None)
module_name = 'audioop'
if module_name in sys.modules:
del sys.modules[module_name]
loader = unittest.TestLoader() loader = unittest.TestLoader()
try: try:
@ -925,7 +917,7 @@ class Test_TestLoader(unittest.TestCase):
self.assertIsInstance(suite, loader.suiteClass) self.assertIsInstance(suite, loader.suiteClass)
self.assertEqual(list(suite), [unittest.TestSuite()]) self.assertEqual(list(suite), [unittest.TestSuite()])
# audioop should now be loaded, thanks to loadTestsFromName() # module should now be loaded, thanks to loadTestsFromName()
self.assertIn(module_name, sys.modules) self.assertIn(module_name, sys.modules)
finally: finally:
if module_name in sys.modules: if module_name in sys.modules: