From 2c347af7a3bdfb0e23ba96b28150d4e83485cf74 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 16 Jan 2021 22:22:36 +0300 Subject: [PATCH] Fix(process_tokens): Check if parser didn't produce any statements at all --- sqlconvert/process_tokens.py | 2 ++ tests/test_process_tokens.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sqlconvert/process_tokens.py b/sqlconvert/process_tokens.py index cb14467..414c5ca 100644 --- a/sqlconvert/process_tokens.py +++ b/sqlconvert/process_tokens.py @@ -54,6 +54,8 @@ class StatementGrouper(object): def process_lines(self): statements = parse(''.join(self.lines), encoding=self.encoding) + if not statements: + return last_stmt = statements[-1] for i in xrange(len(last_stmt.tokens) - 1, 0, -1): token = last_stmt.tokens[i] diff --git a/tests/test_process_tokens.py b/tests/test_process_tokens.py index 0cc431c..d74cb47 100644 --- a/tests/test_process_tokens.py +++ b/tests/test_process_tokens.py @@ -8,8 +8,8 @@ from sqlconvert.process_tokens import is_newline_statement, StatementGrouper def test_newline_statement(): - parsed = parse("\n")[0] - assert is_newline_statement(parsed) + parsed = parse("\n") + assert not parsed or is_newline_statement(parsed[0]) def test_encoding(): -- 2.39.5