diff --git a/tests/test_yql.py b/tests/test_yql.py index dc43eff..6ad942a 100644 --- a/tests/test_yql.py +++ b/tests/test_yql.py @@ -9,21 +9,31 @@ def setUp(self): def test_single_select(self): self.yql.select('*') - self.assertEqual(self.yql.selects(), [('*',)]) + self.assertEqual(self.yql.compiled(), 'select * from yahoo.finance.quotes') def test_single_where(self): self.yql.where('symbol') - self.assertEqual(self.yql.wheres(), [('symbol',)]) + self.assertEqual(self.yql.compiled(), 'where symbol') def test_single__in(self): self.yql._in('TSLA') - self.assertEqual(self.yql._ins(), [('TSLA',)]) + self.assertEqual(self.yql.compiled(), 'in ("TSLA")') def test_chaining(self): + compiled = 'select * from yahoo.finance.quotes where symbol in ("TSLA")' self.yql.select('*').where('symbol')._in('TSLA') - self.assertEqual(self.yql.selects(), [('*',)]) - self.assertEqual(self.yql.wheres(), [('symbol',)]) - self.assertEqual(self.yql._ins(), [('TSLA',)]) + self.assertEqual(self.yql.compiled(), compiled) + + def test_sequence(self): + compiled = 'select * from yahoo.finance.quotes where symbol in ("TSLA")' + self.yql.select('*') + self.yql.where('symbol') + self.yql._in('TSLA') + self.assertEqual(self.yql.compiled(), compiled) + + def yes(self): + return True + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/yfi/yql.py b/yfi/yql.py index 7de1bfe..bce8057 100644 --- a/yfi/yql.py +++ b/yfi/yql.py @@ -1,27 +1,24 @@ class Yql: def __init__(self): - self.statment = {'select': [], - 'where': [], - 'in': []} + self.compiled_str = "" def select(self, *itms): - self.statment['select'].append(itms) + self.compile("select %s from yahoo.finance.quotes" % itms) return self - def selects(self): - return self.statment['select'] - def where(self, *whrs): - self.statment['where'].append(whrs) + self.compile("where %s" % whrs) return self - def wheres(self): - return self.statment['where'] - def _in(self, *lst): - self.statment['in'].append(lst) + self.compile('in ("%s")' % lst) return self - def _ins(self): - return self.statment['in'] \ No newline at end of file + def compile(self, part): + if self.compiled_str: + part = " " + part + self.compiled_str += part + + def compiled(self): + return self.compiled_str