Patchwork [stable] tests: fix test-demandimport.py on Python 3.9

login
register
mail settings
Submitter Manuel Jacob
Date Sept. 1, 2020, 11:32 p.m.
Message ID <386d7621b725560face4.1599003146@tmp>
Download mbox | patch
Permalink /patch/47080/
State Accepted
Headers show

Comments

Manuel Jacob - Sept. 1, 2020, 11:32 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1599003056 -7200
#      Wed Sep 02 01:30:56 2020 +0200
# Branch stable
# Node ID 386d7621b725560face484f963f2a96fead521d3
# Parent  42202492a3b9aed0b2810560dfae1feb56a8bea4
# EXP-Topic python3.9
tests: fix test-demandimport.py on Python 3.9

Starting with Python 3.9, importing importlib.resources (indirectly) imports
the zipfile module. Therefore, the module is not suitable for the test.
Instead, we can use the ftplib module, which is very unlikely to be imported
during the test run.
Augie Fackler - Sept. 2, 2020, 1:32 a.m.
queued for stable, thanks

> On Sep 1, 2020, at 19:32, Manuel Jacob <me@manueljacob.de> wrote:
> 
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1599003056 -7200
> #      Wed Sep 02 01:30:56 2020 +0200
> # Branch stable
> # Node ID 386d7621b725560face484f963f2a96fead521d3
> # Parent  42202492a3b9aed0b2810560dfae1feb56a8bea4
> # EXP-Topic python3.9
> tests: fix test-demandimport.py on Python 3.9
> 
> Starting with Python 3.9, importing importlib.resources (indirectly) imports
> the zipfile module. Therefore, the module is not suitable for the test.
> Instead, we can use the ftplib module, which is very unlikely to be imported
> during the test run.
> 
> diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
> --- a/tests/test-demandimport.py
> +++ b/tests/test-demandimport.py
> @@ -232,7 +232,7 @@
> # Unlike the import statement, __import__() function should not raise
> # ImportError even if fromlist has an unknown item
> # (see Python/import.c:import_module_level() and ensure_fromlist())
> -assert 'zipfile' not in sys.modules
> -zipfileimp = __import__('zipfile', globals(), locals(), ['unknownattr'])
> -assert f(zipfileimp) == "<module 'zipfile' from '?'>", f(zipfileimp)
> +assert 'ftplib' not in sys.modules
> +zipfileimp = __import__('ftplib', globals(), locals(), ['unknownattr'])
> +assert f(zipfileimp) == "<module 'ftplib' from '?'>", f(zipfileimp)
> assert not util.safehasattr(zipfileimp, 'unknownattr')
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -232,7 +232,7 @@ 
 # Unlike the import statement, __import__() function should not raise
 # ImportError even if fromlist has an unknown item
 # (see Python/import.c:import_module_level() and ensure_fromlist())
-assert 'zipfile' not in sys.modules
-zipfileimp = __import__('zipfile', globals(), locals(), ['unknownattr'])
-assert f(zipfileimp) == "<module 'zipfile' from '?'>", f(zipfileimp)
+assert 'ftplib' not in sys.modules
+zipfileimp = __import__('ftplib', globals(), locals(), ['unknownattr'])
+assert f(zipfileimp) == "<module 'ftplib' from '?'>", f(zipfileimp)
 assert not util.safehasattr(zipfileimp, 'unknownattr')