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:
52
test/test_examples.py
Normal file
52
test/test_examples.py
Normal 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)
|
||||
Reference in New Issue
Block a user