# HG changeset patch # User Matt Harbison # Date 1672807452 18000 # Node ID ecde742a5a9da7553d0ad6ec048792f7459a3a7f # Parent a8893ec94a08b7bc186b6a39c0009378f0479f81 tests: drop py2 support from test-demandimport.py diff -r a8893ec94a08 -r ecde742a5a9d tests/test-demandimport.py --- 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) == "", 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) == "", f(errorproxy) -else: - assert f(errorproxy) == "", f(errorproxy) +# unsure why this isn't lazy. +assert not isinstance(f, _LazyModule) +assert f(errorproxy) == "", 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) == "", f(errorproxy) -else: - assert f(errorproxy) == "", f(errorproxy) +assert not isinstance(errorproxy, _LazyModule) +assert f(errorproxy) == "", f(errorproxy) import os -if ispy3: - assert not isinstance(os, _LazyModule) - assert f(os) == "", f(os) -else: - assert f(os) == "", f(os) +assert not isinstance(os, _LazyModule) +assert f(os) == "", f(os) assert f(os.system) == '', f(os.system) assert f(os) == "", 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) == "", f( - procutil - ) -else: - assert f(procutil) == "", f(procutil) +assert isinstance(procutil, _LazyModule) +assert f(procutil) == "", f( + procutil +) assert f(procutil.system) == '', 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) == "", f(hgweb) - assert isinstance(hgweb.hgweb_mod, _LazyModule) - assert ( - f(hgweb.hgweb_mod) == "" - ), f(hgweb.hgweb_mod) -else: - assert f(hgweb) == "", f(hgweb) - assert f(hgweb.hgweb_mod) == "", f( - hgweb.hgweb_mod - ) +assert isinstance(hgweb, _LazyModule) +assert f(hgweb) == "", f(hgweb) +assert isinstance(hgweb.hgweb_mod, _LazyModule) +assert f(hgweb.hgweb_mod) == "", f( + hgweb.hgweb_mod +) assert f(hgweb) == "", f(hgweb) import re as fred -if ispy3: - assert not isinstance(fred, _LazyModule) - assert f(fred) == "" -else: - assert f(fred) == "", f(fred) +assert not isinstance(fred, _LazyModule) +assert f(fred) == "" import re as remod -if ispy3: - assert not isinstance(remod, _LazyModule) - assert f(remod) == "" -else: - assert f(remod) == "", f(remod) +assert not isinstance(remod, _LazyModule) +assert f(remod) == "" import sys as re -if ispy3: - assert not isinstance(re, _LazyModule) - assert f(re) == "" -else: - assert f(re) == "", f(re) +assert not isinstance(re, _LazyModule) +assert f(re) == "" -if ispy3: - assert not isinstance(fred, _LazyModule) - assert f(fred) == "", f(fred) -else: - assert f(fred) == "", f(fred) +assert not isinstance(fred, _LazyModule) +assert f(fred) == "", f(fred) assert f(fred.sub) == '', f(fred.sub) -if ispy3: - assert not isinstance(fred, _LazyModule) - assert f(fred) == "", f(fred) -else: - assert f(fred) == "", f(fred) +assert not isinstance(fred, _LazyModule) +assert f(fred) == "", f(fred) remod.escape # use remod assert f(remod) == "", f(remod) -if ispy3: - assert not isinstance(re, _LazyModule) - assert f(re) == "" - assert f(type(re.stderr)) == "", f( - type(re.stderr) - ) - assert f(re) == "" -else: - assert f(re) == "", f(re) - assert f(re.stderr) == "', mode 'w' at 0x?>", f( - re.stderr - ) - assert f(re) == "", f(re) +assert not isinstance(re, _LazyModule) +assert f(re) == "" +assert f(type(re.stderr)) == "", f(type(re.stderr)) +assert f(re) == "" assert 'telnetlib' not in sys.modules import telnetlib -if ispy3: - assert isinstance(telnetlib, _LazyModule) - assert f(telnetlib) == "" -else: - assert f(telnetlib) == "", f(telnetlib) +assert isinstance(telnetlib, _LazyModule) +assert f(telnetlib) == "" try: from telnetlib import unknownattr