Skip to content

Commit

Permalink
Split the remaining example tests into their own files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Apr 29, 2019
1 parent a9b61d6 commit e614a82
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 83 deletions.
6 changes: 2 additions & 4 deletions src/gevent/testing/testrunner.py
Expand Up @@ -522,11 +522,9 @@ def main():
options = parser.parse_args()
# options.use will be either None for not given, or a list
# of the last specified -u argument.
if options.use is None:
# The default, which we'll take from the environment, if set.
options.use = parse_resources()
# If not given, use the default, which we'll take from the environment, if set.
options.use = list(set(parse_resources() if options.use is None else options.use))

options.use = list(set(options.use))
# Whether or not it came from the environment, put it in the
# environment now.
os.environ['GEVENTTEST_USE_RESOURCES'] = unparse_resources(options.use)
Expand Down
10 changes: 6 additions & 4 deletions src/gevent/tests/known_failures.py
Expand Up @@ -39,9 +39,6 @@
# other Windows-related issues (need investigating)
FAILING_TESTS += [
'FLAKY test__greenletset.py',
# This has been seen to fail on Py3 and Py2 due to socket reuse
# errors, probably timing related again.
'FLAKY test___example_servers.py',
]

if APPVEYOR:
Expand Down Expand Up @@ -344,9 +341,14 @@


# tests that don't do well when run on busy box
# or that are mutually exclusive
RUN_ALONE = [
'test__threadpool.py',
'test__examples.py',
# These share the same port, which means they can conflict
# between concurrent test runs too
# XXX: Fix this by dynamically picking a port.
'test__example_wsgiserver.py',
'test__example_webproxy.py',
]


Expand Down
2 changes: 1 addition & 1 deletion src/gevent/tests/test__example_portforwarder.py
@@ -1,7 +1,7 @@
from __future__ import print_function, absolute_import
from gevent import monkey; monkey.patch_all(subprocess=True)
import signal
import sys

import socket
from time import sleep

Expand Down
29 changes: 29 additions & 0 deletions src/gevent/tests/test__example_webproxy.py
@@ -0,0 +1,29 @@
from unittest import SkipTest


import gevent.testing as greentest

from . import test__example_wsgiserver


@greentest.skipOnCI("Timing issues sometimes lead to a connection refused")
@greentest.skipWithoutExternalNetwork("Tries to reach google.com")
class Test_webproxy(test__example_wsgiserver.Test_wsgiserver):
server = 'webproxy.py'

def _run_all_tests(self):
status, data = self.read('/')
self.assertEqual(status, '200 OK')
self.assertIn(b"gevent example", data)
status, data = self.read('/http://www.google.com')
self.assertEqual(status, '200 OK')
self.assertIn(b'google', data.lower())

def test_a_blocking_client(self):
# Not applicable
raise SkipTest("Not applicable")



if __name__ == '__main__':
greentest.main()
Expand Up @@ -4,7 +4,7 @@
from urllib import request as urllib2
except ImportError:
import urllib2
from unittest import SkipTest


import socket
import ssl
Expand Down Expand Up @@ -89,54 +89,5 @@ def _do_test_a_blocking_client(self):
def test_a_blocking_client(self):
self._do_test_a_blocking_client()

@greentest.skipOnCI("Timing issues sometimes lead to a connection refused")
class Test_wsgiserver_ssl(Test_wsgiserver):
server = 'wsgiserver_ssl.py'
URL = 'https://%s:8443' % (params.DEFAULT_LOCAL_HOST_ADDR,)
PORT = 8443
_use_ssl = True

if hasattr(ssl, '_create_unverified_context'):
# Disable verification for our self-signed cert
# on Python >= 2.7.9 and 3.4
ssl_ctx = ssl._create_unverified_context()


@greentest.skipOnCI("Timing issues sometimes lead to a connection refused")
@greentest.skipWithoutExternalNetwork("Tries to reach google.com")
class Test_webproxy(Test_wsgiserver):
server = 'webproxy.py'

def _run_all_tests(self):
status, data = self.read('/')
self.assertEqual(status, '200 OK')
self.assertIn(b"gevent example", data)
status, data = self.read('/http://www.google.com')
self.assertEqual(status, '200 OK')
self.assertIn(b'google', data.lower())

