300_import.py 1.0 KB

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