Mercurial > hg
diff tests/test-demandimport.py @ 30022:26a4e46af2bc
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 26 Sep 2016 23:28:57 +0900 |
parents | 129e38a76f2c |
children | 1914db1b7d9e |
line wrap: on
line diff
--- a/tests/test-demandimport.py Tue Sep 27 21:56:00 2016 +0900 +++ b/tests/test-demandimport.py Mon Sep 26 23:28:57 2016 +0900 @@ -63,6 +63,15 @@ print("re.stderr =", f(re.stderr)) print("re =", f(re)) +import contextlib +print("contextlib =", f(contextlib)) +try: + from contextlib import unknownattr + print('no demandmod should be created for attribute of non-package ' + 'module:\ncontextlib.unknownattr =', f(unknownattr)) +except ImportError as inst: + print('contextlib.unknownattr = ImportError: %s' % inst) + demandimport.disable() os.environ['HGDEMANDIMPORT'] = 'disable' # this enable call should not actually enable demandimport!