Skip to content
Prev Previous commit
Next Next commit
Refactor assertRaises
test_exceptions: Add exc_info test & fix Exception nameclash
  • Loading branch information
vmuriart committed Jan 31, 2017
commit 2ef30414c88bec9361d16d44223a11c122517a4f
324 changes: 81 additions & 243 deletions src/tests/test_array.py

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions src/tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@ def test_class_default_repr(self):

def test_non_public_class(self):
"""Test that non-public classes are inaccessible."""

def test():
with self.assertRaises(ImportError):
from Python.Test import InternalClass

self.assertRaises(ImportError, test)

def test():
with self.assertRaises(AttributeError):
x = Test.InternalClass

self.assertRaises(AttributeError, test)

def test_basic_subclass(self):
"""Test basic subclass of a managed class."""
from System.Collections import Hashtable
Expand Down Expand Up @@ -256,13 +251,17 @@ def test_comparisons(self):
self.assertEqual(d2 >= d1, True)
self.assertEqual(d2 > d1, True)

self.assertRaises(TypeError, lambda: d1 < None)
self.assertRaises(TypeError, lambda: d1 < System.Guid())
with self.assertRaises(TypeError):
d1 < None

with self.assertRaises(TypeError):
d1 < System.Guid()

# ClassTest does not implement IComparable
c1 = ClassTest()
c2 = ClassTest()
self.assertRaises(TypeError, lambda: c1 < c2)
with self.assertRaises(TypeError):
c1 < c2

def test_self_callback(self):
"""Test calling back and forth between this and a c# baseclass."""
Expand Down
31 changes: 9 additions & 22 deletions src/tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,13 @@ def test_implicit_load_already_valid_namespace(self):
self.assertTrue(isCLRClass(CLR.System.UriBuilder))

def test_import_non_existant_module(self):
"""Test import failure for a non-existant module."""

def test():
"""Test import failure for a non-existent module."""
with self.assertRaises(ImportError):
import System.SpamSpamSpam

def testclr():
with self.assertRaises(ImportError):
import CLR.System.SpamSpamSpam

self.assertRaises(ImportError, test)
self.assertRaises(ImportError, testclr)

def test_lookup_no_namespace_type(self):
"""Test lookup of types without a qualified namespace."""
import CLR.Python.Test
Expand All @@ -201,18 +197,13 @@ def test_lookup_no_namespace_type(self):

def test_module_lookup_recursion(self):
"""Test for recursive lookup handling."""

def test1():
with self.assertRaises(ImportError):
from CLR import CLR

self.assertRaises(ImportError, test1)

def test2():
with self.assertRaises(AttributeError):
import CLR
x = CLR.CLR

self.assertRaises(AttributeError, test2)

def test_module_get_attr(self):
"""Test module getattr behavior."""
import CLR.System as System
Expand All @@ -223,20 +214,16 @@ def test_module_get_attr(self):
module = System.Xml
self.assertTrue(isCLRModule(module))

def test():
with self.assertRaises(AttributeError):
spam = System.Spam

self.assertRaises(AttributeError, test)

def test():
with self.assertRaises(TypeError):
spam = getattr(System, 1)

self.assertRaises(TypeError, test)

def test000_multiple_imports(self):
def test_multiple_imports(self):
# import CLR did raise a Seg Fault once
# test if the Exceptions.warn() method still causes it
for n in range(100):
for _ in range(100):
import CLR


Expand Down
Loading