mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-30197: Enhance functions swap_attr() and swap_item() in test.support. (#1341)
* bpo-30197: Enhance functions swap_attr() and swap_item() in test.support. They now work when delete replaced attribute or item inside the with statement. The old value of the attribute or item (or None if it doesn't exist) now will be assigned to the target of the "as" clause, if there is one. * Update docstrings.
This commit is contained in:
parent
80a3da4d4a
commit
d1a1def7bf
4 changed files with 43 additions and 13 deletions
|
@ -273,13 +273,12 @@ class TestGetDefaultTempdir(BaseTestCase):
|
|||
tempfile._get_default_tempdir()
|
||||
self.assertEqual(os.listdir(our_temp_directory), [])
|
||||
|
||||
open = io.open
|
||||
def bad_writer(*args, **kwargs):
|
||||
fp = open(*args, **kwargs)
|
||||
fp = orig_open(*args, **kwargs)
|
||||
fp.write = raise_OSError
|
||||
return fp
|
||||
|
||||
with support.swap_attr(io, "open", bad_writer):
|
||||
with support.swap_attr(io, "open", bad_writer) as orig_open:
|
||||
# test again with failing write()
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
tempfile._get_default_tempdir()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue