Adding examples as pytest tests

- This way they will be included in CI checks
- Decreased the delay time in the thread-like examples to speed up tests
(probably could decrease the time some more)
- Added an async version of the calculator test
- Forcing python3 support for example scripts
This commit is contained in:
Jacob Alexander
2019-09-27 14:40:54 -07:00
parent 58a5c5fc1f
commit 78776de647
12 changed files with 596 additions and 13 deletions

52
test/test_examples.py Normal file
View File

@@ -0,0 +1,52 @@
import gc
import os
import socket
import subprocess
import sys # add examples dir to sys.path
import time
examples_dir = os.path.join(os.path.dirname(__file__), '..', 'examples')
def run_subprocesses(address, server, client):
server = subprocess.Popen([os.path.join(examples_dir, server), address])
time.sleep(1) # Give the server some small amount of time to start listening
client = subprocess.Popen([os.path.join(examples_dir, client), address])
ret = client.wait()
server.kill()
assert ret == 0
def test_async_calculator_example():
address = 'localhost:36432'
server = 'async_calculator_server.py'
client = 'async_calculator_client.py'
run_subprocesses(address, server, client)
def test_thread_example():
address = 'localhost:36433'
server = 'thread_server.py'
client = 'thread_client.py'
run_subprocesses(address, server, client)
def test_addressbook_example():
proc = subprocess.Popen([os.path.join(examples_dir, 'addressbook.py')])
ret = proc.wait()
assert ret == 0
def test_async_example():
address = 'localhost:36434'
server = 'async_server.py'
client = 'async_client.py'
run_subprocesses(address, server, client)
def test_ssl_async_example():
address = 'localhost:36435'
server = 'async_ssl_server.py'
client = 'async_ssl_client.py'
run_subprocesses(address, server, client)