circuitpython/tests/basics/builtin_dir.py
stijn 40ad8f1666 all: Rename "sys" module to "usys".
This is consistent with the other 'micro' modules and allows implementing
additional features in Python via e.g. micropython-lib's sys.

Note this is a breaking change (not backwards compatible) for ports which
do not enable weak links, as "import sys" must now be replaced with
"import usys".
2020-09-04 00:10:24 +10:00

42 lines
685 B
Python

# test builtin dir
# dir of locals
print('__name__' in dir())
# dir of module
try:
import usys as sys
except ImportError:
import sys
print('version' in dir(sys))
# dir of type
print('append' in dir(list))
class Foo:
def __init__(self):
self.x = 1
foo = Foo()
print('__init__' in dir(foo))
print('x' in dir(foo))
# dir of subclass
class A:
def a():
pass
class B(A):
def b():
pass
d = dir(B())
print(d.count('a'), d.count('b'))
# dir of class with multiple bases and a common parent
class C(A):
def c():
pass
class D(B, C):
def d():
pass
d = dir(D())
print(d.count('a'), d.count('b'), d.count('c'), d.count('d'))