300_import.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  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. from test2.utils import r
  24. assert r.__name__ == 'r'
  25. assert r.__package__ == 'test2.utils'
  26. assert r.__path__ == 'test2.utils.r'
  27. def f():
  28. import math as m
  29. assert m.pi > 3
  30. from test3.a.b import value
  31. assert value == 1
  32. f()
  33. from math import *
  34. assert pi > 3
  35. from math import (pi, pow, sin, cos)
  36. from math import (
  37. pi,
  38. pow,
  39. sin,
  40. cos
  41. )
  42. assert __import__('math').pi > 3
  43. # test reload (dummy)
  44. if not is_pyc:
  45. import importlib
  46. importlib.reload(test2.a)