Skip to content

Commit

Permalink
Attempt to make tests compatible with Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzyman committed Jun 11, 2010
1 parent 03b9206 commit bc702d1
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ def test_loadTestsFromName__empty_name(self):

try:
loader.loadTestsFromName('')
except ValueError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not ValueError:
self.fail("TestLoader.loadTestsFromName failed to raise ValueError")
self.assertEqual(str(e), "Empty module name")
else:
self.fail("TestLoader.loadTestsFromName failed to raise ValueError")
Expand Down Expand Up @@ -240,7 +243,10 @@ def test_loadTestsFromName__unknown_module_name(self):

try:
loader.loadTestsFromName('sdasfasfasdf')
except ImportError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not ImportError:
self.fail("TestLoader.loadTestsFromName failed to raise ImportError")
self.assertEqual(str(e), "No module named sdasfasfasdf")
else:
self.fail("TestLoader.loadTestsFromName failed to raise ImportError")
Expand All @@ -256,7 +262,10 @@ def test_loadTestsFromName__unknown_attr_name(self):

try:
loader.loadTestsFromName('unittest2.sdasfasfasdf')
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
else:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
Expand All @@ -273,7 +282,10 @@ def test_loadTestsFromName__relative_unknown_name(self):

try:
loader.loadTestsFromName('sdasfasfasdf', unittest2)
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
else:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
Expand Down Expand Up @@ -427,7 +439,10 @@ def test(self):
loader = DiscoveringTestLoader()
try:
loader.loadTestsFromName('testcase_1.testfoo', m)
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
else:
self.fail("Failed to raise AttributeError")
Expand Down Expand Up @@ -585,7 +600,10 @@ def test_loadTestsFromNames__empty_name(self):

try:
loader.loadTestsFromNames([''])
except ValueError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not ValueError:
self.fail("TestLoader.loadTestsFromName failed to raise ValueError")
self.assertEqual(str(e), "Empty module name")
else:
self.fail("TestLoader.loadTestsFromNames failed to raise ValueError")
Expand Down Expand Up @@ -620,7 +638,10 @@ def test_loadTestsFromNames__unknown_module_name(self):

try:
loader.loadTestsFromNames(['sdasfasfasdf'])
except ImportError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not ImportError:
self.fail("TestLoader.loadTestsFromName failed to raise ImportError")
self.assertEqual(str(e), "No module named sdasfasfasdf")
else:
self.fail("TestLoader.loadTestsFromNames failed to raise ImportError")
Expand All @@ -636,7 +657,10 @@ def test_loadTestsFromNames__unknown_attr_name(self):

try:
loader.loadTestsFromNames(['unittest2.sdasfasfasdf', 'unittest2'])
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
else:
self.fail("TestLoader.loadTestsFromNames failed to raise AttributeError")
Expand All @@ -655,7 +679,10 @@ def test_loadTestsFromNames__unknown_name_relative_1(self):

try:
loader.loadTestsFromNames(['sdasfasfasdf'], unittest2)
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
else:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
Expand All @@ -674,7 +701,10 @@ def test_loadTestsFromNames__unknown_name_relative_2(self):

try:
loader.loadTestsFromNames(['TestCase', 'sdasfasfasdf'], unittest2)
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "'module' object has no attribute 'sdasfasfasdf'")
else:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
Expand Down Expand Up @@ -823,7 +853,10 @@ def test(self):
loader = DiscoveringTestLoader()
try:
loader.loadTestsFromNames(['testcase_1.testfoo'], m)
except AttributeError, e:
except:
ExceptionClass, e = sys.exc_info()[:2]
if ExceptionClass is not AttributeError:
self.fail("TestLoader.loadTestsFromName failed to raise AttributeError")
self.assertEqual(str(e), "type object 'MyTestCase' has no attribute 'testfoo'")
else:
self.fail("Failed to raise AttributeError")
Expand Down

0 comments on commit bc702d1

Please sign in to comment.