From d90262ad35b25a7a4ec0e01a2dd4d4c813729030 Mon Sep 17 00:00:00 2001 From: Henrique Date: Tue, 12 Nov 2019 23:16:52 -0500 Subject: [PATCH] Getting 100% coverage in the lexer --- mitmproxy/lexer.py | 3 --- test/mitmproxy/test_lexer.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mitmproxy/lexer.py b/mitmproxy/lexer.py index a7024ca22..f123a8384 100644 --- a/mitmproxy/lexer.py +++ b/mitmproxy/lexer.py @@ -90,9 +90,6 @@ class Lexer: acc += ch else: acc += ch - else: - print("This shouldn't have happened") - exit(-1) self._token = acc diff --git a/test/mitmproxy/test_lexer.py b/test/mitmproxy/test_lexer.py index ae706407e..a1898620e 100644 --- a/test/mitmproxy/test_lexer.py +++ b/test/mitmproxy/test_lexer.py @@ -1,5 +1,6 @@ from mitmproxy import lexer import pytest +import io class TestScripts: @@ -47,6 +48,10 @@ class TestScripts: "text": '\n\n\rHello\n World With Spaces\n\n', "result": ['Hello', 'World', 'With', 'Spaces'] }, + { + "text": r'\" Escaping characters without reason', + "result": ['\\"', 'Escaping', 'characters', 'without', 'reason'] + }, ] for t in cases: @@ -61,3 +66,12 @@ class TestScripts: lex = lexer.Lexer(text) with pytest.raises(ValueError, match="No closing quotation"): assert list(lex) + + def test_stringio_text(self): + text = io.StringIO(r'Increase test coverage') + lex = lexer.Lexer(text) + tokens = list(lex) + result = ['Increase', 'test', 'coverage'] + assert(tokens == result) + +