mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-45046: Support context managers in unittest (GH-28045)
Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext().
This commit is contained in:
parent
8f29318079
commit
086c6b1b0f
26 changed files with 307 additions and 92 deletions
|
@ -117,6 +117,7 @@ MMOFILE = os.path.join(LOCALEDIR, 'metadata.mo')
|
|||
|
||||
class GettextBaseTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.addCleanup(os_helper.rmtree, os.path.split(LOCALEDIR)[0])
|
||||
if not os.path.isdir(LOCALEDIR):
|
||||
os.makedirs(LOCALEDIR)
|
||||
with open(MOFILE, 'wb') as fp:
|
||||
|
@ -129,14 +130,10 @@ class GettextBaseTest(unittest.TestCase):
|
|||
fp.write(base64.decodebytes(UMO_DATA))
|
||||
with open(MMOFILE, 'wb') as fp:
|
||||
fp.write(base64.decodebytes(MMO_DATA))
|
||||
self.env = os_helper.EnvironmentVarGuard()
|
||||
self.env = self.enterContext(os_helper.EnvironmentVarGuard())
|
||||
self.env['LANGUAGE'] = 'xx'
|
||||
gettext._translations.clear()
|
||||
|
||||
def tearDown(self):
|
||||
self.env.__exit__()
|
||||
del self.env
|
||||
os_helper.rmtree(os.path.split(LOCALEDIR)[0])
|
||||
|
||||
GNU_MO_DATA_ISSUE_17898 = b'''\
|
||||
3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue