Issue #12326: refactor usage of sys.platform

 * Use str.startswith(tuple): I didn't know this Python feature, Python rocks!
 * Replace sometimes sys.platform.startswith('linux') with
   sys.platform == 'linux'
 * sys.platform doesn't contain the major version on Cygwin on Mac OS X
   (it's just 'cygwin' and 'darwin')
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 64c1b4e..b3989e5 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -311,7 +311,7 @@
     def decorator(func):
         @functools.wraps(func)
         def wrapper(*args, **kw):
-            if sys.platform.startswith('linux'):
+            if sys.platform == 'linux':
                 version_txt = platform.release().split('-', 1)[0]
                 try:
                     version = tuple(map(int, version_txt.split('.')))
diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py
index 6e425aa..29af99c 100644
--- a/Lib/test/test_fcntl.py
+++ b/Lib/test/test_fcntl.py
@@ -23,9 +23,8 @@
     else:
         start_len = "qq"
 
-    if (any(sys.platform.startswith(prefix)
-            for prefix in ('netbsd', 'freebsd', 'openbsd', 'bsdos'))
-        or sys.platform in ('Darwin1.2', 'darwin')):
+    if (sys.platform.startswith(('netbsd', 'freebsd', 'openbsd', 'bsdos'))
+        or sys.platform == 'darwin'):
         if struct.calcsize('l') == 8:
             off_t = 'l'
             pid_t = 'i'
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 35beae4..556bbba 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -527,7 +527,7 @@
     def test_builtin_handlers(self):
         # We can't actually *use* too many handlers in the tests,
         # but we can try instantiating them with various options
-        if sys.platform.startswith('linux') or sys.platform == 'darwin':
+        if sys.platform in ('linux', 'darwin'):
             for existing in (True, False):
                 fd, fn = tempfile.mkstemp()
                 os.close(fd)
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 320f373..4e5085e 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -442,10 +442,8 @@
         # Find one service that exists, then check all the related interfaces.
         # I've ordered this by protocols that have both a tcp and udp
         # protocol, at least for modern Linuxes.
-        if (sys.platform.startswith('linux') or
-            sys.platform.startswith('freebsd') or
-            sys.platform.startswith('netbsd') or
-            sys.platform == 'darwin'):
+        if (sys.platform.startswith(('freebsd', 'netbsd'))
+            or sys.platform in ('linux', 'darwin')):
             # avoid the 'echo' service on this platform, as there is an
             # assumption breaking non-standard port/protocol entry
             services = ('daytime', 'qotd', 'domain')
@@ -2074,7 +2072,7 @@
     ])
     if hasattr(socket, "socketpair"):
         tests.append(BasicSocketPairTest)
-    if sys.platform.startswith('linux'):
+    if sys.platform == 'linux':
         tests.append(TestLinuxAbstractNamespace)
     if isTipcAvailable():
         tests.append(TIPCTest)