Skip to content

Commit 9acc6a0

Browse files
authored
test_locale now ignores the DeprecationWarning (#977)
Don't fail anymore if test run with python3 -Werror. Fix also deprecation message: add a space.
1 parent 7341259 commit 9acc6a0

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Lib/locale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def format_string(f, val, grouping=False, monetary=False):
245245
def format(percent, value, grouping=False, monetary=False, *additional):
246246
"""Deprecated, use format_string instead."""
247247
warnings.warn(
248-
"This method will be removed in a future version of Python."
248+
"This method will be removed in a future version of Python. "
249249
"Use 'locale.format_string()' instead.",
250250
DeprecationWarning, stacklevel=2
251251
)

Lib/test/test_locale.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from test.support import verbose, is_android
1+
from test.support import verbose, is_android, check_warnings
22
import unittest
33
import locale
44
import sys
@@ -144,8 +144,9 @@ def _test_formatfunc(self, format, value, out, func, **format_opts):
144144
func(format, value, **format_opts), out)
145145

146146
def _test_format(self, format, value, out, **format_opts):
147-
self._test_formatfunc(format, value, out,
148-
func=locale.format, **format_opts)
147+
with check_warnings(('', DeprecationWarning)):
148+
self._test_formatfunc(format, value, out,
149+
func=locale.format, **format_opts)
149150

150151
def _test_format_string(self, format, value, out, **format_opts):
151152
self._test_formatfunc(format, value, out,
@@ -232,14 +233,15 @@ class TestFormatPatternArg(unittest.TestCase):
232233
# Test handling of pattern argument of format
233234

234235
def test_onlyOnePattern(self):
235-
# Issue 2522: accept exactly one % pattern, and no extra chars.
236-
self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
237-
self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
238-
self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
239-
self.assertRaises(ValueError, locale.format, " %f", 'foo')
240-
self.assertRaises(ValueError, locale.format, "%fg", 'foo')
241-
self.assertRaises(ValueError, locale.format, "%^g", 'foo')
242-
self.assertRaises(ValueError, locale.format, "%f%%", 'foo')
236+
with check_warnings(('', DeprecationWarning)):
237+
# Issue 2522: accept exactly one % pattern, and no extra chars.
238+
self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
239+
self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
240+
self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
241+
self.assertRaises(ValueError, locale.format, " %f", 'foo')
242+
self.assertRaises(ValueError, locale.format, "%fg", 'foo')
243+
self.assertRaises(ValueError, locale.format, "%^g", 'foo')
244+
self.assertRaises(ValueError, locale.format, "%f%%", 'foo')
243245

244246

245247
class TestLocaleFormatString(unittest.TestCase):

0 commit comments

Comments
 (0)