Expanded basic test

This commit is contained in:
Jason R. Coombs 2012-10-03 19:36:21 -04:00
parent c4ac852a68
commit c9b2863ed1
2 changed files with 19 additions and 3 deletions

View File

@ -6,9 +6,19 @@ class Result(object):
def __init__(self, stream): def __init__(self, stream):
self.tree = etree.parse(stream) self.tree = etree.parse(stream)
def __iter__(self):
return (Pod(node) for node in self.tree.findall('pod'))
def __len__(self):
return len(self.tree)
@property @property
def pods(self): def pods(self):
return map(Pod, self.tree.findall('pod')) return list(iter(self))
@property
def results(self):
return (pod for pod in self if pod.title=='Result')
class Pod(object): class Pod(object):
def __init__(self, node): def __init__(self, node):
@ -16,7 +26,7 @@ class Pod(object):
self.__dict__.update(node.attrib) self.__dict__.update(node.attrib)
def __iter__(self): def __iter__(self):
return (Content(node) for node in self.nodes.findall('subpod')) return (Content(node) for node in self.node.findall('subpod'))
@property @property
def main(self): def main(self):

View File

@ -1,3 +1,7 @@
#-*- coding: utf-8 -*-
from __future__ import unicode_literals
import wolframalpha import wolframalpha
app_id = 'Q59EW4-7K8AHE858R' app_id = 'Q59EW4-7K8AHE858R'
@ -6,4 +10,6 @@ app_id = 'Q59EW4-7K8AHE858R'
def test_basic(): def test_basic():
client = wolframalpha.Client(app_id) client = wolframalpha.Client(app_id)
res = client.query('30 deg C in deg F') res = client.query('30 deg C in deg F')
import pytest; pytest.set_trace() assert len(res.pods) > 0
results = list(res.results)
assert results[0].text == '86 °F (degrees Fahrenheit)'