diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2020-01-05 14:15:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-05 14:15:27 +0200 |
| commit | 41ec17e45d54473d32f543396293256f1581e44d (patch) | |
| tree | 3181bfa98e7f3c942fca53e339a2098af32e3cd1 /Lib/test | |
| parent | 6a265f0d0c0a4b3b8fecf4275d49187a384167f4 (diff) | |
| download | cpython-git-41ec17e45d54473d32f543396293256f1581e44d.tar.gz | |
bpo-39056: Fix handling invalid warning category in the -W option. (GH-17618)
No longer import the re module if it is not needed.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_warnings/__init__.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 3a6d64eaad..c6fb097ae6 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -43,6 +43,10 @@ def warnings_state(module): module.filters = original_filters +class TestWarning(Warning): + pass + + class BaseTest: """Basic bookkeeping required for testing.""" @@ -566,9 +570,28 @@ class WCmdLineTests(BaseTest): self.module._setoption, 'bogus::Warning') self.assertRaises(self.module._OptionError, self.module._setoption, 'ignore:2::4:-5') + with self.assertRaises(self.module._OptionError): + self.module._setoption('ignore::123') + with self.assertRaises(self.module._OptionError): + self.module._setoption('ignore::123abc') + with self.assertRaises(self.module._OptionError): + self.module._setoption('ignore::===') + with self.assertRaisesRegex(self.module._OptionError, 'Wärning'): + self.module._setoption('ignore::Wärning') self.module._setoption('error::Warning::0') self.assertRaises(UserWarning, self.module.warn, 'convert to error') + def test_import_from_module(self): + with original_warnings.catch_warnings(module=self.module): + self.module._setoption('ignore::Warning') + with self.assertRaises(self.module._OptionError): + self.module._setoption('ignore::TestWarning') + with self.assertRaises(self.module._OptionError): + self.module._setoption('ignore::test.test_warnings.bogus') + self.module._setoption('error::test.test_warnings.TestWarning') + with self.assertRaises(TestWarning): + self.module.warn('test warning', TestWarning) + class CWCmdLineTests(WCmdLineTests, unittest.TestCase): module = c_warnings |
