• Home
  • Raw
  • Download

Lines Matching +full:is +full:- +full:module

19 def warnings_state(module):  argument
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
72 self.assertTrue(hasattr(self.module, '__all__'))
76 self.assertSetEqual(set(self.module.__all__),
80 module = c_warnings variable in CPublicAPITests
83 module = py_warnings variable in PyPublicAPITests
90 with original_warnings.catch_warnings(module=self.module) as w:
91 self.module.resetwarnings()
92 self.module.filterwarnings("error", category=UserWarning)
93 self.assertRaises(UserWarning, self.module.warn,
98 module=self.module) as w:
99 self.module.resetwarnings()
100 self.module.filterwarnings("ignore", category=UserWarning)
101 self.module.warn("FilterTests.test_ignore", UserWarning)
106 module=self.module) as w:
107 self.module.resetwarnings()
108 self.module.filterwarnings("always", category=UserWarning)
111 self.module.warn(message, UserWarning)
114 self.assertEqual(w[-1].message.args[0], message)
117 self.assertEqual(w[-1].message.args[0], message)
121 module=self.module) as w:
122 self.module.resetwarnings()
123 self.module.filterwarnings("default", category=UserWarning)
126 self.module.warn(message, UserWarning)
128 self.assertEqual(w[-1].message, message)
137 module=self.module) as w:
138 self.module.resetwarnings()
139 self.module.filterwarnings("module", category=UserWarning)
141 self.module.warn(message, UserWarning)
142 self.assertEqual(w[-1].message, message)
144 self.module.warn(message, UserWarning)
149 module=self.module) as w:
150 self.module.resetwarnings()
151 self.module.filterwarnings("once", category=UserWarning)
153 self.module.warn_explicit(message, UserWarning, "test_warnings.py",
155 self.assertEqual(w[-1].message, message)
157 self.module.warn_explicit(message, UserWarning, "test_warnings.py",
160 self.module.warn_explicit(message, UserWarning, "test_warnings2.py",
165 with original_warnings.catch_warnings(module=self.module) as w:
166 self.module.resetwarnings()
167 self.module.filterwarnings("error", category=Warning)
168 self.assertRaises(UserWarning, self.module.warn,
173 module=self.module) as w:
174 self.module.resetwarnings()
175 self.module.filterwarnings("ignore", category=UserWarning)
176 self.module.filterwarnings("error", category=UserWarning,
180 self.module.warn("FilterTests.test_ordering", UserWarning)
189 module=self.module) as w:
190 self.module.filterwarnings("error", "", Warning, "", 0)
191 self.assertRaises(UserWarning, self.module.warn, 'convert to error')
193 self.module.resetwarnings()
195 self.module.warn(text)
196 self.assertEqual(str(w[-1].message), text)
197 self.assertTrue(w[-1].category is UserWarning)
199 self.module.filterwarnings("ignore", "", Warning, "", 0)
201 self.module.warn(text)
202 self.assertNotEqual(str(w[-1].message), text)
204 self.module.resetwarnings()
205 self.module.filterwarnings("error", "hex*", Warning, "", 0)
206 self.assertRaises(UserWarning, self.module.warn, 'hex/oct')
208 self.module.warn(text)
209 self.assertEqual(str(w[-1].message), text)
210 self.assertTrue(w[-1].category is UserWarning)
214 module=self.module) as w:
215 self.module.simplefilter("ignore", UserWarning)
216 self.module.filterwarnings("error", "match", UserWarning)
217 self.assertRaises(UserWarning, self.module.warn, "match")
218 self.assertRaises(UserWarning, self.module.warn, "match prefix")
219 self.module.warn("suffix match")
221 self.module.warn("something completely different")
225 module = c_warnings variable in CFilterTests
228 module = py_warnings variable in PyFilterTests
237 module=self.module) as w:
238 self.module.simplefilter("once")
241 self.module.warn(text)
242 self.assertEqual(str(w[-1].message), text)
243 self.assertTrue(w[-1].category is UserWarning)
246 with warnings_state(self.module):
248 module=self.module) as w:
250 self.assertEqual(os.path.basename(w[-1].filename),
253 self.assertEqual(os.path.basename(w[-1].filename),
259 with warnings_state(self.module):
261 module=self.module) as w:
263 self.assertEqual(os.path.basename(w[-1].filename),
266 self.assertEqual(os.path.basename(w[-1].filename),
270 self.assertEqual(os.path.basename(w[-1].filename),
273 self.assertEqual(os.path.basename(w[-1].filename),
276 self.assertEqual(os.path.basename(w[-1].filename),
280 self.assertEqual(os.path.basename(w[-1].filename),
284 # If __file__ is not specified and __main__ is not the module name,
285 # then __file__ should be set to the module name.
289 with warnings_state(self.module):
291 module=self.module) as w:
293 self.assertEqual(w[-1].filename, warning_tests.__name__)
299 # If __file__ is not specified and the caller is __main__ and sys.argv
306 with warnings_state(self.module):
308 module=self.module) as w:
310 self.assertEqual(w[-1].filename, sys.argv[0])
316 # If __file__ is not specified, the caller is __main__, and sys.argv
317 # is not set, then '__main__' is the file name.
325 with warnings_state(self.module):
327 module=self.module) as w:
329 self.assertEqual(w[-1].filename, '__main__')
336 # If __file__ is not specified, the caller is __main__, and sys.argv[0]
337 # is the empty string, then '__main__ is the file name.
346 with warnings_state(self.module):
348 module=self.module) as w:
350 self.assertEqual(w[-1].filename, '__main__')
357 # warn_explicit() should error out gracefully if it is given objects
359 # lineno is expected to be an integer.
360 self.assertRaises(TypeError, self.module.warn_explicit,
364 self.assertRaises(TypeError, self.module.warn_explicit,
368 self.module.warn_explicit,
379 {"err" : "there is no %(err)s"})
382 self.module.warn(BadStrWarning())
386 module = c_warnings variable in CWarnTests
391 self.assertFalse(original_warnings is self.module)
392 self.assertFalse(hasattr(self.module.warn, 'func_code'))
395 module = py_warnings variable in PyWarnTests
400 self.assertFalse(original_warnings is self.module)
401 self.assertTrue(hasattr(self.module.warn, 'func_code'))
408 # of command-line warning arguments
409 with original_warnings.catch_warnings(module=self.module):
410 self.assertRaises(self.module._OptionError,
411 self.module._setoption, '1:2:3:4:5:6')
412 self.assertRaises(self.module._OptionError,
413 self.module._setoption, 'bogus::Warning')
414 self.assertRaises(self.module._OptionError,
415 self.module._setoption, 'ignore:2::4:-5')
416 self.module._setoption('error::Warning::0')
417 self.assertRaises(UserWarning, self.module.warn, 'convert to error')
420 # Same as above, but check that the message is printed out when
421 # the interpreter is executed. This also checks that options are
423 rc, out, err = assert_python_ok("-Wxxx", "-c", "pass")
424 self.assertIn(b"Invalid -W option ignored: invalid action: 'xxx'", err)
427 # Check that the warnings module does get loaded when -W<some option>
428 # is used (see issue #10372 for an example of silent bootstrap failure).
429 rc, out, err = assert_python_ok("-Wi", "-c",
431 # '-Wi' was observed
436 module = c_warnings variable in CWCmdLineTests
439 module = py_warnings variable in PyWCmdLineTests
444 """Tests specific to the _warnings module."""
446 module = c_warnings variable in _WarningsTests
449 # Everything should function even if 'filters' is not in warnings.
450 with original_warnings.catch_warnings(module=self.module) as w:
451 self.module.filterwarnings("error", "", Warning, "", 0)
452 self.assertRaises(UserWarning, self.module.warn,
454 del self.module.filters
455 self.assertRaises(UserWarning, self.module.warn,
463 original_registry = self.module.onceregistry
466 module=self.module) as w:
467 self.module.resetwarnings()
468 self.module.filterwarnings("once", category=UserWarning)
469 self.module.warn_explicit(message, UserWarning, "file", 42)
470 self.assertEqual(w[-1].message, message)
472 self.module.warn_explicit(message, UserWarning, "file", 42)
475 self.module.onceregistry = {}
477 self.module.warn('onceregistry test')
478 self.assertEqual(w[-1].message.args, message.args)
479 # Removal of onceregistry is okay.
481 del self.module.onceregistry
483 self.module.warn_explicit(message, UserWarning, "file", 42)
486 self.module.onceregistry = original_registry
491 original = self.module.defaultaction
494 module=self.module) as w:
495 self.module.resetwarnings()
497 self.module.warn_explicit(message, UserWarning, "<test>", 42,
499 self.assertEqual(w[-1].message, message)
504 del self.module.defaultaction
507 self.module.warn_explicit(message, UserWarning, "<test>", 43,
509 self.assertEqual(w[-1].message, message)
514 self.module.defaultaction = "ignore"
517 self.module.warn_explicit(message, UserWarning, "<test>", 44,
521 self.module.defaultaction = original
524 # Test that showwarning() missing is okay.
526 with original_warnings.catch_warnings(module=self.module):
527 self.module.filterwarnings("always", category=UserWarning)
528 del self.module.showwarning
530 self.module.warn(text)
535 with original_warnings.catch_warnings(module=self.module):
536 self.module.filterwarnings("always", category=UserWarning)
537 old_showwarning = self.module.showwarning
538 self.module.showwarning = 23
540 self.assertRaises(TypeError, self.module.warn, "Warning!")
542 self.module.showwarning = old_showwarning
545 # With showarning() missing, make sure that output is okay.
547 with original_warnings.catch_warnings(module=self.module):
548 self.module.filterwarnings("always", category=UserWarning)
549 del self.module.showwarning
568 # issue #12467: race condition if a warning is emitted at shutdown
572 with original_warnings.catch_warnings(module=self.module, record=True) as w:
573 self.module.filterwarnings("always", category=UserWarning)
575 self.module.warn('test', UserWarning)
583 rc, stdout, stderr = assert_python_ok("-c",
601 wmod = self.module
602 with original_warnings.catch_warnings(module=wmod):
616 wmod = self.module
617 with original_warnings.catch_warnings(module=wmod):
638 self.assertEqual(expect, self.module.formatwarning(message,
644 self.assertEqual(expect, self.module.formatwarning(message,
657 self.assertEqual(expect, self.module.formatwarning(message,
663 self.assertEqual(expect, self.module.formatwarning(message,
678 self.assertEqual(expect, self.module.formatwarning(message,
683 self.assertEqual(expect, self.module.formatwarning(message,
696 self.assertEqual(expect, self.module.formatwarning(message,
701 self.assertEqual(expect, self.module.formatwarning(message,
711 expect = self.module.formatwarning(message, category, file_name,
713 self.module.showwarning(message, category, file_name, line_num,
718 expect = self.module.formatwarning(message, category, file_name,
721 self.module.showwarning(message, category, file_name, line_num,
726 module = c_warnings variable in CWarningsDisplayTests
729 module = py_warnings variable in PyWarningsDisplayTests
737 wmod = self.module
741 with wmod.catch_warnings(module=wmod, record=True):
743 self.assertTrue(wmod.filters is orig_filters)
744 self.assertTrue(wmod.showwarning is orig_showwarning)
746 with wmod.catch_warnings(module=wmod, record=False):
748 self.assertTrue(wmod.filters is orig_filters)
749 self.assertTrue(wmod.showwarning is orig_showwarning)
752 wmod = self.module
754 with wmod.catch_warnings(module=wmod, record=True) as w:
756 self.assertTrue(type(w) is list)
759 self.assertEqual(str(w[-1].message), "foo")
761 self.assertEqual(str(w[-1].message), "bar")
768 with wmod.catch_warnings(module=wmod, record=False) as w:
769 self.assertTrue(w is None)
770 self.assertTrue(wmod.showwarning is orig_showwarning)
773 wmod = self.module
774 # Ensure catch_warnings is protected against incorrect usage
775 x = wmod.catch_warnings(module=wmod, record=True)
780 x = wmod.catch_warnings(module=wmod, record=False)
786 wmod = self.module
789 # Ensure default behaviour is not to record warnings
790 with wmod.catch_warnings(module=wmod) as w:
791 self.assertTrue(w is None)
792 self.assertTrue(wmod.showwarning is orig_showwarning)
793 self.assertTrue(wmod.filters is not orig_filters)
794 self.assertTrue(wmod.filters is orig_filters)
795 if wmod is sys.modules['warnings']:
796 # Ensure the default module is this one
798 self.assertTrue(w is None)
799 self.assertTrue(wmod.showwarning is orig_showwarning)
800 self.assertTrue(wmod.filters is not orig_filters)
801 self.assertTrue(wmod.filters is orig_filters)
805 wmod = self.module
806 if wmod is not sys.modules['warnings']:
807 self.skipTest('module to test is not loaded warnings module')
836 module = c_warnings variable in CCatchWarningTests
839 module = py_warnings variable in PyCatchWarningTests
848 "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
858 "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
867 p = subprocess.Popen([sys.executable, "-W" "ignore::UnicodeWarning",
868 "-c", "import sys; sys.stdout.write(str(sys.warnoptions))"],
875 module = c_warnings variable in CEnvironmentVariableTests
878 module = py_warnings variable in PyEnvironmentVariableTests