FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test_locale now ignores the DeprecationWarning by vstinner · Pull Request #977 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Lib/locale.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def format_string(f, val, grouping=False, monetary=False):
def format(percent, value, grouping=False, monetary=False, *additional):
"""Deprecated, use format_string instead."""
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.",
DeprecationWarning, stacklevel=2
)
Expand Down
24 changes: 13 additions & 11 deletions Lib/test/test_locale.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from test.support import verbose, is_android
from test.support import verbose, is_android, check_warnings
import unittest
import locale
import sys
Expand Down Expand Up @@ -144,8 +144,9 @@ def _test_formatfunc(self, format, value, out, func, **format_opts):
func(format, value, **format_opts), out)

def _test_format(self, format, value, out, **format_opts):
self._test_formatfunc(format, value, out,
func=locale.format, **format_opts)
with check_warnings(('', DeprecationWarning)):
self._test_formatfunc(format, value, out,
func=locale.format, **format_opts)

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

def test_onlyOnePattern(self):
# Issue 2522: accept exactly one % pattern, and no extra chars.
self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
self.assertRaises(ValueError, locale.format, " %f", 'foo')
self.assertRaises(ValueError, locale.format, "%fg", 'foo')
self.assertRaises(ValueError, locale.format, "%^g", 'foo')
self.assertRaises(ValueError, locale.format, "%f%%", 'foo')
with check_warnings(('', DeprecationWarning)):
# Issue 2522: accept exactly one % pattern, and no extra chars.
self.assertRaises(ValueError, locale.format, "%f\n", 'foo')
self.assertRaises(ValueError, locale.format, "%f\r", 'foo')
self.assertRaises(ValueError, locale.format, "%f\r\n", 'foo')
self.assertRaises(ValueError, locale.format, " %f", 'foo')
self.assertRaises(ValueError, locale.format, "%fg", 'foo')
self.assertRaises(ValueError, locale.format, "%^g", 'foo')
self.assertRaises(ValueError, locale.format, "%f%%", 'foo')


class TestLocaleFormatString(unittest.TestCase):
Expand Down

Back | FazBrowse Home | New Git URL