diff options
| author | Oren Milman <orenmn@gmail.com> | 2017-09-30 14:06:55 (GMT) |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-30 14:06:55 (GMT) |
| commit | 40d736bcf40c10aa5fc7d6cc305a6641afd3cd0e (patch) | |
| tree | 8f8bb3be3e68b9e00f41b636d91051b01ef309bf /Lib/test/test_warnings.py | |
| parent | 8b83687bdf66d2d10afb78e46bcede399deaefde (diff) | |
| download | cpython-40d736bcf40c10aa5fc7d6cc305a6641afd3cd0e.zip cpython-40d736bcf40c10aa5fc7d6cc305a6641afd3cd0e.tar.gz cpython-40d736bcf40c10aa5fc7d6cc305a6641afd3cd0e.tar.bz2 | |
[2.7] bpo-31285: Don't raise a SystemError in warnings.warn_explicit() in case __loader__.get_source() has a bad splitlines() method. (GH-3219) (#3823)
(cherry picked from commit 91fb0af)
Diffstat (limited to 'Lib/test/test_warnings.py')
| -rw-r--r-- | Lib/test/test_warnings.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 0023363..ae081ee 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -584,6 +584,27 @@ class _WarningsTests(BaseTest): self.assertNotIn(b'Warning!', stderr) self.assertNotIn(b'Error', stderr) + def test_issue31285(self): + # warn_explicit() shouldn't raise a SystemError in case the return + # value of get_source() has a bad splitlines() method. + class BadLoader: + def get_source(self, fullname): + class BadSource(str): + def splitlines(self): + return 42 + return BadSource('spam') + + wmod = self.module + with original_warnings.catch_warnings(module=wmod): + wmod.filterwarnings('default', category=UserWarning) + + with test_support.captured_stderr() as stderr: + wmod.warn_explicit( + 'foo', UserWarning, 'bar', 1, + module_globals={'__loader__': BadLoader(), + '__name__': 'foobar'}) + self.assertIn('UserWarning: foo', stderr.getvalue()) + @test_support.cpython_only def test_issue31411(self): # warn_explicit() shouldn't raise a SystemError in case |
