Add tests for pmxbot command (and Result.results).

This commit is contained in:
Jason R. Coombs 2016-09-04 11:41:18 -04:00
parent 2c2ba47879
commit c66dc29876
3 changed files with 40 additions and 21 deletions

View File

@ -1,4 +1,32 @@
import os
import six
import pytest
import wolframalpha
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)

View File

@ -2,8 +2,6 @@
from __future__ import unicode_literals
import os
import six
import pytest
@ -11,24 +9,6 @@ import pytest
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')
def temp_result(client):
return client.query('30 deg C in deg F')

View 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)'