Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 1 | from contextlib import contextmanager |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 2 | import linecache |
Raymond Hettinger | dc9dcf1 | 2003-07-13 06:15:11 +0000 | [diff] [blame] | 3 | import os |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 4 | from io import StringIO |
Guido van Rossum | 61e21b5 | 2007-08-20 19:06:03 +0000 | [diff] [blame] | 5 | import sys |
Raymond Hettinger | d6f6e50 | 2003-07-13 08:37:40 +0000 | [diff] [blame] | 6 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | from test import support |
Jeremy Hylton | 8501466 | 2003-07-11 15:37:59 +0000 | [diff] [blame] | 8 | |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 9 | from test import warning_tests |
Jeremy Hylton | 8501466 | 2003-07-11 15:37:59 +0000 | [diff] [blame] | 10 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 11 | import warnings as original_warnings |
Jeremy Hylton | 8501466 | 2003-07-11 15:37:59 +0000 | [diff] [blame] | 12 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 13 | sys.modules['_warnings'] = 0 |
| 14 | del sys.modules['warnings'] |
| 15 | |
| 16 | import warnings as py_warnings |
| 17 | |
| 18 | del sys.modules['_warnings'] |
| 19 | del sys.modules['warnings'] |
| 20 | |
| 21 | import warnings as c_warnings |
| 22 | |
| 23 | sys.modules['warnings'] = original_warnings |
| 24 | |
| 25 | |
| 26 | @contextmanager |
| 27 | def warnings_state(module): |
| 28 | """Use a specific warnings implementation in warning_tests.""" |
| 29 | global __warningregistry__ |
| 30 | for to_clear in (sys, warning_tests): |
| 31 | try: |
| 32 | to_clear.__warningregistry__.clear() |
| 33 | except AttributeError: |
| 34 | pass |
| 35 | try: |
| 36 | __warningregistry__.clear() |
| 37 | except NameError: |
| 38 | pass |
| 39 | original_warnings = warning_tests.warnings |
| 40 | try: |
| 41 | warning_tests.warnings = module |
| 42 | yield |
| 43 | finally: |
| 44 | warning_tests.warnings = original_warnings |
| 45 | |
| 46 | |
| 47 | class BaseTest(unittest.TestCase): |
| 48 | |
| 49 | """Basic bookkeeping required for testing.""" |
| 50 | |
| 51 | def setUp(self): |
| 52 | # The __warningregistry__ needs to be in a pristine state for tests |
| 53 | # to work properly. |
| 54 | if '__warningregistry__' in globals(): |
| 55 | del globals()['__warningregistry__'] |
| 56 | if hasattr(warning_tests, '__warningregistry__'): |
| 57 | del warning_tests.__warningregistry__ |
| 58 | if hasattr(sys, '__warningregistry__'): |
| 59 | del sys.__warningregistry__ |
| 60 | # The 'warnings' module must be explicitly set so that the proper |
| 61 | # interaction between _warnings and 'warnings' can be controlled. |
| 62 | sys.modules['warnings'] = self.module |
| 63 | super(BaseTest, self).setUp() |
| 64 | |
| 65 | def tearDown(self): |
| 66 | sys.modules['warnings'] = original_warnings |
| 67 | super(BaseTest, self).tearDown() |
| 68 | |
| 69 | |
| 70 | class FilterTests(object): |
| 71 | |
| 72 | """Testing the filtering functionality.""" |
| 73 | |
| 74 | def test_error(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 75 | with original_warnings.catch_warnings(module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 76 | self.module.resetwarnings() |
| 77 | self.module.filterwarnings("error", category=UserWarning) |
| 78 | self.assertRaises(UserWarning, self.module.warn, |
| 79 | "FilterTests.test_error") |
| 80 | |
| 81 | def test_ignore(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 82 | with original_warnings.catch_warnings(record=True, |
| 83 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 84 | self.module.resetwarnings() |
| 85 | self.module.filterwarnings("ignore", category=UserWarning) |
| 86 | self.module.warn("FilterTests.test_ignore", UserWarning) |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 87 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 88 | |
| 89 | def test_always(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 90 | with original_warnings.catch_warnings(record=True, |
| 91 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 92 | self.module.resetwarnings() |
| 93 | self.module.filterwarnings("always", category=UserWarning) |
| 94 | message = "FilterTests.test_always" |
| 95 | self.module.warn(message, UserWarning) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 96 | self.assert_(message, w[-1].message) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 97 | self.module.warn(message, UserWarning) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 98 | self.assert_(w[-1].message, message) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 99 | |
| 100 | def test_default(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 101 | with original_warnings.catch_warnings(record=True, |
| 102 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 103 | self.module.resetwarnings() |
| 104 | self.module.filterwarnings("default", category=UserWarning) |
| 105 | message = UserWarning("FilterTests.test_default") |
| 106 | for x in range(2): |
| 107 | self.module.warn(message, UserWarning) |
| 108 | if x == 0: |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 109 | self.assertEquals(w[-1].message, message) |
| 110 | del w[:] |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 111 | elif x == 1: |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 112 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 113 | else: |
| 114 | raise ValueError("loop variant unhandled") |
| 115 | |
| 116 | def test_module(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 117 | with original_warnings.catch_warnings(record=True, |
| 118 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 119 | self.module.resetwarnings() |
| 120 | self.module.filterwarnings("module", category=UserWarning) |
| 121 | message = UserWarning("FilterTests.test_module") |
| 122 | self.module.warn(message, UserWarning) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 123 | self.assertEquals(w[-1].message, message) |
| 124 | del w[:] |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 125 | self.module.warn(message, UserWarning) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 126 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 127 | |
| 128 | def test_once(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 129 | with original_warnings.catch_warnings(record=True, |
| 130 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 131 | self.module.resetwarnings() |
| 132 | self.module.filterwarnings("once", category=UserWarning) |
| 133 | message = UserWarning("FilterTests.test_once") |
| 134 | self.module.warn_explicit(message, UserWarning, "test_warnings.py", |
| 135 | 42) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 136 | self.assertEquals(w[-1].message, message) |
| 137 | del w[:] |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 138 | self.module.warn_explicit(message, UserWarning, "test_warnings.py", |
| 139 | 13) |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 140 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 141 | self.module.warn_explicit(message, UserWarning, "test_warnings2.py", |
| 142 | 42) |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 143 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 144 | |
| 145 | def test_inheritance(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 146 | with original_warnings.catch_warnings(module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 147 | self.module.resetwarnings() |
| 148 | self.module.filterwarnings("error", category=Warning) |
| 149 | self.assertRaises(UserWarning, self.module.warn, |
| 150 | "FilterTests.test_inheritance", UserWarning) |
| 151 | |
| 152 | def test_ordering(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 153 | with original_warnings.catch_warnings(record=True, |
| 154 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 155 | self.module.resetwarnings() |
| 156 | self.module.filterwarnings("ignore", category=UserWarning) |
| 157 | self.module.filterwarnings("error", category=UserWarning, |
| 158 | append=True) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 159 | del w[:] |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 160 | try: |
| 161 | self.module.warn("FilterTests.test_ordering", UserWarning) |
| 162 | except UserWarning: |
| 163 | self.fail("order handling for actions failed") |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 164 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 165 | |
| 166 | def test_filterwarnings(self): |
| 167 | # Test filterwarnings(). |
| 168 | # Implicitly also tests resetwarnings(). |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 169 | with original_warnings.catch_warnings(record=True, |
| 170 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 171 | self.module.filterwarnings("error", "", Warning, "", 0) |
| 172 | self.assertRaises(UserWarning, self.module.warn, 'convert to error') |
| 173 | |
| 174 | self.module.resetwarnings() |
| 175 | text = 'handle normally' |
| 176 | self.module.warn(text) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 177 | self.assertEqual(str(w[-1].message), text) |
| 178 | self.assert_(w[-1].category is UserWarning) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 179 | |
| 180 | self.module.filterwarnings("ignore", "", Warning, "", 0) |
| 181 | text = 'filtered out' |
| 182 | self.module.warn(text) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 183 | self.assertNotEqual(str(w[-1].message), text) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 184 | |
| 185 | self.module.resetwarnings() |
| 186 | self.module.filterwarnings("error", "hex*", Warning, "", 0) |
| 187 | self.assertRaises(UserWarning, self.module.warn, 'hex/oct') |
| 188 | text = 'nonmatching text' |
| 189 | self.module.warn(text) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 190 | self.assertEqual(str(w[-1].message), text) |
| 191 | self.assert_(w[-1].category is UserWarning) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 192 | |
| 193 | class CFilterTests(BaseTest, FilterTests): |
| 194 | module = c_warnings |
| 195 | |
| 196 | class PyFilterTests(BaseTest, FilterTests): |
| 197 | module = py_warnings |
| 198 | |
| 199 | |
| 200 | class WarnTests(unittest.TestCase): |
| 201 | |
| 202 | """Test warnings.warn() and warnings.warn_explicit().""" |
| 203 | |
| 204 | def test_message(self): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 205 | with original_warnings.catch_warnings(record=True, |
| 206 | module=self.module) as w: |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 207 | for i in range(4): |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 208 | text = 'multi %d' %i # Different text on each call. |
| 209 | self.module.warn(text) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 210 | self.assertEqual(str(w[-1].message), text) |
| 211 | self.assert_(w[-1].category is UserWarning) |
Raymond Hettinger | d6f6e50 | 2003-07-13 08:37:40 +0000 | [diff] [blame] | 212 | |
Brett Cannon | 54bd41d | 2008-09-02 04:01:42 +0000 | [diff] [blame] | 213 | # Issue 3639 |
| 214 | def test_warn_nonstandard_types(self): |
| 215 | # warn() should handle non-standard types without issue. |
| 216 | for ob in (Warning, None, 42): |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 217 | with original_warnings.catch_warnings(record=True, |
| 218 | module=self.module) as w: |
Brett Cannon | 54bd41d | 2008-09-02 04:01:42 +0000 | [diff] [blame] | 219 | self.module.warn(ob) |
| 220 | # Don't directly compare objects since |
| 221 | # ``Warning() != Warning()``. |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 222 | self.assertEquals(str(w[-1].message), str(UserWarning(ob))) |
Brett Cannon | 54bd41d | 2008-09-02 04:01:42 +0000 | [diff] [blame] | 223 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 224 | def test_filename(self): |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 225 | with warnings_state(self.module): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 226 | with original_warnings.catch_warnings(record=True, |
| 227 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 228 | warning_tests.inner("spam1") |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 229 | self.assertEqual(os.path.basename(w[-1].filename), |
| 230 | "warning_tests.py") |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 231 | warning_tests.outer("spam2") |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 232 | self.assertEqual(os.path.basename(w[-1].filename), |
| 233 | "warning_tests.py") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 234 | |
| 235 | def test_stacklevel(self): |
| 236 | # Test stacklevel argument |
| 237 | # make sure all messages are different, so the warning won't be skipped |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 238 | with warnings_state(self.module): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 239 | with original_warnings.catch_warnings(record=True, |
| 240 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 241 | warning_tests.inner("spam3", stacklevel=1) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 242 | self.assertEqual(os.path.basename(w[-1].filename), |
| 243 | "warning_tests.py") |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 244 | warning_tests.outer("spam4", stacklevel=1) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 245 | self.assertEqual(os.path.basename(w[-1].filename), |
| 246 | "warning_tests.py") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 247 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 248 | warning_tests.inner("spam5", stacklevel=2) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 249 | self.assertEqual(os.path.basename(w[-1].filename), |
| 250 | "test_warnings.py") |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 251 | warning_tests.outer("spam6", stacklevel=2) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 252 | self.assertEqual(os.path.basename(w[-1].filename), |
| 253 | "warning_tests.py") |
Christian Heimes | 5d8da20 | 2008-05-06 13:58:24 +0000 | [diff] [blame] | 254 | warning_tests.outer("spam6.5", stacklevel=3) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 255 | self.assertEqual(os.path.basename(w[-1].filename), |
| 256 | "test_warnings.py") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 257 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 258 | warning_tests.inner("spam7", stacklevel=9999) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 259 | self.assertEqual(os.path.basename(w[-1].filename), |
| 260 | "sys") |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 261 | |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 262 | def test_missing_filename_not_main(self): |
| 263 | # If __file__ is not specified and __main__ is not the module name, |
| 264 | # then __file__ should be set to the module name. |
| 265 | filename = warning_tests.__file__ |
| 266 | try: |
| 267 | del warning_tests.__file__ |
| 268 | with warnings_state(self.module): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 269 | with original_warnings.catch_warnings(record=True, |
| 270 | module=self.module) as w: |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 271 | warning_tests.inner("spam8", stacklevel=1) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 272 | self.assertEqual(w[-1].filename, warning_tests.__name__) |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 273 | finally: |
| 274 | warning_tests.__file__ = filename |
| 275 | |
| 276 | def test_missing_filename_main_with_argv(self): |
| 277 | # If __file__ is not specified and the caller is __main__ and sys.argv |
| 278 | # exists, then use sys.argv[0] as the file. |
| 279 | if not hasattr(sys, 'argv'): |
| 280 | return |
| 281 | filename = warning_tests.__file__ |
| 282 | module_name = warning_tests.__name__ |
| 283 | try: |
| 284 | del warning_tests.__file__ |
| 285 | warning_tests.__name__ = '__main__' |
| 286 | with warnings_state(self.module): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 287 | with original_warnings.catch_warnings(record=True, |
| 288 | module=self.module) as w: |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 289 | warning_tests.inner('spam9', stacklevel=1) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 290 | self.assertEqual(w[-1].filename, sys.argv[0]) |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 291 | finally: |
| 292 | warning_tests.__file__ = filename |
| 293 | warning_tests.__name__ = module_name |
| 294 | |
| 295 | def test_missing_filename_main_without_argv(self): |
| 296 | # If __file__ is not specified, the caller is __main__, and sys.argv |
| 297 | # is not set, then '__main__' is the file name. |
| 298 | filename = warning_tests.__file__ |
| 299 | module_name = warning_tests.__name__ |
| 300 | argv = sys.argv |
| 301 | try: |
| 302 | del warning_tests.__file__ |
| 303 | warning_tests.__name__ = '__main__' |
| 304 | del sys.argv |
| 305 | with warnings_state(self.module): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 306 | with original_warnings.catch_warnings(record=True, |
| 307 | module=self.module) as w: |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 308 | warning_tests.inner('spam10', stacklevel=1) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 309 | self.assertEqual(w[-1].filename, '__main__') |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 310 | finally: |
| 311 | warning_tests.__file__ = filename |
| 312 | warning_tests.__name__ = module_name |
| 313 | sys.argv = argv |
| 314 | |
Christian Heimes | daaf8ee | 2008-05-04 23:58:41 +0000 | [diff] [blame] | 315 | def test_missing_filename_main_with_argv_empty_string(self): |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 316 | # If __file__ is not specified, the caller is __main__, and sys.argv[0] |
| 317 | # is the empty string, then '__main__ is the file name. |
| 318 | # Tests issue 2743. |
| 319 | file_name = warning_tests.__file__ |
| 320 | module_name = warning_tests.__name__ |
| 321 | argv = sys.argv |
| 322 | try: |
| 323 | del warning_tests.__file__ |
| 324 | warning_tests.__name__ = '__main__' |
| 325 | sys.argv = [''] |
| 326 | with warnings_state(self.module): |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 327 | with original_warnings.catch_warnings(record=True, |
| 328 | module=self.module) as w: |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 329 | warning_tests.inner('spam11', stacklevel=1) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 330 | self.assertEqual(w[-1].filename, '__main__') |
Christian Heimes | 81ee3ef | 2008-05-04 22:42:01 +0000 | [diff] [blame] | 331 | finally: |
| 332 | warning_tests.__file__ = file_name |
| 333 | warning_tests.__name__ = module_name |
| 334 | sys.argv = argv |
| 335 | |
Brett Cannon | db73491 | 2008-06-27 00:52:15 +0000 | [diff] [blame] | 336 | def test_warn_explicit_type_errors(self): |
| 337 | # warn_explicit() shoud error out gracefully if it is given objects |
| 338 | # of the wrong types. |
| 339 | # lineno is expected to be an integer. |
| 340 | self.assertRaises(TypeError, self.module.warn_explicit, |
| 341 | None, UserWarning, None, None) |
| 342 | # Either 'message' needs to be an instance of Warning or 'category' |
| 343 | # needs to be a subclass. |
| 344 | self.assertRaises(TypeError, self.module.warn_explicit, |
| 345 | None, None, None, 1) |
| 346 | # 'registry' must be a dict or None. |
| 347 | self.assertRaises((TypeError, AttributeError), |
| 348 | self.module.warn_explicit, |
| 349 | None, Warning, None, 1, registry=42) |
| 350 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 351 | class CWarnTests(BaseTest, WarnTests): |
| 352 | module = c_warnings |
| 353 | |
| 354 | class PyWarnTests(BaseTest, WarnTests): |
| 355 | module = py_warnings |
| 356 | |
| 357 | |
| 358 | class WCmdLineTests(unittest.TestCase): |
| 359 | |
| 360 | def test_improper_input(self): |
| 361 | # Uses the private _setoption() function to test the parsing |
| 362 | # of command-line warning arguments |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 363 | with original_warnings.catch_warnings(module=self.module): |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 364 | self.assertRaises(self.module._OptionError, |
| 365 | self.module._setoption, '1:2:3:4:5:6') |
| 366 | self.assertRaises(self.module._OptionError, |
| 367 | self.module._setoption, 'bogus::Warning') |
| 368 | self.assertRaises(self.module._OptionError, |
| 369 | self.module._setoption, 'ignore:2::4:-5') |
| 370 | self.module._setoption('error::Warning::0') |
| 371 | self.assertRaises(UserWarning, self.module.warn, 'convert to error') |
| 372 | |
| 373 | class CWCmdLineTests(BaseTest, WCmdLineTests): |
| 374 | module = c_warnings |
| 375 | |
| 376 | class PyWCmdLineTests(BaseTest, WCmdLineTests): |
| 377 | module = py_warnings |
| 378 | |
| 379 | |
| 380 | class _WarningsTests(BaseTest): |
| 381 | |
| 382 | """Tests specific to the _warnings module.""" |
| 383 | |
| 384 | module = c_warnings |
| 385 | |
| 386 | def test_filter(self): |
| 387 | # Everything should function even if 'filters' is not in warnings. |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 388 | with original_warnings.catch_warnings(module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 389 | self.module.filterwarnings("error", "", Warning, "", 0) |
| 390 | self.assertRaises(UserWarning, self.module.warn, |
| 391 | 'convert to error') |
| 392 | del self.module.filters |
| 393 | self.assertRaises(UserWarning, self.module.warn, |
| 394 | 'convert to error') |
| 395 | |
| 396 | def test_onceregistry(self): |
| 397 | # Replacing or removing the onceregistry should be okay. |
| 398 | global __warningregistry__ |
| 399 | message = UserWarning('onceregistry test') |
| 400 | try: |
| 401 | original_registry = self.module.onceregistry |
| 402 | __warningregistry__ = {} |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 403 | with original_warnings.catch_warnings(record=True, |
| 404 | module=self.module) as w: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 405 | self.module.resetwarnings() |
| 406 | self.module.filterwarnings("once", category=UserWarning) |
| 407 | self.module.warn_explicit(message, UserWarning, "file", 42) |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 408 | self.failUnlessEqual(w[-1].message, message) |
| 409 | del w[:] |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 410 | self.module.warn_explicit(message, UserWarning, "file", 42) |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 411 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 412 | # Test the resetting of onceregistry. |
| 413 | self.module.onceregistry = {} |
| 414 | __warningregistry__ = {} |
| 415 | self.module.warn('onceregistry test') |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 416 | self.failUnlessEqual(w[-1].message.args, message.args) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 417 | # Removal of onceregistry is okay. |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 418 | del w[:] |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 419 | del self.module.onceregistry |
| 420 | __warningregistry__ = {} |
| 421 | self.module.warn_explicit(message, UserWarning, "file", 42) |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 422 | self.assertEquals(len(w), 0) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 423 | finally: |
| 424 | self.module.onceregistry = original_registry |
| 425 | |
| 426 | def test_showwarning_missing(self): |
| 427 | # Test that showwarning() missing is okay. |
| 428 | text = 'del showwarning test' |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 429 | with original_warnings.catch_warnings(module=self.module): |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 430 | self.module.filterwarnings("always", category=UserWarning) |
| 431 | del self.module.showwarning |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 432 | with support.captured_output('stderr') as stream: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 433 | self.module.warn(text) |
| 434 | result = stream.getvalue() |
| 435 | self.failUnless(text in result) |
| 436 | |
Christian Heimes | 8dc226f | 2008-05-06 23:45:46 +0000 | [diff] [blame] | 437 | def test_showwarning_not_callable(self): |
| 438 | self.module.filterwarnings("always", category=UserWarning) |
| 439 | old_showwarning = self.module.showwarning |
| 440 | self.module.showwarning = 23 |
| 441 | try: |
| 442 | self.assertRaises(TypeError, self.module.warn, "Warning!") |
| 443 | finally: |
| 444 | self.module.showwarning = old_showwarning |
Alexandre Vassalotti | e9f305f | 2008-05-16 04:39:54 +0000 | [diff] [blame] | 445 | self.module.resetwarnings() |
Christian Heimes | 8dc226f | 2008-05-06 23:45:46 +0000 | [diff] [blame] | 446 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 447 | def test_show_warning_output(self): |
| 448 | # With showarning() missing, make sure that output is okay. |
| 449 | text = 'test show_warning' |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 450 | with original_warnings.catch_warnings(module=self.module): |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 451 | self.module.filterwarnings("always", category=UserWarning) |
| 452 | del self.module.showwarning |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 453 | with support.captured_output('stderr') as stream: |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 454 | warning_tests.inner(text) |
| 455 | result = stream.getvalue() |
| 456 | self.failUnlessEqual(result.count('\n'), 2, |
| 457 | "Too many newlines in %r" % result) |
| 458 | first_line, second_line = result.split('\n', 1) |
| 459 | expected_file = os.path.splitext(warning_tests.__file__)[0] + '.py' |
Neal Norwitz | 32dde22 | 2008-04-15 06:43:13 +0000 | [diff] [blame] | 460 | first_line_parts = first_line.rsplit(':', 3) |
| 461 | path, line, warning_class, message = first_line_parts |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 462 | line = int(line) |
| 463 | self.failUnlessEqual(expected_file, path) |
| 464 | self.failUnlessEqual(warning_class, ' ' + UserWarning.__name__) |
| 465 | self.failUnlessEqual(message, ' ' + text) |
| 466 | expected_line = ' ' + linecache.getline(path, line).strip() + '\n' |
| 467 | assert expected_line |
| 468 | self.failUnlessEqual(second_line, expected_line) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 469 | |
| 470 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 471 | class WarningsDisplayTests(unittest.TestCase): |
| 472 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 473 | """Test the displaying of warnings and the ability to overload functions |
| 474 | related to displaying warnings.""" |
| 475 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 476 | def test_formatwarning(self): |
| 477 | message = "msg" |
| 478 | category = Warning |
| 479 | file_name = os.path.splitext(warning_tests.__file__)[0] + '.py' |
| 480 | line_num = 3 |
| 481 | file_line = linecache.getline(file_name, line_num).strip() |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 482 | format = "%s:%s: %s: %s\n %s\n" |
| 483 | expect = format % (file_name, line_num, category.__name__, message, |
| 484 | file_line) |
| 485 | self.failUnlessEqual(expect, self.module.formatwarning(message, |
| 486 | category, file_name, line_num)) |
| 487 | # Test the 'line' argument. |
| 488 | file_line += " for the win!" |
| 489 | expect = format % (file_name, line_num, category.__name__, message, |
| 490 | file_line) |
| 491 | self.failUnlessEqual(expect, self.module.formatwarning(message, |
| 492 | category, file_name, line_num, file_line)) |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 493 | |
| 494 | def test_showwarning(self): |
| 495 | file_name = os.path.splitext(warning_tests.__file__)[0] + '.py' |
| 496 | line_num = 3 |
| 497 | expected_file_line = linecache.getline(file_name, line_num).strip() |
| 498 | message = 'msg' |
| 499 | category = Warning |
| 500 | file_object = StringIO() |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 501 | expect = self.module.formatwarning(message, category, file_name, |
| 502 | line_num) |
| 503 | self.module.showwarning(message, category, file_name, line_num, |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 504 | file_object) |
| 505 | self.failUnlessEqual(file_object.getvalue(), expect) |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 506 | # Test 'line' argument. |
| 507 | expected_file_line += "for the win!" |
| 508 | expect = self.module.formatwarning(message, category, file_name, |
| 509 | line_num, expected_file_line) |
| 510 | file_object = StringIO() |
| 511 | self.module.showwarning(message, category, file_name, line_num, |
| 512 | file_object, expected_file_line) |
| 513 | self.failUnlessEqual(expect, file_object.getvalue()) |
| 514 | |
| 515 | class CWarningsDisplayTests(BaseTest, WarningsDisplayTests): |
| 516 | module = c_warnings |
| 517 | |
| 518 | class PyWarningsDisplayTests(BaseTest, WarningsDisplayTests): |
| 519 | module = py_warnings |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 520 | |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 521 | |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 522 | class CatchWarningTests(BaseTest): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 523 | |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 524 | """Test catch_warnings().""" |
| 525 | |
| 526 | def test_catch_warnings_restore(self): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 527 | wmod = self.module |
| 528 | orig_filters = wmod.filters |
| 529 | orig_showwarning = wmod.showwarning |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 530 | # Ensure both showwarning and filters are restored when recording |
| 531 | with wmod.catch_warnings(module=wmod, record=True): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 532 | wmod.filters = wmod.showwarning = object() |
| 533 | self.assert_(wmod.filters is orig_filters) |
| 534 | self.assert_(wmod.showwarning is orig_showwarning) |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 535 | # Same test, but with recording disabled |
| 536 | with wmod.catch_warnings(module=wmod, record=False): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 537 | wmod.filters = wmod.showwarning = object() |
| 538 | self.assert_(wmod.filters is orig_filters) |
| 539 | self.assert_(wmod.showwarning is orig_showwarning) |
| 540 | |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 541 | def test_catch_warnings_recording(self): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 542 | wmod = self.module |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 543 | # Ensure warnings are recorded when requested |
| 544 | with wmod.catch_warnings(module=wmod, record=True) as w: |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 545 | self.assertEqual(w, []) |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 546 | self.assert_(type(w) is list) |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 547 | wmod.simplefilter("always") |
| 548 | wmod.warn("foo") |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 549 | self.assertEqual(str(w[-1].message), "foo") |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 550 | wmod.warn("bar") |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 551 | self.assertEqual(str(w[-1].message), "bar") |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 552 | self.assertEqual(str(w[0].message), "foo") |
| 553 | self.assertEqual(str(w[1].message), "bar") |
Brett Cannon | 1cd0247 | 2008-09-09 01:52:27 +0000 | [diff] [blame] | 554 | del w[:] |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 555 | self.assertEqual(w, []) |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 556 | # Ensure warnings are not recorded when not requested |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 557 | orig_showwarning = wmod.showwarning |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 558 | with wmod.catch_warnings(module=wmod, record=False) as w: |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 559 | self.assert_(w is None) |
| 560 | self.assert_(wmod.showwarning is orig_showwarning) |
| 561 | |
Benjamin Peterson | fcf5d63 | 2008-10-16 23:24:44 +0000 | [diff] [blame] | 562 | def test_catch_warnings_reentry_guard(self): |
| 563 | wmod = self.module |
| 564 | # Ensure catch_warnings is protected against incorrect usage |
| 565 | x = wmod.catch_warnings(module=wmod, record=True) |
| 566 | self.assertRaises(RuntimeError, x.__exit__) |
| 567 | with x: |
| 568 | self.assertRaises(RuntimeError, x.__enter__) |
| 569 | # Same test, but with recording disabled |
| 570 | x = wmod.catch_warnings(module=wmod, record=False) |
| 571 | self.assertRaises(RuntimeError, x.__exit__) |
| 572 | with x: |
| 573 | self.assertRaises(RuntimeError, x.__enter__) |
| 574 | |
| 575 | def test_catch_warnings_defaults(self): |
| 576 | wmod = self.module |
| 577 | orig_filters = wmod.filters |
| 578 | orig_showwarning = wmod.showwarning |
| 579 | # Ensure default behaviour is not to record warnings |
| 580 | with wmod.catch_warnings(module=wmod) as w: |
| 581 | self.assert_(w is None) |
| 582 | self.assert_(wmod.showwarning is orig_showwarning) |
| 583 | self.assert_(wmod.filters is not orig_filters) |
| 584 | self.assert_(wmod.filters is orig_filters) |
| 585 | if wmod is sys.modules['warnings']: |
| 586 | # Ensure the default module is this one |
| 587 | with wmod.catch_warnings() as w: |
| 588 | self.assert_(w is None) |
| 589 | self.assert_(wmod.showwarning is orig_showwarning) |
| 590 | self.assert_(wmod.filters is not orig_filters) |
| 591 | self.assert_(wmod.filters is orig_filters) |
| 592 | |
| 593 | def test_check_warnings(self): |
| 594 | # Explicit tests for the test.support convenience wrapper |
| 595 | wmod = self.module |
| 596 | if wmod is sys.modules['warnings']: |
| 597 | with support.check_warnings() as w: |
| 598 | self.assertEqual(w.warnings, []) |
| 599 | wmod.simplefilter("always") |
| 600 | wmod.warn("foo") |
| 601 | self.assertEqual(str(w.message), "foo") |
| 602 | wmod.warn("bar") |
| 603 | self.assertEqual(str(w.message), "bar") |
| 604 | self.assertEqual(str(w.warnings[0].message), "foo") |
| 605 | self.assertEqual(str(w.warnings[1].message), "bar") |
| 606 | w.reset() |
| 607 | self.assertEqual(w.warnings, []) |
| 608 | |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 609 | class CCatchWarningTests(CatchWarningTests): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 610 | module = c_warnings |
| 611 | |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 612 | class PyCatchWarningTests(CatchWarningTests): |
Nick Coghlan | b130493 | 2008-07-13 12:25:08 +0000 | [diff] [blame] | 613 | module = py_warnings |
| 614 | |
Christian Heimes | 5fb7c2a | 2007-12-24 08:52:31 +0000 | [diff] [blame] | 615 | |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 616 | def test_main(): |
Christian Heimes | dae2a89 | 2008-04-19 00:55:37 +0000 | [diff] [blame] | 617 | py_warnings.onceregistry.clear() |
| 618 | c_warnings.onceregistry.clear() |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 619 | support.run_unittest(CFilterTests, |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 620 | PyFilterTests, |
| 621 | CWarnTests, |
| 622 | PyWarnTests, |
| 623 | CWCmdLineTests, PyWCmdLineTests, |
| 624 | _WarningsTests, |
| 625 | CWarningsDisplayTests, PyWarningsDisplayTests, |
Brett Cannon | ec92e18 | 2008-09-02 02:46:59 +0000 | [diff] [blame] | 626 | CCatchWarningTests, PyCatchWarningTests, |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 627 | ) |
| 628 | |
Raymond Hettinger | d6f6e50 | 2003-07-13 08:37:40 +0000 | [diff] [blame] | 629 | |
| 630 | if __name__ == "__main__": |
Christian Heimes | 33fe809 | 2008-04-13 13:53:33 +0000 | [diff] [blame] | 631 | test_main() |