1
0
Fork 0
forked from github/pelican

Add unit test utilities temporary_locale and TestCaseWithCLocale (#3224)

This commit is contained in:
boxydog 2023-10-28 17:40:40 -05:00 committed by GitHub
commit fad2ff7ae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 119 deletions

View file

@ -254,3 +254,16 @@ class LoggedTestCase(unittest.TestCase):
actual, count,
msg='expected {} occurrences of {!r}, but found {}'.format(
count, msg, actual))
class TestCaseWithCLocale(unittest.TestCase):
"""Set locale to C for each test case, then restore afterward.
Use utils.temporary_locale if you want a context manager ("with" statement).
"""
def setUp(self):
self.old_locale = locale.setlocale(locale.LC_ALL)
locale.setlocale(locale.LC_ALL, 'C')
def tearDown(self):
locale.setlocale(locale.LC_ALL, self.old_locale)