Commit 7e01c5be authored by Alex Willmer's avatar Alex Willmer Committed by David Wilson

Import and use unittest2 without aliasing it

parent e8e023ce
import logging import logging
import time import time
import unittest2 as unittest import unittest2
import mitogen.core import mitogen.core
import mitogen.master import mitogen.master
...@@ -89,4 +89,4 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase): ...@@ -89,4 +89,4 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import unittest2 as unittest import unittest2
import mitogen.core import mitogen.core
import testlib import testlib
...@@ -17,4 +17,4 @@ class ConstructorTest(testlib.RouterMixin, testlib.TestCase): ...@@ -17,4 +17,4 @@ class ConstructorTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
import os import os
import shutil import shutil
import unittest2 as unittest import unittest2
import mitogen.fakessh import mitogen.fakessh
import testlib import testlib
class RsyncTest(testlib.DockerMixin, unittest.TestCase): class RsyncTest(testlib.DockerMixin, unittest2.TestCase):
def test_rsync_from_master(self): def test_rsync_from_master(self):
context = self.docker_ssh_any() context = self.docker_ssh_any()
...@@ -60,4 +60,4 @@ class RsyncTest(testlib.DockerMixin, unittest.TestCase): ...@@ -60,4 +60,4 @@ class RsyncTest(testlib.DockerMixin, unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import subprocess import subprocess
import unittest2 as unittest import unittest2
import mitogen.master import mitogen.master
import testlib import testlib
...@@ -40,4 +40,4 @@ class CommandLineTest(testlib.RouterMixin, testlib.TestCase): ...@@ -40,4 +40,4 @@ class CommandLineTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import unittest2 as unittest import unittest2
import testlib import testlib
import id_allocation import id_allocation
...@@ -13,4 +13,4 @@ class SlaveTest(testlib.RouterMixin, testlib.TestCase): ...@@ -13,4 +13,4 @@ class SlaveTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
...@@ -6,7 +6,7 @@ import zlib ...@@ -6,7 +6,7 @@ import zlib
import mock import mock
import pytest import pytest
import unittest2 as unittest import unittest2
import mitogen.core import mitogen.core
import testlib import testlib
...@@ -128,4 +128,4 @@ class EmailParseAddrSysTest(testlib.RouterMixin, testlib.TestCase): ...@@ -128,4 +128,4 @@ class EmailParseAddrSysTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import os import os
import unittest2 as unittest import unittest2
import mitogen import mitogen
import mitogen.ssh import mitogen.ssh
...@@ -11,7 +11,7 @@ import testlib ...@@ -11,7 +11,7 @@ import testlib
import plain_old_module import plain_old_module
class LocalTest(testlib.RouterMixin, unittest.TestCase): class LocalTest(testlib.RouterMixin, unittest2.TestCase):
stream_class = mitogen.ssh.Stream stream_class = mitogen.ssh.Stream
def test_stream_name(self): def test_stream_name(self):
...@@ -21,4 +21,4 @@ class LocalTest(testlib.RouterMixin, unittest.TestCase): ...@@ -21,4 +21,4 @@ class LocalTest(testlib.RouterMixin, unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
import subprocess import subprocess
import time import time
import unittest2 as unittest import unittest2
import testlib import testlib
import mitogen.master import mitogen.master
class ScanCodeImportsTest(unittest.TestCase): class ScanCodeImportsTest(unittest2.TestCase):
func = staticmethod(mitogen.master.scan_code_imports) func = staticmethod(mitogen.master.scan_code_imports)
def test_simple(self): def test_simple(self):
...@@ -22,7 +22,7 @@ class ScanCodeImportsTest(unittest.TestCase): ...@@ -22,7 +22,7 @@ class ScanCodeImportsTest(unittest.TestCase):
]) ])
class IterReadTest(unittest.TestCase): class IterReadTest(unittest2.TestCase):
func = staticmethod(mitogen.master.iter_read) func = staticmethod(mitogen.master.iter_read)
def make_proc(self): def make_proc(self):
...@@ -74,7 +74,7 @@ class IterReadTest(unittest.TestCase): ...@@ -74,7 +74,7 @@ class IterReadTest(unittest.TestCase):
proc.terminate() proc.terminate()
class WriteAllTest(unittest.TestCase): class WriteAllTest(unittest2.TestCase):
func = staticmethod(mitogen.master.write_all) func = staticmethod(mitogen.master.write_all)
def make_proc(self): def make_proc(self):
...@@ -115,4 +115,4 @@ class WriteAllTest(unittest.TestCase): ...@@ -115,4 +115,4 @@ class WriteAllTest(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import inspect import inspect
import unittest2 as unittest import unittest2
import mitogen.master import mitogen.master
...@@ -146,4 +146,4 @@ class FindRelatedImportsTest(testlib.TestCase): ...@@ -146,4 +146,4 @@ class FindRelatedImportsTest(testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import os import os
import unittest2 as unittest import unittest2
import testlib import testlib
...@@ -17,4 +17,4 @@ class NestedTest(testlib.RouterMixin, testlib.TestCase): ...@@ -17,4 +17,4 @@ class NestedTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
...@@ -3,7 +3,7 @@ import mock ...@@ -3,7 +3,7 @@ import mock
import subprocess import subprocess
import sys import sys
import unittest2 as unittest import unittest2
import mitogen.master import mitogen.master
import testlib import testlib
...@@ -12,7 +12,7 @@ import plain_old_module ...@@ -12,7 +12,7 @@ import plain_old_module
import simple_pkg.a import simple_pkg.a
class GoodModulesTest(testlib.RouterMixin, unittest.TestCase): class GoodModulesTest(testlib.RouterMixin, unittest2.TestCase):
def test_plain_old_module(self): def test_plain_old_module(self):
# The simplest case: a top-level module with no interesting imports or # The simplest case: a top-level module with no interesting imports or
# package machinery damage. # package machinery damage.
...@@ -34,7 +34,7 @@ class GoodModulesTest(testlib.RouterMixin, unittest.TestCase): ...@@ -34,7 +34,7 @@ class GoodModulesTest(testlib.RouterMixin, unittest.TestCase):
self.assertEquals(output, "['__main__', 50]\n") self.assertEquals(output, "['__main__', 50]\n")
class BrokenModulesTest(unittest.TestCase): class BrokenModulesTest(unittest2.TestCase):
def test_obviously_missing(self): def test_obviously_missing(self):
# Ensure we don't crash in the case of a module legitimately being # Ensure we don't crash in the case of a module legitimately being
# unavailable. Should never happen in the real world. # unavailable. Should never happen in the real world.
...@@ -79,4 +79,4 @@ class BrokenModulesTest(unittest.TestCase): ...@@ -79,4 +79,4 @@ class BrokenModulesTest(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
import unittest2 as unittest import unittest2
import mitogen.master import mitogen.master
...@@ -262,4 +262,4 @@ class GetTest(testlib.RouterMixin, testlib.TestCase): ...@@ -262,4 +262,4 @@ class GetTest(testlib.RouterMixin, testlib.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
...@@ -2,13 +2,13 @@ import mitogen ...@@ -2,13 +2,13 @@ import mitogen
import mitogen.ssh import mitogen.ssh
import mitogen.utils import mitogen.utils
import unittest2 as unittest import unittest2
import testlib import testlib
import plain_old_module import plain_old_module
class FakeSshTest(testlib.RouterMixin, unittest.TestCase): class FakeSshTest(testlib.RouterMixin, unittest2.TestCase):
def test_okay(self): def test_okay(self):
context = self.router.ssh( context = self.router.ssh(
hostname='hostname', hostname='hostname',
...@@ -20,7 +20,7 @@ class FakeSshTest(testlib.RouterMixin, unittest.TestCase): ...@@ -20,7 +20,7 @@ class FakeSshTest(testlib.RouterMixin, unittest.TestCase):
self.assertEquals(3, context.call(plain_old_module.add, 1, 2)) self.assertEquals(3, context.call(plain_old_module.add, 1, 2))
class SshTest(testlib.DockerMixin, unittest.TestCase): class SshTest(testlib.DockerMixin, unittest2.TestCase):
stream_class = mitogen.ssh.Stream stream_class = mitogen.ssh.Stream
def test_stream_name(self): def test_stream_name(self):
...@@ -101,4 +101,4 @@ class SshTest(testlib.DockerMixin, unittest.TestCase): ...@@ -101,4 +101,4 @@ class SshTest(testlib.DockerMixin, unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
...@@ -7,7 +7,7 @@ import sys ...@@ -7,7 +7,7 @@ import sys
import time import time
import urlparse import urlparse
import unittest2 as unittest import unittest2
import mitogen.master import mitogen.master
if mitogen.is_master: # TODO: shouldn't be necessary. if mitogen.is_master: # TODO: shouldn't be necessary.
...@@ -114,7 +114,7 @@ def wait_for_port( ...@@ -114,7 +114,7 @@ def wait_for_port(
% (host, port)) % (host, port))
class TestCase(unittest.TestCase): class TestCase(unittest2.TestCase):
def assertRaises(self, exc, func, *args, **kwargs): def assertRaises(self, exc, func, *args, **kwargs):
"""Like regular assertRaises, except return the exception that was """Like regular assertRaises, except return the exception that was
raised. Can't use context manager because tests must run on Python2.4""" raised. Can't use context manager because tests must run on Python2.4"""
......
#!/usr/bin/env python #!/usr/bin/env python
import unittest2 as unittest import unittest2
import mitogen.master import mitogen.master
import mitogen.utils import mitogen.utils
...@@ -15,7 +15,7 @@ def func(router): ...@@ -15,7 +15,7 @@ def func(router):
return router return router
class RunWithRouterTest(unittest.TestCase): class RunWithRouterTest(unittest2.TestCase):
# test_shutdown_on_exception # test_shutdown_on_exception
# test_shutdown_on_success # test_shutdown_on_success
...@@ -25,7 +25,7 @@ class RunWithRouterTest(unittest.TestCase): ...@@ -25,7 +25,7 @@ class RunWithRouterTest(unittest.TestCase):
self.assertFalse(router.broker._thread.isAlive()) self.assertFalse(router.broker._thread.isAlive())
class WithRouterTest(unittest.TestCase): class WithRouterTest(unittest2.TestCase):
def test_with_broker(self): def test_with_broker(self):
router = func() router = func()
self.assertIsInstance(router, mitogen.master.Router) self.assertIsInstance(router, mitogen.master.Router)
...@@ -33,4 +33,4 @@ class WithRouterTest(unittest.TestCase): ...@@ -33,4 +33,4 @@ class WithRouterTest(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest2.main()
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