Commit Graph

16 Commits

Author SHA1 Message Date
Augie Fackler
f804840943 tests: ensure demandimport test uses absolute_import 2017-08-22 15:50:53 -04:00
Yuya Nishihara
07ba7d360b demandimport: stop overriding __getattribute__()
Proxy __dict__ and __doc__ explicitly instead.

I'm not sure which is less evil, but this seems slightly simpler than hooking
all attribute accesses.
2017-04-28 00:01:22 +09:00
Yuya Nishihara
7cd4cd9753 demandimport: look for 'mod' suffix as alternative name for module reference
It's widely used in our codebase.
2017-04-28 23:46:16 +09:00
Yuya Nishihara
3379250232 demandimport: do not raise ImportError for unknown item in fromlist
This is the behavior of the default __import__() function, which doesn't
validate the existence of the fromlist items. Later on, the missing attribute
is detected while processing the import statement.

https://hg.python.org/cpython/file/v2.7.13/Python/import.c#l2575

The comtypes library relies on this (maybe) undocumented behavior, and we
got a bug report to TortoiseHg, sigh.

https://bitbucket.org/tortoisehg/thg/issues/4647/

The test added at 0be19b069edf verifies the behavior of the import statement,
so this patch only adds the test of __import__() function and works around
CPython/PyPy difference.
2016-12-19 22:46:00 +09:00
Yuya Nishihara
09cf7ebffd demandimport: error out early on missing attribute of non package (issue5373)
If the parent module isn't a package, all valid attributes must be obtained
from it. We can raise ImportError early if any attributes not found.
2016-09-26 23:28:57 +09:00
timeless
837067a341 tests: clarify demandimport disabled state 2016-09-21 03:39:37 +00:00
timeless
5e52f93083 tests: skip demandimport if disabled
demandimport and setuptools and decorator (from ironpython) and
pygments leads to lots of fail.

If demandimport is disabled we should skip testing it...
2016-08-25 22:03:51 +00:00
Pulkit Goyal
bc1d2102b1 py3: make test-demandimport use print_function
Replacing print statements with print function.
2016-04-16 12:41:58 +05:30
Bryan O'Sullivan
3002054ec0 test-demandimport: ensure that relative imports are deferred
This adds a test not just at our local "top level" (the mercurial
package), but also one level deeper (mercurial.hgweb).
2015-12-23 16:22:20 -08:00
Augie Fackler
ffd2cf1dba demandimport: blacklist distutils.msvc9compiler (issue4475)
This module depends on _winreg, which is windows-only. Recent versions
of setuptools load distutils.msvc9compiler and expect it to
ImportError immediately when on non-Windows platforms, so we need to
let them do that. This breaks in an especially mystifying way, because
setuptools uses vars() on the imported module. We then throw an
exception, which vars doesn't pick up on well. For example:

In [3]: class wat(object):
   ...:     @property
   ...:     def __dict__(self):
   ...:         assert False
   ...:

In [4]: vars(wat())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-2781ada5ffe6> in <module>()
----> 1 vars(wat())

TypeError: vars() argument must have __dict__ attribute

Which is similar to the problem we run into.
2014-12-22 17:27:31 -05:00
Mads Kiilerich
2572d4c880 demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
Convenient for debugging weird problems that are caused by demandimport or
obfuscated by it.

This is an undocumented developer feature.
2014-04-08 01:35:13 +02:00
Dan Villiom Podlaski Christiansen
165e2565b2 test-demandimport.py: PyPy support
The stringification of sys.stderr is different in PyPy:

$ pypy -c 'import sys; print sys.stderr'
<open file '<fdopen>', mode 'w' at 0x00a42080>

$ python -c 'import sys; print sys.stderr'
<open file '<stderr>', mode 'w' at 0x10025a270>

The test will now ignore the exact value between the angle brackets.
2010-12-01 21:46:08 +01:00
Dan Villiom Podlaski Christiansen
f385faac7a *: kill all unnecessary shebangs. 2010-10-26 12:18:39 +02:00
James Abbatiello
493895e163 Fix test-demandimport and test-trusted under Windows
The Windows-only wrapper around stdout is causing both of these tests to fail.
test-demandimport fails because it tries to print repr(sys.stdout).  Use
stderr instead since that is not wrapped.

test-trusted fails because the wrapper doesn't handle softspace and an
unexpected extra space gets printed.
2009-07-14 22:38:12 -04:00
Martin Geisler
aedc0ac57f tests: removed unnecessary execute bit on Python tests 2009-05-17 01:42:21 +02:00
Martin Geisler
a645da9ed1 tests: renamed Python tests to .py 2009-05-17 01:39:31 +02:00