kuroko/test/testPackageImports.krk

64 lines
1.2 KiB
Python
Raw Normal View History

def printPackage(p):
let s = repr(p)
let a,b,c,d = s.split(' ')
print(' '.join([a,b,c]),'...>')
2021-01-17 16:01:58 +03:00
def testTop():
import foo
printPackage(foo)
2021-01-17 16:01:58 +03:00
try:
print(foo.bar, "Fail")
except:
print(repr(exception)) # AttributeError
def testCaching():
from foo.bar import baz
printPackage(baz)
2021-01-17 16:01:58 +03:00
import foo
printPackage(foo)
printPackage(foo.bar)
printPackage(foo.bar.baz)
2021-01-17 16:01:58 +03:00
print(foo.bar.baz.qux)
def testDirect():
import foo.bar.baz
printPackage(foo)
printPackage(foo.bar)
printPackage(foo.bar.baz)
2021-01-17 16:01:58 +03:00
print(foo.bar.baz.qux)
def testFromImport():
from foo.bar import baz
printPackage(baz)
2021-01-17 16:01:58 +03:00
print(baz.qux)
try:
print(foo, "Fail")
except:
print(repr(exception))
def testRenames():
import foo.bar.baz as blah
printPackage(blah)
2021-01-17 16:01:58 +03:00
print(blah.qux)
try:
print(foo, "Fail")
except:
print(repr(exception))
from foo.bar.baz import qux as thing
print(thing)
try:
print(qux, "Fail")
except:
print(repr(exception))
try:
print(foo.bar, "Fail")
except:
print(repr(exception))
if __name__ == '__main__':
testTop()
testCaching()
testDirect()
testFromImport()
testRenames()