diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-11-24 17:26:47 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-11-24 17:49:36 -0500 |
commit | 47d1659826e53d09b86eba8b418dc684050659ca (patch) | |
tree | 246f65318c13a27c4e0bd8c080122baa26260f76 /tests/modules | |
parent | 4dae569d7ccafd6e6fcdc3c2f6bcca09a6611ac0 (diff) | |
download | python-coveragepy-git-47d1659826e53d09b86eba8b418dc684050659ca.tar.gz |
Implement __spec__ for files we run. #745 #838
Diffstat (limited to 'tests/modules')
-rw-r--r-- | tests/modules/process_test/try_execfile.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/modules/process_test/try_execfile.py b/tests/modules/process_test/try_execfile.py index 706fe39f..48f9d098 100644 --- a/tests/modules/process_test/try_execfile.py +++ b/tests/modules/process_test/try_execfile.py @@ -66,7 +66,7 @@ def my_function(a): FN_VAL = my_function("fooey") loader = globals().get('__loader__') -fullname = getattr(loader, 'fullname', None) or getattr(loader, 'name', None) +spec = globals().get('__spec__') # A more compact ad-hoc grouped-by-first-letter list of builtins. CLUMPS = "ABC,DEF,GHI,JKLMN,OPQR,ST,U,VWXYZ_,ab,cd,efg,hij,lmno,pqr,stuvwxyz".split(",") @@ -88,8 +88,8 @@ globals_to_check = { '__builtins__.has_open': hasattr(__builtins__, 'open'), '__builtins__.dir': builtin_dir, '__loader__ exists': loader is not None, - '__loader__.fullname': fullname, '__package__': __package__, + '__spec__ exists': spec is not None, 'DATA': DATA, 'FN_VAL': FN_VAL, '__main__.DATA': getattr(__main__, "DATA", "nothing"), @@ -98,4 +98,15 @@ globals_to_check = { 'path': cleaned_sys_path, } +if loader is not None: + globals_to_check.update({ + '__loader__.fullname': getattr(loader, 'fullname', None) or getattr(loader, 'name', None) + }) + +if spec is not None: + globals_to_check.update({ + '__spec__.' + aname: getattr(spec, aname) + for aname in ['name', 'origin', 'submodule_search_locations', 'parent', 'has_location'] + }) + print(json.dumps(globals_to_check, indent=4, sort_keys=True)) |