PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/basics/run_all.py

https://bitbucket.org/pombredanne/nuitka
Python | 148 lines | 103 code | 23 blank | 22 comment | 29 complexity | 8e120f22f26dfa8902ba75e02d629f7d MD5 | raw file
  1. #!/usr/bin/env python
  2. # Copyright 2013, Kay Hayen, mailto:kay.hayen@gmail.com
  3. #
  4. # Python tests originally created or extracted from other peoples work. The
  5. # parts were too small to be protected.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. from __future__ import print_function
  20. import os, sys, subprocess, tempfile, shutil
  21. # Go its own directory, to have it easy with path knowledge.
  22. os.chdir( os.path.dirname( os.path.abspath( __file__ ) ) )
  23. search_mode = len( sys.argv ) > 1 and sys.argv[1] == "search"
  24. start_at = sys.argv[2] if len( sys.argv ) > 2 else None
  25. if start_at:
  26. active = False
  27. else:
  28. active = True
  29. if "PYTHON" not in os.environ:
  30. os.environ[ "PYTHON" ] = "python" if os.name != "nt" else sys.executable
  31. if "PYTHONIOENCODING" not in os.environ:
  32. os.environ[ "PYTHONIOENCODING" ] = "utf-8"
  33. def check_output(*popenargs, **kwargs):
  34. from subprocess import Popen, PIPE, CalledProcessError
  35. if 'stdout' in kwargs:
  36. raise ValueError('stdout argument not allowed, it will be overridden.')
  37. process = Popen(stdout=PIPE, *popenargs, **kwargs)
  38. output, unused_err = process.communicate()
  39. retcode = process.poll()
  40. if retcode:
  41. cmd = kwargs.get("args")
  42. if cmd is None:
  43. cmd = popenargs[0]
  44. raise CalledProcessError(retcode, cmd, output=output)
  45. return output
  46. version_output = check_output(
  47. [ os.environ[ "PYTHON" ], "--version" ],
  48. stderr = subprocess.STDOUT
  49. )
  50. python_version = version_output.split()[1]
  51. os.environ[ "PYTHONPATH" ] = os.getcwd()
  52. print( "Using concrete python", python_version )
  53. for filename in sorted( os.listdir( "." ) ):
  54. if not filename.endswith( ".py" ) or filename.startswith( "run_" ):
  55. continue
  56. # Skip tests that require Python 2.7 at least.
  57. if filename.endswith( "27.py" ) and python_version.startswith( b"2.6" ):
  58. continue
  59. # Skip tests that require Python 3.2 at least.
  60. if filename.endswith( "32.py" ) and not python_version.startswith( b"3" ):
  61. continue
  62. # The overflow functions test gives syntax error on Python 3.x and can be ignored.
  63. if filename == "OverflowFunctions.py" and python_version.startswith( b"3" ):
  64. continue
  65. path = filename
  66. if not active and start_at in ( filename, path ):
  67. active = True
  68. extra_flags = [ "expect_success", "remove_output" ]
  69. if active:
  70. if filename in ( "Referencing.py", "Referencing32.py" ):
  71. debug_python = os.environ[ "PYTHON" ]
  72. if not debug_python.endswith( "-dbg" ):
  73. debug_python += "-dbg"
  74. if os.name == "nt" or "--windows-target" in os.environ.get( "NUITKA_EXTRA_OPTIONS", "" ):
  75. print( "Skip reference count test, CPython debug not on Windows." )
  76. continue
  77. if not os.path.exists( os.path.join( "/usr/bin", debug_python ) ):
  78. print( "Skip reference count test, CPython debug version not found." )
  79. continue
  80. extra_flags.append( "ignore_stderr" )
  81. extra_flags.append( "python_debug" )
  82. # Apply 2to3 conversion if necessary.
  83. assert type( python_version ) is bytes
  84. if python_version.startswith( b"3" ) and not filename.endswith( "32.py" ):
  85. new_path = os.path.join( tempfile.gettempdir(), filename )
  86. shutil.copy( path, new_path )
  87. path = new_path
  88. # No idea how to make this portable to Windows, but we can delay it until
  89. # Python3 is fully functional under Linux first.
  90. result = subprocess.call(
  91. "2to3 -w -n --no-diffs " + path,
  92. stderr = open( "/dev/null", "w" ),
  93. shell = True
  94. )
  95. command = "%s %s %s silent %s" % (
  96. sys.executable,
  97. os.path.join( "..", "..", "bin", "compare_with_cpython" ),
  98. path,
  99. " ".join( extra_flags )
  100. )
  101. result = subprocess.call(
  102. command,
  103. shell = True
  104. )
  105. if result == 2:
  106. sys.stderr.write( "Interruped, with CTRL-C\n" )
  107. sys.exit( 2 )
  108. if result != 0 and search_mode:
  109. print("Error exit!", result)
  110. sys.exit( result )
  111. if python_version.startswith( b"3" ) and not filename.endswith( "32.py" ):
  112. os.unlink( new_path )
  113. else:
  114. print("Skipping", filename)