Add tests for pmxbot command (and Result.results).
This commit is contained in:
parent
2c2ba47879
commit
c66dc29876
30
conftest.py
30
conftest.py
|
@ -1,4 +1,32 @@
|
||||||
|
import os
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import wolframalpha
|
||||||
|
|
||||||
|
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
collect_ignore = ['wolframalpha/pmxbot.py']
|
collect_ignore = [
|
||||||
|
'wolframalpha/pmxbot.py',
|
||||||
|
'wolframalpha/test_pmxbot.py',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def API_key():
|
||||||
|
"""
|
||||||
|
To run the tests fully, the environment must be configured
|
||||||
|
with a WOLFRAMALPHA_API_KEY environment variable. Otherwise,
|
||||||
|
skip them.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return os.environ['WOLFRAMALPHA_API_KEY']
|
||||||
|
except KeyError:
|
||||||
|
pytest.skip("Need WOLFRAMALPHA_API_KEY in environment")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def client(API_key):
|
||||||
|
return wolframalpha.Client(API_key)
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -11,24 +9,6 @@ import pytest
|
||||||
import wolframalpha
|
import wolframalpha
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def API_key():
|
|
||||||
"""
|
|
||||||
To run the tests fully, the environment must be configured
|
|
||||||
with a WOLFRAMALPHA_API_KEY environment variable. Otherwise,
|
|
||||||
skip them.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
return os.environ['WOLFRAMALPHA_API_KEY']
|
|
||||||
except KeyError:
|
|
||||||
pytest.skip("Need WOLFRAMALPHA_API_KEY in environment")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def client(API_key):
|
|
||||||
return wolframalpha.Client(API_key)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module')
|
@pytest.fixture(scope='module')
|
||||||
def temp_result(client):
|
def temp_result(client):
|
||||||
return client.query('30 deg C in deg F')
|
return client.query('30 deg C in deg F')
|
||||||
|
|
11
wolframalpha/test_pmxbot.py
Normal file
11
wolframalpha/test_pmxbot.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import pmxbot
|
||||||
|
|
||||||
|
import wolframalpha.pmxbot
|
||||||
|
|
||||||
|
|
||||||
|
def test_pmxbot_command(monkeypatch, API_key):
|
||||||
|
config = {'Wolfram|Alpha API key': API_key}
|
||||||
|
monkeypatch.setattr(pmxbot, 'config', config, raising=False)
|
||||||
|
query = "1kg in lbs"
|
||||||
|
res = wolframalpha.pmxbot.wa(None, None, None, None, rest=query)
|
||||||
|
assert res == '2.205 lb (pounds)'
|
Loading…
Reference in New Issue
Block a user