File: module_getattr.py

package info (click to toggle)
micropython 1.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 48,944 kB
  • sloc: ansic: 317,850; python: 59,539; xml: 4,241; makefile: 3,530; sh: 1,421; javascript: 744; asm: 681; cpp: 45; exp: 11; pascal: 6
file content (25 lines) | stat: -rw-r--r-- 541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# test __getattr__ on module

# ensure that does_not_exist doesn't exist to start with
this = __import__(__name__)
try:
    this.does_not_exist
    assert False
except AttributeError:
    pass


# define __getattr__
def __getattr__(attr):
    if attr == "does_not_exist":
        return False
    raise AttributeError


# do feature test (will also test functionality if the feature exists)
if not hasattr(this, "does_not_exist"):
    print("SKIP")
    raise SystemExit

# check that __getattr__ works as expected
print(this.does_not_exist)