Restore expectation that results can be an iterator.

This commit is contained in:
Jason R. Coombs 2016-09-03 12:33:58 -04:00
parent 7ab8e44695
commit 9115d23d83
2 changed files with 16 additions and 5 deletions

View File

@ -100,14 +100,14 @@ class Result(ErrorHandler, object):
@property @property
def results(self): def results(self):
""" """
Get the pods that hold the response to a simple, discrete query. The pods that hold the response to a simple, discrete query.
""" """
return [pod for pod in self.pods if pod.primary or pod.title=='Result'] return (pod for pod in self.pods if pod.primary or pod.title=='Result')
@property @property
def details(self): def details(self):
""" """
Get a simplified set of answers with some context. A simplified set of answer text by title.
""" """
return {pod.title: pod.text for pod in self.pods} return {pod.title: pod.text for pod in self.pods}

View File

@ -22,8 +22,11 @@ def API_key():
pytest.skip("Need WOLFRAMALPHA_API_KEY in environment") pytest.skip("Need WOLFRAMALPHA_API_KEY in environment")
def test_basic(API_key): @pytest.fixture
client = wolframalpha.Client(API_key) def client(API_key):
return wolframalpha.Client(API_key)
def test_basic(client):
res = client.query('30 deg C in deg F') res = client.query('30 deg C in deg F')
assert len(res.pods) > 0 assert len(res.pods) > 0
result, = res.results result, = res.results
@ -31,6 +34,14 @@ def test_basic(API_key):
assert result.texts == ['86 °F (degrees Fahrenheit)'] assert result.texts == ['86 °F (degrees Fahrenheit)']
def test_results_iterator(client):
"""
A Result.results should be an iterator.
"""
res = client.query('30 deg C in deg F')
next(res.results)
def test_invalid_app_id(): def test_invalid_app_id():
client = wolframalpha.Client('abcdefg') client = wolframalpha.Client('abcdefg')
with pytest.raises(Exception): with pytest.raises(Exception):