changeset 49871:ecde742a5a9d

tests: drop py2 support from test-demandimport.py
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 03 Jan 2023 23:44:12 -0500
parents a8893ec94a08
children 40060267df22
files tests/test-demandimport.py
diffstat 1 files changed, 38 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-demandimport.py	Fri Jan 06 10:59:59 2023 -0500
+++ b/tests/test-demandimport.py	Tue Jan 03 23:44:12 2023 -0500
@@ -8,7 +8,6 @@
 import types
 
 # Don't import pycompat because it has too many side-effects.
-ispy3 = sys.version_info[0] >= 3
 
 # Only run if demandimport is allowed
 if subprocess.call(
@@ -24,14 +23,11 @@
 if sys.version_info[0:2] == (3, 5):
     sys.exit(80)
 
-if ispy3:
-    from importlib.util import _LazyModule
+from importlib.util import _LazyModule
 
-    try:
-        from importlib.util import _Module as moduletype
-    except ImportError:
-        moduletype = types.ModuleType
-else:
+try:
+    from importlib.util import _Module as moduletype
+except ImportError:
     moduletype = types.ModuleType
 
 if os.name != 'nt':
@@ -67,10 +63,7 @@
 
 # We use assert instead of a unittest test case because having imports inside
 # functions changes behavior of the demand importer.
-if ispy3:
-    assert not isinstance(node, _LazyModule)
-else:
-    assert f(node) == "<module 'mercurial.node' from '?'>", f(node)
+assert not isinstance(node, _LazyModule)
 
 # now enable it for real
 del os.environ['HGDEMANDIMPORT']
@@ -80,12 +73,9 @@
 assert 'mercurial.error' not in sys.modules
 from mercurial import error as errorproxy
 
-if ispy3:
-    # unsure why this isn't lazy.
-    assert not isinstance(f, _LazyModule)
-    assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
-else:
-    assert f(errorproxy) == "<unloaded module 'error'>", f(errorproxy)
+# unsure why this isn't lazy.
+assert not isinstance(f, _LazyModule)
+assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
 
 doc = ' '.join(errorproxy.__doc__.split()[:3])
 assert doc == 'Mercurial exceptions. This', doc
@@ -96,19 +86,13 @@
 name = errorproxy.__dict__['__name__']
 assert name == 'mercurial.error', name
 
-if ispy3:
-    assert not isinstance(errorproxy, _LazyModule)
-    assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
-else:
-    assert f(errorproxy) == "<proxied module 'error'>", f(errorproxy)
+assert not isinstance(errorproxy, _LazyModule)
+assert f(errorproxy) == "<module 'mercurial.error' from '?'>", f(errorproxy)
 
 import os
 
-if ispy3:
-    assert not isinstance(os, _LazyModule)
-    assert f(os) == "<module 'os' from '?'>", f(os)
-else:
-    assert f(os) == "<unloaded module 'os'>", f(os)
+assert not isinstance(os, _LazyModule)
+assert f(os) == "<module 'os' from '?'>", f(os)
 
 assert f(os.system) == '<built-in function system>', f(os.system)
 assert f(os) == "<module 'os' from '?'>", f(os)
@@ -116,13 +100,10 @@
 assert 'mercurial.utils.procutil' not in sys.modules
 from mercurial.utils import procutil
 
-if ispy3:
-    assert isinstance(procutil, _LazyModule)
-    assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
-        procutil
-    )
-else:
-    assert f(procutil) == "<unloaded module 'procutil'>", f(procutil)
+assert isinstance(procutil, _LazyModule)
+assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
+    procutil
+)
 
 assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
 assert procutil.__class__ == moduletype, procutil.__class__
@@ -134,84 +115,51 @@
 assert 'mercurial.hgweb' not in sys.modules
 from mercurial import hgweb
 
