@@ -71,6 +71,13 @@ def setUp(self):
7171 def use_real_fs (self ):
7272 return False
7373
74+ def deprecation_warning_since_313 (self ):
75+ return (
76+ contextlib .nullcontext ()
77+ if sys .version_info < (3 , 13 )
78+ else self .assertWarns (DeprecationWarning )
79+ )
80+
7481
7582class FakePathlibInitializationTest (RealPathlibTestCase ):
7683 def test_initialization_type (self ):
@@ -217,11 +224,7 @@ class FakePathlibPurePathTest(RealPathlibTestCase):
217224
218225 def test_is_reserved_posix (self ):
219226 self .check_posix_only ()
220- with (
221- contextlib .nullcontext ()
222- if sys .version_info < (3 , 13 )
223- else self .assertWarns (DeprecationWarning )
224- ):
227+ with self .deprecation_warning_since_313 ():
225228 self .assertFalse (self .path ("/dev" ).is_reserved ())
226229 self .assertFalse (self .path ("/" ).is_reserved ())
227230 self .assertFalse (self .path ("COM1" ).is_reserved ())
@@ -230,11 +233,7 @@ def test_is_reserved_posix(self):
230233 @unittest .skipIf (not is_windows , "Windows specific behavior" )
231234 def test_is_reserved_windows (self ):
232235 self .check_windows_only ()
233- with (
234- contextlib .nullcontext ()
235- if sys .version_info < (3 , 13 )
236- else self .assertWarns (DeprecationWarning )
237- ):
236+ with self .deprecation_warning_since_313 ():
238237 self .assertFalse (self .path ("/dev" ).is_reserved ())
239238 self .assertFalse (self .path ("/" ).is_reserved ())
240239 self .assertTrue (self .path ("COM1" ).is_reserved ())
@@ -310,11 +309,7 @@ def setUp(self):
310309 self .path = self .pathlib .PurePosixPath
311310
312311 def test_is_reserved (self ):
313- with (
314- contextlib .nullcontext ()
315- if sys .version_info < (3 , 13 )
316- else self .assertWarns (DeprecationWarning )
317- ):
312+ with self .deprecation_warning_since_313 ():
318313 self .assertFalse (self .path ("/dev" ).is_reserved ())
319314 self .assertFalse (self .path ("/" ).is_reserved ())
320315 self .assertFalse (self .path ("COM1" ).is_reserved ())
@@ -389,11 +384,7 @@ def setUp(self):
389384 self .path = self .pathlib .PureWindowsPath
390385
391386 def test_is_reserved (self ):
392- with (
393- contextlib .nullcontext ()
394- if sys .version_info < (3 , 13 )
395- else self .assertWarns (DeprecationWarning )
396- ):
387+ with self .deprecation_warning_since_313 ():
397388 self .assertFalse (self .path ("/dev" ).is_reserved ())
398389 self .assertFalse (self .path ("/" ).is_reserved ())
399390 self .assertTrue (self .path ("COM1" ).is_reserved ())
0 commit comments