|
6 | 6 | # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
7 | 7 | # FOR A PARTICULAR PURPOSE. |
8 | 8 | # =========================================================================== |
9 | | - |
10 | 9 | import clr |
11 | 10 | clr.AddReference('Python.Test') |
12 | 11 | clr.AddReference('System.Data') |
13 | 12 |
|
14 | 13 | # testImplicitAssemblyLoad() passes on deprecation warning; perfect! # |
15 | 14 | ##clr.AddReference('System.Windows.Forms') |
16 | | -import sys, os, string, unittest, types |
| 15 | +import sys, os, string, unittest, types, warnings |
17 | 16 |
|
18 | 17 |
|
19 | 18 | class ModuleTests(unittest.TestCase): |
@@ -42,8 +41,8 @@ def test000importClr(self): |
42 | 41 | def testPreloadVar(self): |
43 | 42 | import clr |
44 | 43 | self.assertTrue(clr.getPreload() is False, clr.getPreload()) |
45 | | - clr.setPreload(False) |
46 | | - self.assertTrue(clr.getPreload() is False, clr.getPreload()) |
| 44 | + clr.setPreload(False) |
| 45 | + self.assertTrue(clr.getPreload() is False, clr.getPreload()) |
47 | 46 | try: |
48 | 47 | clr.setPreload(True) |
49 | 48 | self.assertTrue(clr.getPreload() is True, clr.getPreload()) |
@@ -204,27 +203,25 @@ def testFromModuleImportStar(self): |
204 | 203 |
|
205 | 204 | def testImplicitAssemblyLoad(self): |
206 | 205 | """Test implicit assembly loading via import.""" |
207 | | - # this test only applies to windows |
208 | | - if sys.platform != "win32": |
209 | | - return |
210 | | - |
211 | | - def test(): |
212 | | - # This should fail until System.Windows.Forms has been |
213 | | - # imported or that assembly has been explicitly loaded. |
214 | | - # True for Windows; Not so for Mono 2.8.1 |
215 | | - import System.Windows |
216 | | - |
217 | | - # The test fails when the project is compiled with MS VS 2005. Dunno why :( |
218 | | - # Fails (as expected) on Late Binding model. Works as expected on an interactive sesson. |
219 | | - self.assertRaises(ImportError, test) |
220 | | - |
221 | | - clr.AddReference("System.Windows.Forms") |
222 | | - import System.Windows.Forms as Forms |
223 | | - self.assertTrue(self.isCLRModule(Forms)) |
224 | | - self.assertTrue(Forms.__name__ == 'System.Windows.Forms') |
225 | | - from System.Windows.Forms import Form |
226 | | - self.assertTrue(self.isCLRClass(Form)) |
227 | | - self.assertTrue(Form.__name__ == 'Form') |
| 206 | + with warnings.catch_warnings(record=True) as w: |
| 207 | + warnings.simplefilter("always") |
| 208 | + |
| 209 | + # should trigger a DeprecationWarning as Microsoft.Build hasn't |
| 210 | + # been added as a reference yet (and should exist for mono) |
| 211 | + import Microsoft.Build |
| 212 | + |
| 213 | + self.assertEqual(len(w), 1) |
| 214 | + self.assertTrue(isinstance(w[0].message, DeprecationWarning)) |
| 215 | + |
| 216 | + with warnings.catch_warnings(record=True) as w: |
| 217 | + clr.AddReference("System.Windows.Forms") |
| 218 | + import System.Windows.Forms as Forms |
| 219 | + self.assertTrue(self.isCLRModule(Forms)) |
| 220 | + self.assertTrue(Forms.__name__ == 'System.Windows.Forms') |
| 221 | + from System.Windows.Forms import Form |
| 222 | + self.assertTrue(self.isCLRClass(Form)) |
| 223 | + self.assertTrue(Form.__name__ == 'Form') |
| 224 | + self.assertEqual(len(w), 0) |
228 | 225 |
|
229 | 226 |
|
230 | 227 | def testExplicitAssemblyLoad(self): |
|
0 commit comments