tests: obfuscate Python version checks to subvert `pyupgrade`
When specifying `--py38-plus`, it reasonably deletes conditionals that check for
that version of python or earlier. But we actually want the check to remain, so
use a simple obfuscation to preserve it.
--- a/tests/fsmonitor-run-tests.py Tue Jan 07 17:46:56 2025 -0500
+++ b/tests/fsmonitor-run-tests.py Tue Jan 07 17:52:52 2025 -0500
@@ -24,7 +24,11 @@
osenvironb = getattr(os, 'environb', os.environ)
-if sys.version_info >= (3, 8, 0):
+# Don't compare sys.version_info directly, to prevent pyupgrade from dropping
+# the conditional.
+sys_version_info = sys.version_info
+
+if sys_version_info >= (3, 8, 0):
def _sys2bytes(p):
return p.encode('utf-8')
--- a/tests/run-tests.py Tue Jan 07 17:46:56 2025 -0500
+++ b/tests/run-tests.py Tue Jan 07 17:52:52 2025 -0500
@@ -73,7 +73,11 @@
import xml.dom.minidom as minidom
-if sys.version_info < (3, 8, 0):
+# Don't compare sys.version_info directly, to prevent pyupgrade from dropping
+# the conditional.
+sys_version_info = sys.version_info
+
+if sys_version_info < (3, 8, 0):
print(
'%s is only supported on Python 3.8+, not %s'
% (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3]))