tests/test-demandimport.py
author Gregory Szorc <gregory.szorc@gmail.com>
Fri, 01 Feb 2019 12:09:05 -0800
changeset 41505 dffd6a301570
parent 37964 1d0610fdd63b
child 41506 3e89736b98ce
permissions -rw-r--r--
py3: replace print() with assert in test-demandimport.py Behavior of demand imports behaves differently between Python 2 and 3. .out files do not support conditional output the way that .t files do. In order to make this test work on Python 3, we'll need to make the test itself conditional. The first step of this is to port the test to not use a .out file to compare output. Unfortunately, we can't easily use the unittest framework for defining this test because putting import statements in functions changes the behavior of the demand importer (at least on Python 2). So, we effectively replace a bunch of print() with assert statements. This makes the test a bit annoying to debug, as the test will stop at first assertion failure. But we don't exactly have a good alternative. Differential Revision: https://phab.mercurial-scm.org/D5795
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33918
eddca62d9e64 tests: ensure demandimport test uses absolute_import
Augie Fackler <raf@durin42.com>
parents: 32448
diff changeset
     1
from __future__ import absolute_import, print_function
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
     2
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
from mercurial import demandimport
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
demandimport.enable()
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
     6
import os
29868
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
     7
import subprocess
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
     8
import sys
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
     9
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    10
# Only run if demandimport is allowed
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    11
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'],
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    12
                    'demandimport']):
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    13
    sys.exit(80)
4b50e1f922a0 tests: skip demandimport if disabled
timeless <timeless@mozdev.org>
parents: 28948
diff changeset
    14
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    15
# We rely on assert, which gets optimized out.
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    16
if sys.flags.optimize:
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    17
    sys.exit(80)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    18
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    19
if os.name != 'nt':
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    20
    try:
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    21
        import distutils.msvc9compiler
28948
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    22
        print('distutils.msvc9compiler needs to be an immediate '
16390f4cccf0 py3: make test-demandimport use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27535
diff changeset
    23
              'importerror on non-windows platforms')
23643
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    24
        distutils.msvc9compiler
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    25
    except ImportError:
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    26
        pass
2205d00b6d2b demandimport: blacklist distutils.msvc9compiler (issue4475)
Augie Fackler <raf@durin42.com>
parents: 21025
diff changeset
    27
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
import re
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
rsub = re.sub
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
def f(obj):
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
    l = repr(obj)
