Skip to content

Commit add854f

Browse files
committed
Add basic functional tests
1 parent b308803 commit add854f

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
'scipy == 0.19.1',
2727
],
2828
tests_require=[
29+
'gunicorn',
2930
'pytest >= 2.8.7',
31+
'requests',
3032
],
3133
classifiers=[
3234
'Environment :: Web Environment',

tests/functional/__init__.py

Whitespace-only changes.

tests/functional/test_wsgi_app.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import re
2+
import subprocess
3+
4+
import pytest
5+
import requests
6+
7+
8+
@pytest.fixture(scope='session')
9+
def wsgi_server():
10+
# rough size of the gunicorn startup message, so that we know it has
11+
# actually bound the socket and is ready to accept incoming connections
12+
bufsize = 200
13+
14+
process = subprocess.Popen(['gunicorn', 'xpolyglot.wsgi:app', '-b', 'localhost:0'],
15+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
16+
bufsize=bufsize)
17+
addr = re.search(r'Listening at: (.*) ', process.stderr.read(bufsize).decode('utf-8')).groups()[0]
18+
19+
yield addr
20+
21+
process.terminate()
22+
23+
24+
def test_smoke_predict(wsgi_server):
25+
sample = '''\
26+
#include <stdio.h>
27+
28+
int main()
29+
{
30+
printf("Hello, World!\n");
31+
return 0;
32+
}\n'''
33+
34+
resp = requests.post(wsgi_server + '/predict',
35+
json={'data': sample})
36+
37+
assert resp.status_code == 200
38+
assert resp.headers['content-type'] == 'application/json'
39+
assert resp.json() == {'lang': 'C'}
40+
41+
42+
def test_smoke_supported_languages(wsgi_server):
43+
resp = requests.get(wsgi_server + '/languages')
44+
45+
assert resp.status_code == 200
46+
assert resp.headers['content-type'] == 'application/json'
47+
48+
content = resp.json()
49+
assert isinstance(content, list)
50+
assert len(content) > 0
51+
assert 'Python' in content
52+
assert 'C' in content
53+
assert 'C++' in content
54+
assert 'Haskell' in content
55+
assert 'Rust' in content
56+
assert 'Go' in content
57+
assert 'Clojure' in content
58+
assert 'Java' in content

tox.ini

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
[tox]
22
skipsdist = true
3-
envlist = py36
3+
envlist = py36, functional
44

55
[testenv]
66
usedevelop = true
77
deps =
88
pytest
99
commands =
10-
{envpython} -m pytest tests/unit/ {posargs:.} --strict
10+
{envpython} -m pytest tests/unit/ {posargs} --strict
11+
12+
13+
[testenv:functional]
14+
basepython = python3
15+
deps =
16+
gunicorn
17+
pytest
18+
requests
19+
commands =
20+
{envpython} -m pytest tests/functional/ {posargs} --strict

0 commit comments

Comments
 (0)