File Lib/locale.py changed (mode: 100644) (index 50cd652574..73fc94d936) |
... |
... |
def format_string(f, val, grouping=False, monetary=False): |
245 |
245 |
def format(percent, value, grouping=False, monetary=False, *additional): |
def format(percent, value, grouping=False, monetary=False, *additional): |
246 |
246 |
"""Deprecated, use format_string instead.""" |
"""Deprecated, use format_string instead.""" |
247 |
247 |
warnings.warn( |
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. " |
249 |
249 |
"Use 'locale.format_string()' instead.", |
"Use 'locale.format_string()' instead.", |
250 |
250 |
DeprecationWarning, stacklevel=2 |
DeprecationWarning, stacklevel=2 |
251 |
251 |
) |
) |
File Lib/test/test_locale.py changed (mode: 100644) (index 06d286622a..4dd300ed11) |
1 |
|
from test.support import verbose, is_android |
|
|
1 |
|
from test.support import verbose, is_android, check_warnings |
2 |
2 |
import unittest |
import unittest |
3 |
3 |
import locale |
import locale |
4 |
4 |
import sys |
import sys |
|
... |
... |
class BaseFormattingTest(object): |
144 |
144 |
func(format, value, **format_opts), out) |
func(format, value, **format_opts), out) |
145 |
145 |
|
|
146 |
146 |
def _test_format(self, format, value, out, **format_opts): |
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) |
149 |
150 |
|
|
150 |
151 |
def _test_format_string(self, format, value, out, **format_opts): |
def _test_format_string(self, format, value, out, **format_opts): |
151 |
152 |
self._test_formatfunc(format, value, out, |
self._test_formatfunc(format, value, out, |
|
... |
... |
class TestFormatPatternArg(unittest.TestCase): |
232 |
233 |
# Test handling of pattern argument of format |
# Test handling of pattern argument of format |
233 |
234 |
|
|
234 |
235 |
def test_onlyOnePattern(self): |
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') |
243 |
245 |
|
|
244 |
246 |
|
|
245 |
247 |
class TestLocaleFormatString(unittest.TestCase): |
class TestLocaleFormatString(unittest.TestCase): |