@@ -340,6 +340,27 @@ def test_no_fields(self):
340340 self .assertEqual (result , "" )
341341
342342
343+ class TestLimit (unittest .TestCase ):
344+
345+ def test_with_limit (self ):
346+ """Ensure that render limit works."""
347+ from bigquery .query_builder \
348+ import _render_limit
349+
350+ result = _render_limit (8 )
351+
352+ self .assertEqual (result , "LIMIT 8" )
353+
354+ def test_no_fields (self ):
355+ """Ensure that render limit can work without any arguments."""
356+ from bigquery .query_builder \
357+ import _render_limit
358+
359+ result = _render_limit (None )
360+
361+ self .assertEqual (result , "" )
362+
363+
343364class TestRenderQuery (unittest .TestCase ):
344365
345366 def test_full_query (self ):
@@ -392,14 +413,16 @@ def test_full_query(self):
392413 'type' : 'INTEGER'
393414 }
394415 ],
395- order_by = {'fields' : ['timestamp' ], 'direction' : 'desc' })
416+ order_by = {'fields' : ['timestamp' ], 'direction' : 'desc' },
417+ limit = 10 )
396418
397419 expected_query = ("SELECT status as status, start_time as timestamp, "
398420 "resource as url FROM [dataset.2013_06_appspot_1]"
399421 " WHERE (start_time <= INTEGER('1371566954')) AND "
400422 "(start_time >= INTEGER('1371556954')) GROUP BY "
401423 "timestamp, status HAVING (status == INTEGER('1')) "
402- "ORDER BY timestamp desc " )
424+ "ORDER BY timestamp desc "
425+ "LIMIT 10" )
403426 expected_select = (expected_query [len ('SELECT ' ):]
404427 .split ('FROM' )[0 ].strip ().split (', ' ))
405428 expected_from = expected_query [len ('SELECT ' ):].split ('FROM' )[1 ]
0 commit comments