Lines Matching defs:module
19 def warnings_state(module):
32 original_filters = module.filters
34 module.filters = original_filters[:]
35 module.simplefilter("once")
36 warning_tests.warnings = module
40 module.filters = original_filters
56 # The 'warnings' module must be explicitly set so that the proper
58 sys.modules['warnings'] = self.module
71 with original_warnings.catch_warnings(module=self.module) as w:
72 self.module.resetwarnings()
73 self.module.filterwarnings("error", category=UserWarning)
74 self.assertRaises(UserWarning, self.module.warn,
79 module=self.module) as w:
80 self.module.resetwarnings()
81 self.module.filterwarnings("ignore", category=UserWarning)
82 self.module.warn("FilterTests.test_ignore", UserWarning)
87 module=self.module) as w:
88 self.module.resetwarnings()
89 self.module.filterwarnings("always", category=UserWarning)
91 self.module.warn(message, UserWarning)
93 self.module.warn(message, UserWarning)
98 module=self.module) as w:
99 self.module.resetwarnings()
100 self.module.filterwarnings("default", category=UserWarning)
103 self.module.warn(message, UserWarning)
114 module=self.module) as w:
115 self.module.resetwarnings()
116 self.module.filterwarnings("module", category=UserWarning)
118 self.module.warn(message, UserWarning)
121 self.module.warn(message, UserWarning)
126 module=self.module) as w:
127 self.module.resetwarnings()
128 self.module.filterwarnings("once", category=UserWarning)
130 self.module.warn_explicit(message, UserWarning, "test_warnings.py",
134 self.module.warn_explicit(message, UserWarning, "test_warnings.py",
137 self.module.warn_explicit(message, UserWarning, "test_warnings2.py",
142 with original_warnings.catch_warnings(module=self.module) as w:
143 self.module.resetwarnings()
144 self.module.filterwarnings("error", category=Warning)
145 self.assertRaises(UserWarning, self.module.warn,
150 module=self.module) as w:
151 self.module.resetwarnings()
152 self.module.filterwarnings("ignore", category=UserWarning)
153 self.module.filterwarnings("error", category=UserWarning,
157 self.module.warn("FilterTests.test_ordering", UserWarning)
166 module=self.module) as w:
167 self.module.filterwarnings("error", "", Warning, "", 0)
168 self.assertRaises(UserWarning, self.module.warn, 'convert to error')
170 self.module.resetwarnings()
172 self.module.warn(text)
176 self.module.filterwarnings("ignore", "", Warning, "", 0)
178 self.module.warn(text)
181 self.module.resetwarnings()
182 self.module.filterwarnings("error", "hex*", Warning, "", 0)
183 self.assertRaises(UserWarning, self.module.warn, 'hex/oct')
185 self.module.warn(text)
190 module = c_warnings
193 module = py_warnings
202 module=self.module) as w:
203 self.module.simplefilter("once")
206 self.module.warn(text)
211 with warnings_state(self.module):
213 module=self.module) as w:
224 with warnings_state(self.module):
226 module=self.module) as w:
249 # If __file__ is not specified and __main__ is not the module name,
250 # then __file__ should be set to the module name.
254 with warnings_state(self.module):
256 module=self.module) as w:
272 with warnings_state(self.module):
274 module=self.module) as w:
291 with warnings_state(self.module):
293 module=self.module) as w:
312 with warnings_state(self.module):
314 module=self.module) as w:
326 self.assertRaises(TypeError, self.module.warn_explicit,
330 self.assertRaises(TypeError, self.module.warn_explicit,
334 self.module.warn_explicit,
348 self.module.warn(BadStrWarning())
352 module = c_warnings
357 self.assertFalse(original_warnings is self.module)
358 self.assertFalse(hasattr(self.module.warn, 'func_code'))
361 module = py_warnings
366 self.assertFalse(original_warnings is self.module)
367 self.assertTrue(hasattr(self.module.warn, 'func_code'))
375 with original_warnings.catch_warnings(module=self.module):
376 self.assertRaises(self.module._OptionError,
377 self.module._setoption, '1:2:3:4:5:6')
378 self.assertRaises(self.module._OptionError,
379 self.module._setoption, 'bogus::Warning')
380 self.assertRaises(self.module._OptionError,
381 self.module._setoption, 'ignore:2::4:-5')
382 self.module._setoption('error::Warning::0')
383 self.assertRaises(UserWarning, self.module.warn, 'convert to error')
393 # Check that the warnings module does get loaded when -W<some option>
402 module = c_warnings
405 module = py_warnings
410 """Tests specific to the _warnings module."""
412 module = c_warnings
416 with original_warnings.catch_warnings(module=self.module) as w:
417 self.module.filterwarnings("error", "", Warning, "", 0)
418 self.assertRaises(UserWarning, self.module.warn,
420 del self.module.filters
421 self.assertRaises(UserWarning, self.module.warn,
429 original_registry = self.module.onceregistry
432 module=self.module) as w:
433 self.module.resetwarnings()
434 self.module.filterwarnings("once", category=UserWarning)
435 self.module.warn_explicit(message, UserWarning, "file", 42)
438 self.module.warn_explicit(message, UserWarning, "file", 42)
441 self.module.onceregistry = {}
443 self.module.warn('onceregistry test')
447 del self.module.onceregistry
449 self.module.warn_explicit(message, UserWarning, "file", 42)
452 self.module.onceregistry = original_registry
457 original = self.module.defaultaction
460 module=self.module) as w:
461 self.module.resetwarnings()
463 self.module.warn_explicit(message, UserWarning, "<test>", 42,
470 del self.module.defaultaction
473 self.module.warn_explicit(message, UserWarning, "<test>", 43,
480 self.module.defaultaction = "ignore"
483 self.module.warn_explicit(message, UserWarning, "<test>", 44,
487 self.module.defaultaction = original
492 with original_warnings.catch_warnings(module=self.module):
493 self.module.filterwarnings("always", category=UserWarning)
494 del self.module.showwarning
496 self.module.warn(text)
501 with original_warnings.catch_warnings(module=self.module):
502 self.module.filterwarnings("always", category=UserWarning)
503 old_showwarning = self.module.showwarning
504 self.module.showwarning = 23
506 self.assertRaises(TypeError, self.module.warn, "Warning!")
508 self.module.showwarning = old_showwarning
513 with original_warnings.catch_warnings(module=self.module):
514 self.module.filterwarnings("always", category=UserWarning)
515 del self.module.showwarning
538 with original_warnings.catch_warnings(module=self.module) as w:
539 self.module.filterwarnings("always", category=UserWarning)
541 self.module.warn('test', UserWarning)
560 self.assertEqual(expect, self.module.formatwarning(message,
566 self.assertEqual(expect, self.module.formatwarning(message,
576 expect = self.module.formatwarning(message, category, file_name,
578 self.module.showwarning(message, category, file_name, line_num,
583 expect = self.module.formatwarning(message, category, file_name,
586 self.module.showwarning(message, category, file_name, line_num,
591 module = c_warnings
594 module = py_warnings
602 wmod = self.module
606 with wmod.catch_warnings(module=wmod, record=True):
611 with wmod.catch_warnings(module=wmod, record=False):
617 wmod = self.module
619 with wmod.catch_warnings(module=wmod, record=True) as w:
633 with wmod.catch_warnings(module=wmod, record=False) as w:
638 wmod = self.module
640 x = wmod.catch_warnings(module=wmod, record=True)
645 x = wmod.catch_warnings(module=wmod, record=False)
651 wmod = self.module
655 with wmod.catch_warnings(module=wmod) as w:
661 # Ensure the default module is this one
670 wmod = self.module
701 module = c_warnings
704 module = py_warnings
740 module = c_warnings
743 module = py_warnings