Convert on-object lists into properties. Add tests for these properties.

This commit is contained in:
Jason R. Coombs
2016-09-03 12:49:33 -04:00
parent 9115d23d83
commit d4e09bb905
3 changed files with 53 additions and 25 deletions
+30 -7
View File
@@ -9,7 +9,7 @@ import pytest
import wolframalpha
@pytest.fixture
@pytest.fixture(scope='session')
def API_key():
"""
To run the tests fully, the environment must be configured
@@ -22,26 +22,49 @@ def API_key():
pytest.skip("Need WOLFRAMALPHA_API_KEY in environment")
@pytest.fixture
@pytest.fixture(scope='session')
def client(API_key):
return wolframalpha.Client(API_key)
def test_basic(client):
res = client.query('30 deg C in deg F')
assert len(res.pods) > 0
@pytest.fixture(scope='module')
def temp_result(client):
return client.query('30 deg C in deg F')
def test_basic(temp_result):
res = temp_result
assert len(list(res.pods)) > 0
result, = res.results
assert result.text == '86 °F (degrees Fahrenheit)'
assert result.texts == ['86 °F (degrees Fahrenheit)']
def test_results_iterator(client):
def test_results_iterator(temp_result):
"""
A Result.results should be an iterator.
"""
res = client.query('30 deg C in deg F')
res = temp_result
next(res.results)
def test_properties(temp_result):
"""
A result should have a number of properties.
"""
res = temp_result
info = list(res.info)
warnings = list(res.warnings)
assert all(isinstance(item, wolframalpha.Warning) for item in warnings)
assumptions = list(res.assumptions)
assert all(
isinstance(item, wolframalpha.Assumption)
for item in assumptions
)
pods = list(res.pods)
assert all(isinstance(item, wolframalpha.Pod) for item in pods)
assert len(info) == len(pods) + len(warnings) + len(assumptions)
def test_invalid_app_id():
client = wolframalpha.Client('abcdefg')
with pytest.raises(Exception):