def test_a_blocking_client(self):
# Not applicable
raise SkipTest("Not applicable")


# class Test_webpy(Test_wsgiserver):
# server = 'webpy.py'
# not_found_message = 'not found'
#
# def _test_hello(self):
# status, data = self.read('/')
# self.assertEqual(status, '200 OK')
# assert "Hello, world" in data, repr(data)
#
# def _test_long(self):
# start = time.time()
# status, data = self.read('/long')
# delay = time.time() - start
# assert 10 - 0.5 < delay < 10 + 0.5, delay
# self.assertEqual(status, '200 OK')
# self.assertEqual(data, 'Hello, 10 seconds later')


if __name__ == '__main__':
greentest.main()
24 changes: 24 additions & 0 deletions src/gevent/tests/test__example_wsgiserver_ssl.py
@@ -0,0 +1,24 @@
import ssl

import gevent.testing as greentest

from gevent.testing import params

from . import test__example_wsgiserver


@greentest.skipOnCI("Timing issues sometimes lead to a connection refused")
class Test_wsgiserver_ssl(test__example_wsgiserver.Test_wsgiserver):
server = 'wsgiserver_ssl.py'
URL = 'https://%s:8443' % (params.DEFAULT_LOCAL_HOST_ADDR,)
PORT = 8443
_use_ssl = True

if hasattr(ssl, '_create_unverified_context'):
# Disable verification for our self-signed cert
# on Python >= 2.7.9 and 3.4
ssl_ctx = ssl._create_unverified_context()


if __name__ == '__main__':
greentest.main()
10 changes: 1 addition & 9 deletions src/gevent/tests/test__examples.py
Expand Up @@ -27,19 +27,11 @@ def _find_files_to_ignore():
try:
os.chdir(this_dir)

# These three are all tested with test___example_servers.
# TODO: Refactor those to regular test__example_*foo* files.
result = [
'wsgiserver.py',
'wsgiserver_ssl.py',
'webproxy.py',
]
result = [x[14:] for x in glob.glob('test__example_*.py')]
if greentest.PYPY and greentest.RUNNING_ON_APPVEYOR:
# For some reason on Windows with PyPy, this times out,
# when it should be very fast.
result.append("processes.py")
result += [x[14:] for x in glob.glob('test__example_*.py')]

finally:
os.chdir(old_dir)

Expand Down
30 changes: 16 additions & 14 deletions src/gevent/tests/tests_that_dont_monkeypatch.txt
@@ -1,9 +1,23 @@
test___example_servers.py
test___config.py
test___ident.py
test___monitor.py
test__ares_timeout.py
test__backdoor.py
test__close_backend_fd.py
test__events.py
test__example_echoserver.py
test__example_portforwarder.py
test__example_udp_client.py
test__example_wsgiserver.py
test__example_wsgiserver_ssl.py
test__example_webproxy.py
test__examples.py
test__getaddrinfo_import.py
test__example_portforwarder.py
test__hub_join.py
test__hub_join_timeout.py
test__issue330.py
test__iwait.py
test__monkey_scope.py
test__pywsgi.py
test__server.py
test__server_pywsgi.py
Expand All @@ -12,15 +26,3 @@ test__socket_dns6.py
test__socket_errors.py
test__socket_send_memoryview.py
test__socket_timeout.py
test__examples.py
test__issue330.py
test___ident.py
test___config.py
test___monitor.py
test__events.py
test__monkey_scope.py
test__iwait.py
test__ares_timeout.py
test__close_backend_fd.py
test__hub_join.py
test__hub_join_timeout.py
2 changes: 1 addition & 1 deletion src/gevent/tests/tests_that_dont_use_resolver.txt
Expand Up @@ -18,7 +18,7 @@ test__environ.py
test__event.py
# uses socket test__example_echoserver.py
# uses socket test__example_portforwarder.py
# uses socket test___example_servers.py
# uses socket test__example_w*.py
# uses bunch of things test__examples.py
# uses socket test__example_udp_client.py
# uses socket test__example_udp_server.py
Expand Down

0 comments on commit e614a82

Please sign in to comment.