PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/greentest/patched_tests_setup.py

https://code.google.com/p/gevent/
Python | 92 lines | 69 code | 8 blank | 15 comment | 5 complexity | ccfbfc91de8209718cf2e53be76456c4 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. import sys
  2. import re
  3. # By default, test cases are expected to switch and emit warnings if there was none
  4. # If a test is found in this list, it's expected not to switch.
  5. tests = '''test_select.SelectTestCase.test_error_conditions
  6. test_ftplib.TestFTPClass.test_all_errors
  7. test_ftplib.TestFTPClass.test_getwelcome
  8. test_ftplib.TestFTPClass.test_sanitize
  9. test_ftplib.TestFTPClass.test_set_pasv
  10. test_ftplib.TestIPv6Environment.test_af
  11. test_socket.TestExceptions.testExceptionTree
  12. test_socket.Urllib2FileobjectTest.testClose
  13. test_socket.TestLinuxAbstractNamespace.testLinuxAbstractNamespace
  14. test_socket.TestLinuxAbstractNamespace.testMaxName
  15. test_socket.TestLinuxAbstractNamespace.testNameOverflow
  16. test_socket.GeneralModuleTests.*
  17. '''
  18. tests = [x.strip().replace('\.', '\\.').replace('*', '.*?') for x in tests.split('\n') if x.strip()]
  19. tests = re.compile('^%s$' % '|'.join(tests))
  20. def get_switch_expected(fullname):
  21. """
  22. >>> get_switch_expected('test_select.SelectTestCase.test_error_conditions')
  23. False
  24. >>> get_switch_expected('test_socket.GeneralModuleTests.testCrucialConstants')
  25. False
  26. >>> get_switch_expected('test_socket.SomeOtherTest.testHello')
  27. True
  28. """
  29. if tests.match(fullname) is not None:
  30. print (fullname)
  31. return False
  32. return True
  33. disabled_tests = \
  34. [ 'test_threading.ThreadTests.test_PyThreadState_SetAsyncExc'
  35. # uses some internal C API of threads not available when threads are emulated with greenlets
  36. , 'test_urllib2net.TimeoutTest.test_ftp_no_timeout'
  37. , 'test_urllib2net.TimeoutTest.test_ftp_timeout'
  38. , 'test_urllib2net.TimeoutTest.test_http_no_timeout'
  39. , 'test_urllib2net.TimeoutTest.test_http_timeout'
  40. # access _sock.gettimeout() which is always in non-blocking mode
  41. , 'test_socket.UDPTimeoutTest.testUDPTimeout'
  42. # has a bug which makes it fail with error: (107, 'Transport endpoint is not connected')
  43. # (it creates a TCP socket, not UDP)
  44. , 'test_socket.GeneralModuleTests.testRefCountGetNameInfo'
  45. # fails with "socket.getnameinfo loses a reference" while the reference is only "lost"
  46. # because it is referenced by the traceback - any Python function would lose a reference like that.
  47. # the original getnameinfo does not lose it because it's in C.
  48. , 'test_socket.NetworkConnectionNoServer.test_create_connection_timeout'
  49. # replaces socket.socket with MockSocket and then calls create_connection.
  50. # this unfortunately does not work with monkey patching, because gevent.socket.create_connection
  51. # is bound to gevent.socket.socket and updating socket.socket does not affect it.
  52. # this issues also manifests itself when not monkey patching DNS: http://code.google.com/p/gevent/issues/detail?id=54
  53. # create_connection still uses gevent.socket.getaddrinfo while it should be using socket.getaddrinfo
  54. , 'test_asyncore.BaseTestAPI.test_handle_expt'
  55. # sends some OOB data and expect it to be detected as such; gevent.select.select does not support that
  56. , 'test_signal.WakeupSignalTests.test_wakeup_fd_early'
  57. # expects time.sleep() to return prematurely in case of a signal;
  58. # gevent.sleep() is better than that and does not get interrupted (unless signal handler raises an error)
  59. , 'test_signal.WakeupSignalTests.test_wakeup_fd_during'
  60. # expects select.select() to raise select.error(EINTR, 'interrupted system call')
  61. # gevent.select.select() does not get interrupted (unless signal handler raises an error)
  62. # maybe it should?
  63. ]
  64. if sys.version_info[:2] < (2, 7):
  65. # On Python 2.6, this test fails even without monkey patching
  66. disabled_tests.append('test_threading.ThreadTests.test_foreign_thread')
  67. def disable_tests_in_source(source, name):
  68. my_disabled_tests = [x for x in disabled_tests if x.startswith(name + '.')]
  69. if not my_disabled_tests:
  70. return source
  71. for test in my_disabled_tests:
  72. # XXX ignoring TestCase class name
  73. testcase = test.split('.')[-1]
  74. source, n = re.subn(testcase, 'XXX' + testcase, source)
  75. print >> sys.stderr, 'Removed %s (%d)' % (testcase, n)
  76. return source