9090 "anticipate_failure" , "load_package_tests" , "detect_api_mismatch" ,
9191 "check__all__" , "skip_unless_bind_unix_socket" ,
9292 # sys
93- "is_jython " , "is_android " , "check_impl_detail" , "unix_shell" ,
94- "setswitchinterval" ,
93+ "JYTHON " , "ANDROID " , "check_impl_detail" , "unix_shell" ,
94+ "setswitchinterval" , "MS_WINDOWS" , "MACOS" ,
9595 # network
9696 "HOST" , "IPV6_ENABLED" , "find_unused_port" , "bind_port" , "open_urlresource" ,
9797 "bind_unix_socket" ,
108108 "run_with_tz" , "PGO" , "missing_compiler_executable" , "fd_count" ,
109109 ]
110110
111+
112+ # True if Python is running on Microsoft Windows.
113+ MS_WINDOWS = (sys .platform == 'win32' )
114+
115+ # True if Python is running on Apple macOS.
116+ MACOS = (sys .platform == 'darwin' )
117+
118+ # True if Python runs on Jython
119+ # (Python implemented in Java running in a Java VM)
120+ JYTHON = sys .platform .startswith ('java' )
121+
122+ # True if Python runs on Android
123+ ANDROID = hasattr (sys , 'getandroidapilevel' )
124+
125+
111126class Error (Exception ):
112127 """Base class for regression test exceptions."""
113128
@@ -484,7 +499,7 @@ class USEROBJECTFLAGS(ctypes.Structure):
484499 raise ctypes .WinError ()
485500 if not bool (uof .dwFlags & WSF_VISIBLE ):
486501 reason = "gui not available (WSF_VISIBLE flag not set)"
487- elif sys . platform == 'darwin' :
502+ elif MACOS :
488503 # The Aqua Tk implementations on OS X can abort the process if
489504 # being called in an environment where a window server connection
490505 # cannot be made, for instance when invoked by a buildbot or ssh
@@ -600,7 +615,7 @@ def requires_mac_ver(*min_version):
600615 def decorator (func ):
601616 @functools .wraps (func )
602617 def wrapper (* args , ** kw ):
603- if sys . platform == 'darwin' :
618+ if MACOS :
604619 version_txt = platform .mac_ver ()[0 ]
605620 try :
606621 version = tuple (map (int , version_txt .split ('.' )))
@@ -788,14 +803,12 @@ def dec(*args, **kwargs):
788803
789804requires_lzma = unittest .skipUnless (lzma , 'requires lzma' )
790805
791- is_jython = sys .platform .startswith ('java' )
792-
793- is_android = hasattr (sys , 'getandroidapilevel' )
794-
795- if sys .platform != 'win32' :
796- unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
797- else :
806+ if MS_WINDOWS :
798807 unix_shell = None
808+ elif ANDROID :
809+ unix_shell = '/system/bin/sh'
810+ else :
811+ unix_shell = '/bin/sh'
799812
800813# Filename used for testing
801814if os .name == 'java' :
@@ -854,7 +867,7 @@ def dec(*args, **kwargs):
854867
855868# TESTFN_UNICODE is a non-ascii filename
856869TESTFN_UNICODE = TESTFN + "-\xe0 \xf2 \u0258 \u0141 \u011f "
857- if sys . platform == 'darwin' :
870+ if MACOS :
858871 # In Mac OS X's VFS API file names are, by definition, canonically
859872 # decomposed Unicode, encoded using UTF-8. See QA1173:
860873 # http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
@@ -866,7 +879,7 @@ def dec(*args, **kwargs):
866879# encoded by the filesystem encoding (in strict mode). It can be None if we
867880# cannot generate such filename.
868881TESTFN_UNENCODABLE = None
869- if os . name == 'nt' :
882+ if MS_WINDOWS :
870883 # skip win32s (0) or Windows 9x/ME (1)
871884 if sys .getwindowsversion ().platform >= 2 :
872885 # Different kinds of characters from various languages to minimize the
@@ -881,8 +894,8 @@ def dec(*args, **kwargs):
881894 'Unicode filename tests may not be effective'
882895 % (TESTFN_UNENCODABLE , TESTFN_ENCODING ))
883896 TESTFN_UNENCODABLE = None
884- # Mac OS X denies unencodable filenames (invalid utf-8)
885- elif sys . platform != 'darwin' :
897+ # macOS denies unencodable filenames (invalid utf-8)
898+ elif not MACOS :
886899 try :
887900 # ascii and utf-8 cannot encode the byte 0xff
888901 b'\xff ' .decode (TESTFN_ENCODING )
@@ -1523,7 +1536,7 @@ def gc_collect():
15231536 objects to disappear.
15241537 """
15251538 gc .collect ()
1526- if is_jython :
1539+ if JYTHON :
15271540 time .sleep (0.1 )
15281541 gc .collect ()
15291542 gc .collect ()
@@ -1982,7 +1995,7 @@ def _check_docstrings():
19821995 """Just used to check if docstrings are enabled"""
19831996
19841997MISSING_C_DOCSTRINGS = (check_impl_detail () and
1985- sys . platform != 'win32' and
1998+ not MS_WINDOWS and
19861999 not sysconfig .get_config_var ('WITH_DOC_STRINGS' ))
19872000
19882001HAVE_DOCSTRINGS = (_check_docstrings .__doc__ is not None and
@@ -2592,7 +2605,7 @@ def __enter__(self):
25922605 except (ValueError , OSError ):
25932606 pass
25942607
2595- if sys . platform == 'darwin' :
2608+ if MACOS :
25962609 # Check if the 'Crash Reporter' on OSX was configured
25972610 # in 'Developer' mode and warn that it will get triggered
25982611 # when it is.
@@ -2736,7 +2749,7 @@ def setswitchinterval(interval):
27362749 # Setting a very low gil interval on the Android emulator causes python
27372750 # to hang (issue #26939).
27382751 minimum_interval = 1e-5
2739- if is_android and interval < minimum_interval :
2752+ if ANDROID and interval < minimum_interval :
27402753 global _is_android_emulator
27412754 if _is_android_emulator is None :
27422755 _is_android_emulator = (subprocess .check_output (
@@ -2782,7 +2795,7 @@ def fd_count():
27822795 pass
27832796
27842797 old_modes = None
2785- if sys . platform == 'win32' :
2798+ if MS_WINDOWS :
27862799 # bpo-25306, bpo-31009: Call CrtSetReportMode() to not kill the process
27872800 # on invalid file descriptor if Python is compiled in debug mode
27882801 try :
0 commit comments