@@ -981,12 +981,23 @@ def do_create(self, dir=None, pre="", suf="", delete=True):
981981
982982 def test_basic (self ):
983983 # NamedTemporaryFile can create files
984- self .do_create ()
984+ f = self .do_create ()
985+ self .assertIsInstance (f , tempfile .TemporaryFileWrapper )
985986 self .do_create (pre = "a" )
986987 self .do_create (suf = "b" )
987988 self .do_create (pre = "a" , suf = "b" )
988989 self .do_create (pre = "aa" , suf = ".txt" )
989990
991+ def test_in_all (self ):
992+ self .assertIn ("TemporaryFileWrapper" , tempfile .__all__ )
993+
994+ def test_deprecated_TemporaryFileWrapper_alias (self ):
995+ # gh-152586: _TemporaryFileWrapper is a deprecated alias
996+ # for the public TemporaryFileWrapper class.
997+ with self .assertWarns (DeprecationWarning ):
998+ obj = tempfile ._TemporaryFileWrapper
999+ self .assertIs (obj , tempfile .TemporaryFileWrapper )
1000+
9901001 def test_method_lookup (self ):
9911002 # Issue #18879: Looking up a temporary file method should keep it
9921003 # alive long enough.
@@ -1186,7 +1197,7 @@ def test_bad_encoding(self):
11861197 def test_unexpected_error (self ):
11871198 dir = tempfile .mkdtemp ()
11881199 self .addCleanup (os_helper .rmtree , dir )
1189- with mock .patch ('tempfile._TemporaryFileWrapper ' ) as mock_ntf , \
1200+ with mock .patch ('tempfile.TemporaryFileWrapper ' ) as mock_ntf , \
11901201 mock .patch ('io.open' , mock .mock_open ()) as mock_open :
11911202 mock_ntf .side_effect = KeyboardInterrupt ()
11921203 with self .assertRaises (KeyboardInterrupt ):
@@ -1196,18 +1207,6 @@ def test_unexpected_error(self):
11961207
11971208 # How to test the mode and bufsize parameters?
11981209
1199- class TestTemporaryFileWrapper (BaseTestCase ):
1200- """Test TemporaryFileWrapper."""
1201-
1202- def test_public_name (self ):
1203- self .assertIs (tempfile .TemporaryFileWrapper , tempfile ._TemporaryFileWrapper )
1204-
1205- def test_in_all (self ):
1206- self .assertIn ("TemporaryFileWrapper" , tempfile .__all__ )
1207-
1208- def test_is_return_type_of_named_temporary_file (self ):
1209- with tempfile .NamedTemporaryFile () as f :
1210- self .assertIsInstance (f , tempfile .TemporaryFileWrapper )
12111210
12121211class TestSpooledTemporaryFile (BaseTestCase ):
12131212 """Test SpooledTemporaryFile()."""
0 commit comments