Kaydet (Commit) 9acc6a03 authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

test_locale now ignores the DeprecationWarning (#977)

Don't fail anymore if test run with python3 -Werror.

Fix also deprecation message: add a space.
üst 73412593
...@@ -245,7 +245,7 @@ def format_string(f, val, grouping=False, monetary=False): ...@@ -245,7 +245,7 @@ def format_string(f, val, grouping=False, monetary=False):
def format(percent, value, grouping=False, monetary=False, *additional): def format(percent, value, grouping=False, monetary=False, *additional):
"""Deprecated, use format_string instead.""" """Deprecated, use format_string instead."""
warnings.warn( warnings.warn(
"This method will be removed in a future version of Python." "This method will be removed in a future version of Python. "
"Use 'locale.format_string()' instead.", "Use 'locale.format_string()' instead.",
DeprecationWarning, stacklevel=2 DeprecationWarning, stacklevel=2
) )
......
from test.support import verbose, is_android from test.support import verbose, is_android, check_warnings
import unittest import unittest
import locale import locale
import sys import sys
...@@ -144,8 +144,9 @@ class BaseFormattingTest(object): ...@@ -144,8 +144,9 @@ class BaseFormattingTest(object):
func(format, value, **format_opts), out) func(format, value, **format_opts), out)
def _test_format(self, format, value, out, **format_opts): def _test_format(self, format, value, out, **format_opts):
self._test_formatfunc(format, value, out, with check_warnings(('', DeprecationWarning)):
func=locale.format, **format_opts) self._test_formatfunc(format, value, out,
func=locale.format, **format_opts)
def _test_format_string(self, format, value, out, **format_opts): def _test_format_string(self, format, value, out, **format_opts):
self._test_formatfunc(format, value, out, self._test_formatfunc(format, value, out,
...@@ -232,14 +233,15 @@ class TestFormatPatternArg(unittest.TestCase): ...@@ -232,14 +233,15 @@ class TestFormatPatternArg(unittest.TestCase):
# Test handling of pattern argument of format # Test handling of pattern argument of format
def test_onlyOnePattern(self): def test_onlyOnePattern(self):
# Issue 2522: accept exactly one % pattern, and no extra chars. with check_warnings(('', DeprecationWarning)):
self.assertRaises(ValueError, locale.format, "%f\n", 'foo') # Issue 2522: accept exactly one % pattern, and no extra chars.
self.assertRaises(ValueError, locale.format, "%f\r", 'foo') self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo') self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
self.assertRaises(ValueError, locale.format, " %f", 'foo') self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
self.assertRaises(ValueError, locale.format, "%fg", 'foo') self.assertRaises(ValueError, locale.format, " %f", 'foo')
self.assertRaises(ValueError, locale.format, "%^g", 'foo') self.assertRaises(ValueError, locale.format, "%fg", 'foo')
self.assertRaises(ValueError, locale.format, "%f%%", 'foo') self.assertRaises(ValueError, locale.format, "%^g", 'foo')
self.assertRaises(ValueError, locale.format, "%f%%", 'foo')
class TestLocaleFormatString(unittest.TestCase): class TestLocaleFormatString(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment