300_import.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. print('sandbox mode, module is disabled')
  2. exit()
  3. try:
  4. import os
  5. except ImportError:
  6. exit(0)
  7. import sys
  8. is_pyc = sys.argv[0].endswith('.pyc')
  9. if is_pyc:
  10. os.chdir('tmp/tests')
  11. else:
  12. os.chdir('tests')
  13. assert os.getcwd().endswith('tests')
  14. import test1
  15. assert test1.add(1, 2) == 13
  16. from test2.a.g import get_value, A
  17. assert get_value() == '123'
  18. assert (A.__module__ == 'test2.a.g'), A.__module__
  19. import test2.a.g
  20. assert test2.a.g.get_value() == '123'
  21. from test2.utils import get_value_2
  22. assert get_value_2() == '123'
  23. from test3.a.b import value
  24. assert value == 1
  25. import test3.a.b as test3_ab
  26. assert test3_ab.value == 1
  27. from test2.utils import r
  28. assert r.__name__ == 'test2.utils.r'
  29. assert r.__package__ == 'test2.utils'
  30. def f():
  31. import math as m
  32. assert m.pi > 3
  33. from test3.a.b import value
  34. assert value == 1
  35. f()
  36. from math import *
  37. assert pi > 3
  38. from math import (pi, pow, sin, cos)
  39. from math import (
  40. pi,
  41. pow,
  42. sin,
  43. cos
  44. )
  45. assert __import__('math').pi > 3
  46. # test reload (dummy)
  47. if not is_pyc:
  48. import importlib
  49. importlib.reload(test2.a)