-if ispy3:
-    assert isinstance(hgweb, _LazyModule)
-    assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
-    assert isinstance(hgweb.hgweb_mod, _LazyModule)
-    assert (
-        f(hgweb.hgweb_mod) == "<module 'mercurial.hgweb.hgweb_mod' from '?'>"
-    ), f(hgweb.hgweb_mod)
-else:
-    assert f(hgweb) == "<unloaded module 'hgweb'>", f(hgweb)
-    assert f(hgweb.hgweb_mod) == "<unloaded module 'hgweb_mod'>", f(
-        hgweb.hgweb_mod
-    )
+assert isinstance(hgweb, _LazyModule)
+assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
+assert isinstance(hgweb.hgweb_mod, _LazyModule)
+assert f(hgweb.hgweb_mod) == "<module 'mercurial.hgweb.hgweb_mod' from '?'>", f(
+    hgweb.hgweb_mod
+)
 
 assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
 
 import re as fred
 
-if ispy3:
-    assert not isinstance(fred, _LazyModule)
-    assert f(fred) == "<module 're' from '?'>"
-else:
-    assert f(fred) == "<unloaded module 're'>", f(fred)
+assert not isinstance(fred, _LazyModule)
+assert f(fred) == "<module 're' from '?'>"
 
 import re as remod
 
-if ispy3:
-    assert not isinstance(remod, _LazyModule)
-    assert f(remod) == "<module 're' from '?'>"
-else:
-    assert f(remod) == "<unloaded module 're'>", f(remod)
+assert not isinstance(remod, _LazyModule)
+assert f(remod) == "<module 're' from '?'>"
 
 import sys as re
 
-if ispy3:
-    assert not isinstance(re, _LazyModule)
-    assert f(re) == "<module 'sys' (built-in)>"
-else:
-    assert f(re) == "<unloaded module 'sys'>", f(re)
+assert not isinstance(re, _LazyModule)
+assert f(re) == "<module 'sys' (built-in)>"
 
-if ispy3:
-    assert not isinstance(fred, _LazyModule)
-    assert f(fred) == "<module 're' from '?'>", f(fred)
-else:
-    assert f(fred) == "<unloaded module 're'>", f(fred)
+assert not isinstance(fred, _LazyModule)
+assert f(fred) == "<module 're' from '?'>", f(fred)
 
 assert f(fred.sub) == '<function sub at 0x?>', f(fred.sub)
 
-if ispy3:
-    assert not isinstance(fred, _LazyModule)
-    assert f(fred) == "<module 're' from '?'>", f(fred)
-else:
-    assert f(fred) == "<proxied module 're'>", f(fred)
+assert not isinstance(fred, _LazyModule)
+assert f(fred) == "<module 're' from '?'>", f(fred)
 
 remod.escape  # use remod
 assert f(remod) == "<module 're' from '?'>", f(remod)
 
-if ispy3:
-    assert not isinstance(re, _LazyModule)
-    assert f(re) == "<module 'sys' (built-in)>"
-    assert f(type(re.stderr)) == "<class '_io.TextIOWrapper'>", f(
-        type(re.stderr)
-    )
-    assert f(re) == "<module 'sys' (built-in)>"
-else:
-    assert f(re) == "<unloaded module 'sys'>", f(re)
-    assert f(re.stderr) == "<open file '<whatever>', mode 'w' at 0x?>", f(
-        re.stderr
-    )
-    assert f(re) == "<proxied module 'sys'>", f(re)
+assert not isinstance(re, _LazyModule)
+assert f(re) == "<module 'sys' (built-in)>"
+assert f(type(re.stderr)) == "<class '_io.TextIOWrapper'>", f(type(re.stderr))
+assert f(re) == "<module 'sys' (built-in)>"
 
 assert 'telnetlib' not in sys.modules
 import telnetlib
 
-if ispy3:
-    assert isinstance(telnetlib, _LazyModule)
-    assert f(telnetlib) == "<module 'telnetlib' from '?'>"
-else:
-    assert f(telnetlib) == "<unloaded module 'telnetlib'>", f(telnetlib)
+assert isinstance(telnetlib, _LazyModule)
+assert f(telnetlib) == "<module 'telnetlib' from '?'>"
 
 try:
     from telnetlib import unknownattr