4802
3a4310e8fe72 test-demandimport: match upper-case hexadecimal
Patrick Mezard <pmezard@gmail.com>
parents: 4631
diff changeset
    33
    l = rsub("0x[0-9a-fA-F]+", "0x?", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
    l = rsub("from '.*'", "from '?'", l)
13083
c0290fc6b486 test-demandimport.py: PyPy support
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 12865
diff changeset
    35
    l = rsub("'<[a-z]*>'", "'<whatever>'", l)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    36
    return l
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
36237
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    38
demandimport.disable()
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    39
os.environ['HGDEMANDIMPORT'] = 'disable'
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    40
# this enable call should not actually enable demandimport!
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    41
demandimport.enable()
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    42
from mercurial import node
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    43
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    44
# We use assert instead of a unittest test case because having imports inside
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    45
# functions changes behavior of the demand importer.
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    46
assert f(node) == "<module 'mercurial.node' from '?'>", f(node)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    47
36237
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    48
# now enable it for real
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    49
del os.environ['HGDEMANDIMPORT']
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    50
demandimport.enable()
b39f0fdb0338 tests: actually check that HGDEMANDIMPORT=disable disables demandimport
Martin von Zweigbergk <martinvonz@google.com>
parents: 33918
diff changeset
    51
36251
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36237
diff changeset
    52
# Test access to special attributes through demandmod proxy
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36237
diff changeset
    53
from mercurial import error as errorproxy
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    54
assert f(errorproxy) == "<unloaded module 'error'>", f(errorproxy)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    55
doc = ' '.join(errorproxy.__doc__.split()[:3])
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    56
assert doc == 'Mercurial exceptions. This', doc
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    57
assert errorproxy.__name__ == 'mercurial.error', errorproxy.__name__
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    58
36251
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36237
diff changeset
    59
# __name__ must be accessible via __dict__ so the relative imports can be
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36237
diff changeset
    60
# resolved
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    61
name = errorproxy.__dict__['__name__']
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    62
assert name == 'mercurial.error', name
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    63
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    64
assert f(errorproxy) == "<proxied module 'error'>", f(errorproxy)
36251
c2c5f9f6fa21 tests: avoid referring to pvec in demandimport test
Martin von Zweigbergk <martinvonz@google.com>
parents: 36237
diff changeset
    65
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    66
import os
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    67
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    68
assert f(os) == "<unloaded module 'os'>", f(os)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    69
assert f(os.system) == '<built-in function system>', f(os.system)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    70
assert f(os) == "<module 'os' from '?'>", f(os)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    71
37964
1d0610fdd63b tests: migrate demandimport.py away from deprecated `util` module symbols
Matt Harbison <matt_harbison@yahoo.com>
parents: 36251
diff changeset
    72
from mercurial.utils import procutil
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    73
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    74
assert f(procutil) == "<unloaded module 'procutil'>", f(procutil)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    75
assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    76
assert f(procutil) == "<module 'mercurial.utils.procutil' from '?'>", f(
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    77
    procutil
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    78
)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    79
assert f(procutil.system) == '<function system at 0x?>', f(procutil.system)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    80
27535
0d0f4070f6d7 test-demandimport: ensure that relative imports are deferred
Bryan O'Sullivan <bos@serpentine.com>
parents: 23643
diff changeset
    81
from mercurial import hgweb
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    82
assert f(hgweb) == "<unloaded module 'hgweb'>", f(hgweb)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    83
assert f(hgweb.hgweb_mod) == "<unloaded module 'hgweb_mod'>", f(hgweb.hgweb_mod)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    84
assert f(hgweb) == "<module 'mercurial.hgweb' from '?'>", f(hgweb)
27535
0d0f4070f6d7 test-demandimport: ensure that relative imports are deferred
Bryan O'Sullivan <bos@serpentine.com>
parents: 23643
diff changeset
    85
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    86
import re as fred
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    87
assert f(fred) == "<unloaded module 're'>", f(fred)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    88
32447
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30647
diff changeset
    89
import re as remod
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    90
assert f(remod) == "<unloaded module 're'>", f(remod)
32447
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30647
diff changeset
    91
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    92
import sys as re
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    93
assert f(re) == "<unloaded module 'sys'>", f(re)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    94
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    95
assert f(fred) == "<unloaded module 're'>", f(fred)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    96
assert f(fred.sub) == '<function sub at 0x?>', f(fred.sub)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
    97
assert f(fred) == "<proxied module 're'>", f(fred)
4631
e3afa670e484 demandimport: fix issue579 and add a test
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    98
32447
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30647
diff changeset
    99
remod.escape  # use remod
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   100
assert f(remod) == "<module 're' from '?'>", f(remod)
32447
252d2260c74e demandimport: look for 'mod' suffix as alternative name for module reference
Yuya Nishihara <yuya@tcha.org>
parents: 30647
diff changeset
   101
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   102
assert f(re) == "<unloaded module 'sys'>", f(re)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   103
assert f(re.stderr) == "<open file '<whatever>', mode 'w' at 0x?>", f(re.stderr)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   104
assert f(re) == "<proxied module 'sys'>", f(re)
21025
54af51c18c4c demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Mads Kiilerich <madski@unity3d.com>
parents: 13083
diff changeset
   105
30022
26a4e46af2bc demandimport: error out early on missing attribute of non package (issue5373)
Yuya Nishihara <yuya@tcha.org>
parents: 29981
diff changeset
   106
import contextlib
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   107
assert f(contextlib) == "<unloaded module 'contextlib'>", f(contextlib)
30022
26a4e46af2bc demandimport: error out early on missing attribute of non package (issue5373)
Yuya Nishihara <yuya@tcha.org>
parents: 29981
diff changeset
   108
try:
26a4e46af2bc demandimport: error out early on missing attribute of non package (issue5373)
Yuya Nishihara <yuya@tcha.org>
parents: 29981
diff changeset
   109
    from contextlib import unknownattr
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   110
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   111
    assert False, (
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   112
        'no demandmod should be created for attribute of non-package '
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   113
        'module:\ncontextlib.unknownattr = %s' % f(unknownattr)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   114
    )
30022
26a4e46af2bc demandimport: error out early on missing attribute of non package (issue5373)
Yuya Nishihara <yuya@tcha.org>
parents: 29981
diff changeset
   115
except ImportError as inst:
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   116
    assert rsub(r"'", '', str(inst)) == 'cannot import name unknownattr'
30647
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30022
diff changeset
   117
37964
1d0610fdd63b tests: migrate demandimport.py away from deprecated `util` module symbols
Matt Harbison <matt_harbison@yahoo.com>
parents: 36251
diff changeset
   118
from mercurial import util
1d0610fdd63b tests: migrate demandimport.py away from deprecated `util` module symbols
Matt Harbison <matt_harbison@yahoo.com>
parents: 36251
diff changeset
   119
30647
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30022
diff changeset
   120
# Unlike the import statement, __import__() function should not raise
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30022
diff changeset
   121
# ImportError even if fromlist has an unknown item
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30022
diff changeset
   122
# (see Python/import.c:import_module_level() and ensure_fromlist())
1914db1b7d9e demandimport: do not raise ImportError for unknown item in fromlist
Yuya Nishihara <yuya@tcha.org>
parents: 30022
diff changeset
   123
contextlibimp = __import__('contextlib', globals(), locals(), ['unknownattr'])
41505
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   124
assert f(contextlibimp) == "<module 'contextlib' from '?'>", f(contextlibimp)
dffd6a301570 py3: replace print() with assert in test-demandimport.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37964
diff changeset
   125
assert not util.safehasattr(contextlibimp, 'unknownattr')