def test_format_status_with_stats(): FakeCursor = namedtuple( "FakeCursor", ["execution_time_in_millis", "data_scanned_in_bytes"]) assert format_status( rows_length=1, cursor=FakeCursor(10, 12345678900) ) == "1 row in set\nExecution time: 10 ms, Data scanned: 11.5 GB, Approximate cost: $0.06" assert format_status( rows_length=2, cursor=FakeCursor(1000, 1234) ) == "2 rows in set\nExecution time: 1000 ms, Data scanned: 1.21 KB, Approximate cost: $0.00"
def get_result(self, cursor): '''Get the current result's data from the cursor.''' title = headers = None special.set_output_location(cursor.output_location) # cursor.description is not None for queries that return result sets, # e.g. SELECT or SHOW. if cursor.description is not None: headers = [x[0] for x in cursor.description] rows = cursor.fetchall() status = format_status(rows_length=len(rows), cursor=cursor) else: logger.debug('No rows in result.') rows = None status = format_status(rows_length=None, cursor=cursor) return (title, rows, headers, status)
def test_format_status_plural(): assert format_status(rows_length=1) == "1 row in set" assert format_status(rows_length=2) == "2 rows in set"
def test_format_status_no_results(): assert format_status(rows_length=None) == "Query OK"