def test_backspace(): # Single backspace assert strip_control_sequences("123\x084") == "124" # Triple backspace assert strip_control_sequences("123\x08\x08\x084") == "4" # Backspaces followed with spaces assert strip_control_sequences( "\x08 \x08\x08 \x08\x08 \x08\x08 test") == " test"
def test_CSI(): # CSI without P and I stripped assert strip_control_sequences("\x1b[@\x1b[a\x1b[~") == "" # CSI with I stripped assert strip_control_sequences("\x1b[ @\x1b[/~") == "" # CSI with P and I stripped assert strip_control_sequences("\x1b[0 @\x1b[0;7/~") == "" # Cleaned stream assert strip_control_sequences( "L\x1b[@or\x1b[/~em\x1b[0 @ Ips\x1b[0;7/~um\x07") == "Lorem Ipsum"
def cleaned_input(self, input): """ Preprocessor to clean up and normalize input from device. Delete ASCII sequences by default. Can be overriden to achieve desired behavior """ return strip_control_sequences(input)
def test_C1_stripped(): """ C1 set stripped (ESC+[ survive) :return: """ assert strip_control_sequences("".join( ["\x1b" + chr(i) for i in range(64, 96)])) == "\x1b["
def test_control_survive(): """ CR,LF and ESC survive from C0 set :return: """ assert strip_control_sequences("".join([chr(i) for i in range(32)])) == "\t\n\r"
def test_backspace(config, expected): """ Single backspace Triple backspace Backspaces followed with spaces :return: """ assert strip_control_sequences(config) == expected
def test_CSI(config, expected): """ CSI without P and I stripped CSI with I stripped CSI with P and I stripped Cleaned stream :return: """ assert strip_control_sequences(config) == expected
def test_ascii_mess(): """ ASCII mess :return: """ assert strip_control_sequences( "\x1b[2J\x1b[?7l\x1b[3;23r\x1b[?6l\x1b[24;27H\x1b[?25h\x1b[24;27H" "\x1b[?6l\x1b[1;24r\x1b[?7l\x1b[2J\x1b[24;27H\x1b[1;24r\x1b[24;27H" "\x1b[2J\x1b[?7l\x1b[1;24r\x1b[?6l\x1b[24;1H\x1b[1;24r\x1b[24;1H" "\x1b[24;1H\x1b[2K\x1b[24;1H\x1b[?25h\x1b[24;1H\x1b[24;1Hswitch# " "\x1b[24;1H\x1b[24;13H\x1b[24;1H\x1b[?25h\x1b[24;13H") == "switch# "
def test_incomplete_CSI(config, expected): """ Incomplete CSI passed :return: """ assert strip_control_sequences(config) == expected
def test_C1_stripped(config, expected): """ C1 set stripped (ESC+[ survive) :return: """ assert strip_control_sequences(config) == expected
def test_control_survive(config, expected): """ CR,LF and ESC survive from C0 set :return: """ assert strip_control_sequences(config) == expected
def test_strip_normal(config, expected): """ Normal text leaved untouched :return: """ assert strip_control_sequences(config) == expected
def test_ascii_mess(config, expected): """ ASCII mess :return: """ assert strip_control_sequences(config) == expected
def test_incomplete_CSI(): """ Incomplete CSI passed :return: """ assert strip_control_sequences("\x1b[") == "\x1b["
def test_incomplete_C1(): """ Incomplete C1 passed """ assert strip_control_sequences("\x1b") == "\x1b"
def test_strip_normal(): """ Normal text leaved untouched :return: """ assert strip_control_sequences("Lorem Ipsum") == "Lorem Ipsum"