Skip to content

Commit

Permalink
Changed flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelkr committed Jan 29, 2016
1 parent 8b03cb7 commit c1cd8c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
22 changes: 16 additions & 6 deletions tests/test_yql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
25 changes: 11 additions & 14 deletions yfi/yql.py
Original file line number Diff line number Diff line change
@@ -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']
def compile(self, part):
if self.compiled_str:
part = " " + part
self.compiled_str += part

def compiled(self):
return self.compiled_str

0 comments on commit c1cd8c4

Please sign in to comment.