PageRenderTime 39ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/lib-python/conftest.py

https://bitbucket.org/pypy/pypy/
Python | 681 lines | 661 code | 1 blank | 19 comment | 2 complexity | 6525b65bbd61c5efd2af280808fc6119 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. """
  2. test configuration(s) for running CPython's regression
  3. test suite on top of PyPy
  4. """
  5. import py
  6. import sys
  7. import pypy
  8. import re
  9. from pypy.interpreter.gateway import ApplevelClass
  10. from pypy.interpreter.error import OperationError
  11. from pypy.interpreter.module import Module as PyPyModule
  12. from pypy.interpreter.main import run_string, run_file
  13. # the following adds command line options as a side effect!
  14. from pypy.conftest import option as pypy_option
  15. from pypy.tool.pytest import appsupport
  16. from pypy.tool.pytest.confpath import pypydir, rpythondir, testdir, testresultdir
  17. from rpython.config.parse import parse_info
  18. pytest_plugins = "resultlog",
  19. rsyncdirs = ['.', '../pypy/']
  20. #
  21. # Interfacing/Integrating with py.test's collection process
  22. #
  23. def pytest_addoption(parser):
  24. group = parser.getgroup("complicance testing options")
  25. group.addoption('-T', '--timeout', action="store", type="string",
  26. default="1000", dest="timeout",
  27. help="fail a test module after the given timeout. "
  28. "specify in seconds or 'NUMmp' aka Mega-Pystones")
  29. group.addoption('--pypy', action="store", type="string", dest="pypy",
  30. help="use given pypy executable to run lib-python tests. "
  31. "This will run the tests directly (i.e. not through py.py)")
  32. group.addoption('--filter', action="store", type="string", default=None,
  33. dest="unittest_filter", help="Similar to -k, XXX")
  34. def gettimeout(timeout):
  35. from rpython.translator.test import rpystone
  36. if timeout.endswith('mp'):
  37. megapystone = float(timeout[:-2])
  38. t, stone = pystone.Proc0(10000)
  39. pystonetime = t/stone
  40. seconds = megapystone * 1000000 * pystonetime
  41. return seconds
  42. return float(timeout)
  43. # ________________________________________________________________________
  44. #
  45. # classification of all tests files (this is ongoing work)
  46. #
  47. class RegrTest:
  48. """ Regression Test Declaration."""
  49. def __init__(self, basename, core=False, compiler=None, usemodules='',
  50. skip=None):
  51. self.basename = basename
  52. self._usemodules = usemodules.split() + ['signal', 'time', 'itertools', '_socket']
  53. self._compiler = compiler
  54. self.core = core
  55. self.skip = skip
  56. assert self.getfspath().check(), "%r not found!" % (basename,)
  57. def usemodules(self):
  58. return self._usemodules # + pypy_option.usemodules
  59. usemodules = property(usemodules)
  60. def compiler(self):
  61. return self._compiler # or pypy_option.compiler
  62. compiler = property(compiler)
  63. def ismodified(self):
  64. #XXX: ask hg
  65. return None
  66. def getfspath(self):
  67. return testdir.join(self.basename)
  68. def run_file(self, space):
  69. fspath = self.getfspath()
  70. assert fspath.check()
  71. modname = fspath.purebasename
  72. space.appexec([], '''():
  73. from test import %(modname)s
  74. m = %(modname)s
  75. if hasattr(m, 'test_main'):
  76. m.test_main()
  77. ''' % locals())
  78. testmap = [
  79. RegrTest('test___all__.py', core=True),
  80. RegrTest('test___future__.py', core=True),
  81. RegrTest('test__locale.py', usemodules='_locale'),
  82. RegrTest('test__osx_support.py'),
  83. RegrTest('test_abc.py'),
  84. RegrTest('test_abstract_numbers.py'),
  85. RegrTest('test_aepack.py'),
  86. RegrTest('test_aifc.py'),
  87. RegrTest('test_al.py'),
  88. RegrTest('test_anydbm.py', usemodules='struct'),
  89. RegrTest('test_applesingle.py'),
  90. RegrTest('test_argparse.py', usemodules='binascii'),
  91. RegrTest('test_array.py', core=True, usemodules='struct array binascii'),
  92. RegrTest('test_ascii_formatd.py'),
  93. RegrTest('test_ast.py', core=True, usemodules='struct'),
  94. RegrTest('test_asynchat.py', usemodules='select fcntl'),
  95. RegrTest('test_asyncore.py', usemodules='select fcntl'),
  96. RegrTest('test_atexit.py', core=True),
  97. RegrTest('test_audioop.py'),
  98. RegrTest('test_augassign.py', core=True),
  99. RegrTest('test_base64.py', usemodules='struct'),
  100. RegrTest('test_bastion.py'),
  101. RegrTest('test_bigaddrspace.py'),
  102. RegrTest('test_bigmem.py'),
  103. RegrTest('test_binascii.py', usemodules='binascii'),
  104. RegrTest('test_binhex.py'),
  105. RegrTest('test_binop.py', core=True),
  106. RegrTest('test_bisect.py', core=True, usemodules='_bisect'),
  107. RegrTest('test_bool.py', core=True),
  108. RegrTest('test_bsddb.py'),
  109. RegrTest('test_bsddb185.py'),
  110. RegrTest('test_bsddb3.py'),
  111. RegrTest('test_buffer.py'),
  112. RegrTest('test_bufio.py', core=True),
  113. RegrTest('test_builtin.py', core=True, usemodules='binascii'),
  114. RegrTest('test_bytes.py', usemodules='struct binascii'),
  115. RegrTest('test_bz2.py', usemodules='bz2'),
  116. RegrTest('test_calendar.py'),
  117. RegrTest('test_call.py', core=True),
  118. RegrTest('test_capi.py', usemodules='cpyext'),
  119. RegrTest('test_cd.py'),
  120. RegrTest('test_cfgparser.py'),
  121. RegrTest('test_cgi.py'),
  122. RegrTest('test_charmapcodec.py', core=True),
  123. RegrTest('test_cl.py'),
  124. RegrTest('test_class.py', core=True),
  125. RegrTest('test_cmath.py', core=True),
  126. RegrTest('test_cmd.py'),
  127. RegrTest('test_cmd_line.py'),
  128. RegrTest('test_cmd_line_script.py'),
  129. RegrTest('test_code.py', core=True),
  130. RegrTest('test_codeccallbacks.py', core=True),
  131. RegrTest('test_codecencodings_cn.py', usemodules='_multibytecodec'),
  132. RegrTest('test_codecencodings_hk.py', usemodules='_multibytecodec'),
  133. RegrTest('test_codecencodings_iso2022.py', usemodules='_multibytecodec'),
  134. RegrTest('test_codecencodings_jp.py', usemodules='_multibytecodec'),
  135. RegrTest('test_codecencodings_kr.py', usemodules='_multibytecodec'),
  136. RegrTest('test_codecencodings_tw.py', usemodules='_multibytecodec'),
  137. RegrTest('test_codecmaps_cn.py', usemodules='_multibytecodec'),
  138. RegrTest('test_codecmaps_hk.py', usemodules='_multibytecodec'),
  139. RegrTest('test_codecmaps_jp.py', usemodules='_multibytecodec'),
  140. RegrTest('test_codecmaps_kr.py', usemodules='_multibytecodec'),
  141. RegrTest('test_codecmaps_tw.py', usemodules='_multibytecodec'),
  142. RegrTest('test_codecs.py', core=True, usemodules='_multibytecodec'),
  143. RegrTest('test_codeop.py', core=True),
  144. RegrTest('test_coding.py', core=True),
  145. RegrTest('test_coercion.py', core=True, usemodules='struct'),
  146. RegrTest('test_collections.py', usemodules='binascii struct'),
  147. RegrTest('test_colorsys.py'),
  148. RegrTest('test_commands.py'),
  149. RegrTest('test_compare.py', core=True),
  150. RegrTest('test_compile.py', core=True),
  151. RegrTest('test_compileall.py'),
  152. RegrTest('test_compiler.py', core=False, skip="slowly deprecating compiler"),
  153. RegrTest('test_complex.py', core=True),
  154. RegrTest('test_complex_args.py'),
  155. RegrTest('test_contains.py', core=True),
  156. RegrTest('test_contextlib.py', usemodules="thread"),
  157. RegrTest('test_cookie.py'),
  158. RegrTest('test_cookielib.py'),
  159. RegrTest('test_copy.py', core=True),
  160. RegrTest('test_copy_reg.py', core=True),
  161. RegrTest('test_cpickle.py', core=True),
  162. RegrTest('test_cprofile.py'),
  163. RegrTest('test_crypt.py', usemodules='crypt'),
  164. RegrTest('test_csv.py', usemodules='_csv'),
  165. RegrTest('test_ctypes.py', usemodules="_rawffi thread cpyext"),
  166. RegrTest('test_curses.py'),
  167. RegrTest('test_datetime.py', usemodules='binascii struct'),
  168. RegrTest('test_dbm.py'),
  169. RegrTest('test_decimal.py'),
  170. RegrTest('test_decorators.py', core=True),
  171. RegrTest('test_defaultdict.py', usemodules='_collections'),
  172. RegrTest('test_deque.py', core=True, usemodules='_collections'),
  173. RegrTest('test_descr.py', core=True, usemodules='_weakref'),
  174. RegrTest('test_descrtut.py', core=True),
  175. RegrTest('test_dict.py', core=True),
  176. RegrTest('test_dictcomps.py', core=True),
  177. RegrTest('test_dictviews.py', core=True),
  178. RegrTest('test_difflib.py'),
  179. RegrTest('test_dircache.py', core=True),
  180. RegrTest('test_dis.py'),
  181. RegrTest('test_distutils.py', skip=True),
  182. RegrTest('test_dl.py'),
  183. RegrTest('test_doctest.py', usemodules="thread"),
  184. RegrTest('test_doctest2.py'),
  185. RegrTest('test_docxmlrpc.py'),
  186. RegrTest('test_dumbdbm.py'),
  187. RegrTest('test_dummy_thread.py', core=True),
  188. RegrTest('test_dummy_threading.py', core=True),
  189. RegrTest('test_email.py'),
  190. RegrTest('test_email_codecs.py'),
  191. RegrTest('test_email_renamed.py'),
  192. RegrTest('test_ensurepip.py'),
  193. RegrTest('test_enumerate.py', core=True),
  194. RegrTest('test_eof.py', core=True),
  195. RegrTest('test_epoll.py'),
  196. RegrTest('test_errno.py', usemodules="errno"),
  197. RegrTest('test_exception_variations.py'),
  198. RegrTest('test_exceptions.py', core=True),
  199. RegrTest('test_extcall.py', core=True),
  200. RegrTest('test_fcntl.py', usemodules='fcntl'),
  201. RegrTest('test_file.py', usemodules="posix", core=True),
  202. RegrTest('test_file2k.py', usemodules="posix", core=True),
  203. RegrTest('test_file_eintr.py'),
  204. RegrTest('test_filecmp.py', core=True),
  205. RegrTest('test_fileinput.py', core=True),
  206. RegrTest('test_fileio.py'),
  207. RegrTest('test_float.py', core=True),
  208. RegrTest('test_fnmatch.py', core=True),
  209. RegrTest('test_fork1.py', usemodules="thread"),
  210. RegrTest('test_format.py', core=True),
  211. RegrTest('test_fpformat.py', core=True),
  212. RegrTest('test_fractions.py'),
  213. RegrTest('test_frozen.py', skip="unsupported extension module"),
  214. RegrTest('test_ftplib.py'),
  215. RegrTest('test_funcattrs.py', core=True),
  216. RegrTest('test_functools.py'),
  217. RegrTest('test_future.py', core=True),
  218. RegrTest('test_future1.py', core=True),
  219. RegrTest('test_future2.py', core=True),
  220. RegrTest('test_future3.py', core=True),
  221. RegrTest('test_future4.py', core=True),
  222. RegrTest('test_future5.py', core=True),
  223. RegrTest('test_future_builtins.py'),
  224. RegrTest('test_gc.py', usemodules='_weakref', skip="implementation detail"),
  225. RegrTest('test_gdb.py', skip="not applicable"),
  226. RegrTest('test_gdbm.py'),
  227. RegrTest('test_generators.py', core=True, usemodules='thread _weakref'),
  228. RegrTest('test_genericpath.py'),
  229. RegrTest('test_genexps.py', core=True, usemodules='_weakref'),
  230. RegrTest('test_getargs.py'),
  231. RegrTest('test_getargs2.py', usemodules='binascii', skip=True),
  232. RegrTest('test_getopt.py', core=True),
  233. RegrTest('test_gettext.py'),
  234. RegrTest('test_gl.py'),
  235. RegrTest('test_glob.py', core=True),
  236. RegrTest('test_global.py', core=True),
  237. RegrTest('test_grammar.py', core=True),
  238. RegrTest('test_grp.py'),
  239. RegrTest('test_gzip.py', usemodules='zlib'),
  240. RegrTest('test_hash.py', core=True),
  241. RegrTest('test_hashlib.py', core=True),
  242. RegrTest('test_heapq.py', core=True),
  243. RegrTest('test_hmac.py'),
  244. RegrTest('test_hotshot.py', skip="unsupported extension module"),
  245. RegrTest('test_htmllib.py'),
  246. RegrTest('test_htmlparser.py'),
  247. RegrTest('test_httplib.py'),
  248. RegrTest('test_httpservers.py'),
  249. RegrTest('test_idle.py'),
  250. RegrTest('test_imageop.py'),
  251. RegrTest('test_imaplib.py'),
  252. RegrTest('test_imgfile.py'),
  253. RegrTest('test_imghdr.py'),
  254. RegrTest('test_imp.py', core=True, usemodules='thread'),
  255. RegrTest('test_import.py', core=True),
  256. RegrTest('test_importhooks.py', core=True),
  257. RegrTest('test_importlib.py'),
  258. RegrTest('test_index.py'),
  259. RegrTest('test_inspect.py'),
  260. RegrTest('test_int.py', core=True),
  261. RegrTest('test_int_literal.py', core=True),
  262. RegrTest('test_io.py', usemodules='array binascii'),
  263. RegrTest('test_ioctl.py'),
  264. RegrTest('test_isinstance.py', core=True),
  265. RegrTest('test_iter.py', core=True),
  266. RegrTest('test_iterlen.py', core=True, usemodules="_collections itertools"),
  267. RegrTest('test_itertools.py', core=True, usemodules="itertools struct"),
  268. RegrTest('test_json.py'),
  269. RegrTest('test_kqueue.py'),
  270. RegrTest('test_largefile.py'),
  271. RegrTest('test_lib2to3.py'),
  272. RegrTest('test_linecache.py'),
  273. RegrTest('test_linuxaudiodev.py', skip="unsupported extension module"),
  274. RegrTest('test_list.py', core=True),
  275. RegrTest('test_locale.py', usemodules="_locale"),
  276. RegrTest('test_logging.py', usemodules='thread'),
  277. RegrTest('test_long.py', core=True),
  278. RegrTest('test_long_future.py', core=True),
  279. RegrTest('test_longexp.py', core=True),
  280. RegrTest('test_macos.py'),
  281. RegrTest('test_macostools.py'),
  282. RegrTest('test_macpath.py'),
  283. RegrTest('test_macurl2path.py'),
  284. RegrTest('test_mailbox.py'),
  285. RegrTest('test_marshal.py', core=True),
  286. RegrTest('test_math.py', core=True, usemodules='math'),
  287. RegrTest('test_memoryio.py'),
  288. RegrTest('test_memoryview.py'),
  289. RegrTest('test_md5.py'),
  290. RegrTest('test_mhlib.py', usemodules='binascii struct'),
  291. RegrTest('test_mimetools.py'),
  292. RegrTest('test_mimetypes.py'),
  293. RegrTest('test_MimeWriter.py', core=False, usemodules='binascii'),
  294. RegrTest('test_minidom.py'),
  295. RegrTest('test_mmap.py', usemodules="mmap"),
  296. RegrTest('test_module.py', core=True),
  297. RegrTest('test_modulefinder.py'),
  298. RegrTest('test_msilib.py'),
  299. RegrTest('test_multibytecodec.py', usemodules='_multibytecodec'),
  300. RegrTest('test_multifile.py'),
  301. RegrTest('test_multiprocessing.py'),
  302. RegrTest('test_mutants.py', core="possibly"),
  303. RegrTest('test_mutex.py'),
  304. RegrTest('test_netrc.py'),
  305. RegrTest('test_new.py', core=True),
  306. RegrTest('test_nis.py'),
  307. RegrTest('test_normalization.py'),
  308. RegrTest('test_nntplib.py'),
  309. RegrTest('test_ntpath.py'),
  310. RegrTest('test_old_mailbox.py'),
  311. RegrTest('test_opcodes.py', core=True),
  312. RegrTest('test_openpty.py'),
  313. RegrTest('test_operator.py', core=True),
  314. RegrTest('test_optparse.py'),
  315. RegrTest('test_os.py', core=True),
  316. RegrTest('test_ossaudiodev.py'),
  317. RegrTest('test_parser.py', skip="slowly deprecating compiler"),
  318. RegrTest('test_pdb.py'),
  319. RegrTest('test_peepholer.py'),
  320. RegrTest('test_pep247.py'),
  321. RegrTest('test_pep263.py'),
  322. RegrTest('test_pep277.py'),
  323. RegrTest('test_pep292.py'),
  324. RegrTest('test_pep352.py'),
  325. RegrTest('test_pickle.py', core=True),
  326. RegrTest('test_pickletools.py', core=False),
  327. RegrTest('test_pipes.py'),
  328. RegrTest('test_pkg.py', core=True),
  329. RegrTest('test_pkgimport.py', core=True),
  330. RegrTest('test_pkgutil.py'),
  331. RegrTest('test_platform.py'),
  332. RegrTest('test_plistlib.py'),
  333. RegrTest('test_poll.py'),
  334. RegrTest('test_popen.py'),
  335. RegrTest('test_popen2.py'),
  336. RegrTest('test_poplib.py'),
  337. RegrTest('test_posix.py', usemodules="_rawffi"),
  338. RegrTest('test_posixpath.py'),
  339. RegrTest('test_pow.py', core=True),
  340. RegrTest('test_pprint.py', core=True),
  341. RegrTest('test_print.py', core=True),
  342. RegrTest('test_profile.py'),
  343. RegrTest('test_property.py', core=True),
  344. RegrTest('test_pstats.py'),
  345. RegrTest('test_pty.py', usemodules='fcntl termios select'),
  346. RegrTest('test_pwd.py', usemodules="pwd"),
  347. RegrTest('test_py3kwarn.py'),
  348. RegrTest('test_py_compile.py'),
  349. RegrTest('test_pyclbr.py'),
  350. RegrTest('test_pydoc.py'),
  351. RegrTest('test_pyexpat.py'),
  352. RegrTest('test_queue.py', usemodules='thread'),
  353. RegrTest('test_quopri.py'),
  354. RegrTest('test_random.py'),
  355. RegrTest('test_re.py', core=True),
  356. RegrTest('test_readline.py'),
  357. RegrTest('test_repr.py', core=True),
  358. RegrTest('test_resource.py'),
  359. RegrTest('test_rfc822.py'),
  360. RegrTest('test_richcmp.py', core=True),
  361. RegrTest('test_rlcompleter.py'),
  362. RegrTest('test_robotparser.py'),
  363. RegrTest('test_runpy.py'),
  364. RegrTest('test_sax.py'),
  365. RegrTest('test_scope.py', core=True),
  366. RegrTest('test_scriptpackages.py'),
  367. RegrTest('test_select.py'),
  368. RegrTest('test_set.py', core=True),
  369. RegrTest('test_sets.py'),
  370. RegrTest('test_setcomps.py', core=True),
  371. RegrTest('test_sgmllib.py'),
  372. RegrTest('test_sha.py'),
  373. RegrTest('test_shelve.py'),
  374. RegrTest('test_shlex.py'),
  375. RegrTest('test_shutil.py'),
  376. RegrTest('test_signal.py'),
  377. RegrTest('test_SimpleHTTPServer.py', usemodules='binascii'),
  378. RegrTest('test_site.py', core=False),
  379. RegrTest('test_slice.py', core=True),
  380. RegrTest('test_smtplib.py'),
  381. RegrTest('test_smtpnet.py'),
  382. RegrTest('test_socket.py', usemodules='thread _weakref'),
  383. RegrTest('test_socketserver.py', usemodules='thread'),
  384. RegrTest('test_softspace.py', core=True),
  385. RegrTest('test_sort.py', core=True),
  386. RegrTest('test_spwd.py'),
  387. RegrTest('test_sqlite.py', usemodules="thread _rawffi zlib"),
  388. RegrTest('test_ssl.py', usemodules='_ssl _socket select'),
  389. RegrTest('test_startfile.py'),
  390. RegrTest('test_stat.py'),
  391. RegrTest('test_str.py', core=True),
  392. RegrTest('test_strftime.py'),
  393. RegrTest('test_string.py', core=True),
  394. RegrTest('test_StringIO.py', core=True, usemodules='cStringIO array'),
  395. RegrTest('test_stringprep.py'),
  396. RegrTest('test_strop.py', skip="deprecated"),
  397. RegrTest('test_strptime.py'),
  398. RegrTest('test_strtod.py'),
  399. RegrTest('test_struct.py', usemodules='struct'),
  400. RegrTest('test_structmembers.py', skip="CPython specific"),
  401. RegrTest('test_structseq.py'),
  402. RegrTest('test_subprocess.py', usemodules='signal'),
  403. RegrTest('test_sunau.py'),
  404. RegrTest('test_sunaudiodev.py'),
  405. RegrTest('test_sundry.py'),
  406. RegrTest('test_symtable.py', skip="implementation detail"),
  407. RegrTest('test_syntax.py', core=True),
  408. RegrTest('test_sys.py', core=True, usemodules='struct'),
  409. RegrTest('test_sys_setprofile.py', core=True),
  410. RegrTest('test_sys_settrace.py', core=True),
  411. RegrTest('test_sysconfig.py'),
  412. RegrTest('test_tarfile.py'),
  413. RegrTest('test_tcl.py'),
  414. RegrTest('test_telnetlib.py'),
  415. RegrTest('test_tempfile.py'),
  416. RegrTest('test_textwrap.py'),
  417. RegrTest('test_thread.py', usemodules="thread", core=True),
  418. RegrTest('test_threaded_import.py', usemodules="thread", core=True),
  419. RegrTest('test_threadedtempfile.py',
  420. usemodules="thread", core=False),
  421. RegrTest('test_threading.py', usemodules="thread", core=True),
  422. RegrTest('test_threading_local.py', usemodules="thread", core=True),
  423. RegrTest('test_threadsignals.py', usemodules="thread"),
  424. RegrTest('test_time.py', core=True),
  425. RegrTest('test_timeit.py'),
  426. RegrTest('test_timeout.py'),
  427. RegrTest('test_tk.py'),
  428. RegrTest('test_tokenize.py'),
  429. RegrTest('test_tools.py'),
  430. RegrTest('test_trace.py'),
  431. RegrTest('test_traceback.py', core=True),
  432. RegrTest('test_transformer.py', core=True),
  433. RegrTest('test_ttk_guionly.py'),
  434. RegrTest('test_ttk_textonly.py'),
  435. RegrTest('test_tuple.py', core=True),
  436. RegrTest('test_typechecks.py'),
  437. RegrTest('test_types.py', core=True),
  438. RegrTest('test_ucn.py'),
  439. RegrTest('test_unary.py', core=True),
  440. RegrTest('test_undocumented_details.py'),
  441. RegrTest('test_unicode.py', core=True),
  442. RegrTest('test_unicode_file.py'),
  443. RegrTest('test_unicodedata.py'),
  444. RegrTest('test_unittest.py', core=True),
  445. RegrTest('test_univnewlines.py'),
  446. RegrTest('test_univnewlines2k.py', core=True),
  447. RegrTest('test_unpack.py', core=True),
  448. RegrTest('test_urllib.py'),
  449. RegrTest('test_urllib2.py'),
  450. RegrTest('test_urllib2_localnet.py', usemodules="thread"),
  451. RegrTest('test_urllib2net.py'),
  452. RegrTest('test_urllibnet.py'),
  453. RegrTest('test_urlparse.py'),
  454. RegrTest('test_userdict.py', core=True),
  455. RegrTest('test_userlist.py', core=True),
  456. RegrTest('test_userstring.py', core=True),
  457. RegrTest('test_uu.py'),
  458. RegrTest('test_uuid.py'),
  459. RegrTest('test_wait3.py', usemodules="thread"),
  460. RegrTest('test_wait4.py', usemodules="thread"),
  461. RegrTest('test_warnings.py', core=True),
  462. RegrTest('test_wave.py'),
  463. RegrTest('test_weakref.py', core=True, usemodules='_weakref'),
  464. RegrTest('test_weakset.py'),
  465. RegrTest('test_whichdb.py'),
  466. RegrTest('test_winreg.py'),
  467. RegrTest('test_winsound.py'),
  468. RegrTest('test_with.py'),
  469. RegrTest('test_wsgiref.py'),
  470. RegrTest('test_xdrlib.py'),
  471. RegrTest('test_xml_etree.py'),
  472. RegrTest('test_xml_etree_c.py'),
  473. RegrTest('test_xmllib.py'),
  474. RegrTest('test_xmlrpc.py'),
  475. RegrTest('test_xpickle.py'),
  476. RegrTest('test_xrange.py', core=True),
  477. RegrTest('test_zipfile.py'),
  478. RegrTest('test_zipfile64.py'),
  479. RegrTest('test_zipimport.py', usemodules='zlib zipimport'),
  480. RegrTest('test_zipimport_support.py', usemodules='zlib zipimport'),
  481. RegrTest('test_zlib.py', usemodules='zlib'),
  482. ]
  483. def check_testmap_complete():
  484. listed_names = dict.fromkeys([regrtest.basename for regrtest in testmap])
  485. assert len(listed_names) == len(testmap)
  486. # names to ignore
  487. listed_names['test_support.py'] = True
  488. listed_names['test_multibytecodec_support.py'] = True
  489. missing = []
  490. for path in testdir.listdir(fil='test_*.py'):
  491. name = path.basename
  492. if name not in listed_names:
  493. missing.append(' RegrTest(%r),' % (name,))
  494. missing.sort()
  495. assert not missing, "non-listed tests:\n%s" % ('\n'.join(missing),)
  496. check_testmap_complete()
  497. def pytest_configure(config):
  498. config._basename2spec = cache = {}
  499. for x in testmap:
  500. cache[x.basename] = x
  501. def pytest_collect_file(path, parent, __multicall__):
  502. # don't collect files except through this hook
  503. # implemented by clearing the list of to-be-called
  504. # remaining hook methods
  505. __multicall__.methods[:] = []
  506. regrtest = parent.config._basename2spec.get(path.basename, None)
  507. if regrtest is None:
  508. return
  509. if path.dirpath() != testdir:
  510. return
  511. return RunFileExternal(path.basename, parent=parent, regrtest=regrtest)
  512. class RunFileExternal(py.test.collect.File):
  513. def __init__(self, name, parent, regrtest):
  514. super(RunFileExternal, self).__init__(name, parent)
  515. self.regrtest = regrtest
  516. self.fspath = regrtest.getfspath()
  517. def collect(self):
  518. if self.regrtest.ismodified():
  519. name = 'modified'
  520. else:
  521. name = 'unmodified'
  522. return [ReallyRunFileExternal(name, parent=self)]
  523. #
  524. # testmethod:
  525. # invoking in a separate process: py.py TESTFILE
  526. #
  527. import os
  528. class ReallyRunFileExternal(py.test.collect.Item):
  529. class ExternalFailure(Exception):
  530. """Failure in running subprocess"""
  531. def getinvocation(self, regrtest):
  532. fspath = regrtest.getfspath()
  533. python = sys.executable
  534. pypy_script = pypydir.join('bin', 'pyinteractive.py')
  535. alarm_script = pypydir.join('tool', 'alarm.py')
  536. if sys.platform == 'win32':
  537. watchdog_name = 'watchdog_nt.py'
  538. else:
  539. watchdog_name = 'watchdog.py'
  540. watchdog_script = rpythondir.join('tool', watchdog_name)
  541. regr_script = pypydir.join('tool', 'pytest',
  542. 'run-script', 'regrverbose.py')
  543. regrrun = str(regr_script)
  544. option = self.config.option
  545. TIMEOUT = gettimeout(option.timeout.lower())
  546. if option.pypy:
  547. execpath = py.path.local(option.pypy)
  548. if not execpath.check():
  549. execpath = py.path.local.sysfind(option.pypy)
  550. if not execpath:
  551. raise LookupError("could not find executable %r" % option.pypy)
  552. # check modules
  553. info = py.process.cmdexec("%s --info" % execpath)
  554. info = parse_info(info)
  555. for mod in regrtest.usemodules:
  556. if info.get('objspace.usemodules.%s' % mod) is not True:
  557. py.test.skip("%s module not included in %s" % (mod,
  558. execpath))
  559. cmd = "%s %s %s" % (execpath, regrrun, fspath.purebasename)
  560. # add watchdog for timing out
  561. cmd = "%s %s %s %s" % (python, watchdog_script, TIMEOUT, cmd)
  562. else:
  563. pypy_options = []
  564. pypy_options.extend(
  565. ['--withmod-%s' % mod for mod in regrtest.usemodules])
  566. sopt = " ".join(pypy_options)
  567. cmd = "%s %s %d %s -S %s %s %s -v" % (
  568. python, alarm_script, TIMEOUT,
  569. pypy_script, sopt,
  570. regrrun, fspath.purebasename)
  571. return cmd
  572. def runtest(self):
  573. """ invoke a subprocess running the test file via PyPy.
  574. record its output into the 'result/user@host' subdirectory.
  575. (we might want to create subdirectories for
  576. each user, because we will probably all produce
  577. such result runs and they will not be the same
  578. i am afraid.
  579. """
  580. regrtest = self.parent.regrtest
  581. if regrtest.skip:
  582. if regrtest.skip is True:
  583. msg = "obsolete or unsupported platform"
  584. else:
  585. msg = regrtest.skip
  586. py.test.skip(msg)
  587. (skipped, exit_status, test_stdout, test_stderr) = \
  588. self.getresult(regrtest)
  589. if skipped:
  590. py.test.skip(test_stderr.splitlines()[-1])
  591. if exit_status:
  592. raise self.ExternalFailure(test_stdout, test_stderr)
  593. def repr_failure(self, excinfo):
  594. if not excinfo.errisinstance(self.ExternalFailure):
  595. return super(ReallyRunFileExternal, self).repr_failure(excinfo)
  596. out, err = excinfo.value.args
  597. return out + err
  598. def getstatusouterr(self, cmd):
  599. tempdir = py.test.ensuretemp(self.fspath.basename)
  600. stdout = tempdir.join(self.fspath.basename) + '.out'
  601. stderr = tempdir.join(self.fspath.basename) + '.err'
  602. if sys.platform == 'win32':
  603. status = os.system("%s >%s 2>%s" % (cmd, stdout, stderr))
  604. if status >= 0:
  605. status = status
  606. else:
  607. status = 'abnormal termination 0x%x' % status
  608. else:
  609. if self.config.option.unittest_filter is not None:
  610. cmd += ' --filter %s' % self.config.option.unittest_filter
  611. if self.config.option.usepdb:
  612. cmd += ' --pdb'
  613. if self.config.option.capture == 'no':
  614. status = os.system(cmd)
  615. stdout.write('')
  616. stderr.write('')
  617. else:
  618. status = os.system("%s >>%s 2>>%s" % (cmd, stdout, stderr))
  619. if os.WIFEXITED(status):
  620. status = os.WEXITSTATUS(status)
  621. else:
  622. status = 'abnormal termination 0x%x' % status
  623. return status, stdout.read(mode='rU'), stderr.read(mode='rU')
  624. def getresult(self, regrtest):
  625. cmd = self.getinvocation(regrtest)
  626. tempdir = py.test.ensuretemp(self.fspath.basename)
  627. oldcwd = tempdir.chdir()
  628. exit_status, test_stdout, test_stderr = self.getstatusouterr(cmd)
  629. oldcwd.chdir()
  630. skipped = False
  631. timedout = test_stderr.rfind(26*"=" + "timedout" + 26*"=") != -1
  632. if not timedout:
  633. timedout = test_stderr.rfind("KeyboardInterrupt") != -1
  634. if test_stderr.rfind(26*"=" + "skipped" + 26*"=") != -1:
  635. skipped = True
  636. if not exit_status:
  637. # match "FAIL" but not e.g. "FAILURE", which is in the output of a
  638. # test in test_zipimport_support.py
  639. if re.search(r'\bFAIL\b', test_stdout) or re.search('[^:]ERROR', test_stderr):
  640. exit_status = 2
  641. return skipped, exit_status, test_stdout, test_stderr
  642. def _keywords(self):
  643. lst = list(py.test.collect.Item._keywords(self))
  644. regrtest = self.parent.regrtest
  645. if regrtest.core:
  646. lst.append('core')
  647. return lst