Esempio n. 1
0
class Test_LineReceiver_aspects:

    def setUp(self):
        self.received = []
        self.tc = TelnetClient(TelnetClientFactory(None, 'ascii', None))
        self.tc.transport = FakeTransport()
        self.tc.lineReceived = self.lr

    def lr(self, line):
        self.received.append(line)

    def test_boring(self):
        self.tc.dataReceived("foo\r\nbar\r\nbaz")
        assert self.received == ['foo', 'bar'], self.received

    def test_closing_flushes_buffer(self):
        self.tc.dataReceived("bar")
        self.tc.connectionLost(None)
        assert self.received == ['bar']
Esempio n. 2
0
class Test_receiving_lines:

    def setUp(self):
        self.f = TelnetClientFactory(None, 'ascii', None)
        self.f.realm = self.e = Mock(spec = RootRealm)
        self.tc = TelnetClient(self.f)
        self.tc.transport = FakeTransport()
        self.fores = RunLengthList([(0, fg_code(WHITE, False))])
        self.backs = RunLengthList([(0, bg_code(BLACK))])

    def test_ga_received_sends_line_on(self):
        expected = [Metaline('foo', self.fores, self.backs, wrap = True,
                             line_end = 'soft')]
        self.tc.dataReceived("foo" + IAC + GA)
        print expected
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_ga_received_flushes_out_the_buffer(self):
        expected = [Metaline("foo", self.fores, self.backs, wrap = True,
                             line_end = 'soft'),
                    Metaline('', self.fores, self.backs, wrap = True,
                             line_end = 'soft')]
        self.tc.dataReceived('foo' + IAC + GA + IAC + GA)
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_lineReceived_sends_line_on(self):
        self.tc.lineReceived("foo")
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == [Metaline('foo', self.fores, self.backs, wrap = True)]

    def test_lineReceived_parses_colours(self):
        expected = [Metaline('foo', RunLengthList([(0, fg_code(RED, False))]),
                             self.backs, wrap = True)]
        self.tc.lineReceived('\x1b[31mfoo')
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_lineReceived_works_via_dataReceived(self):
        expected = [Metaline('foo', self.fores, self.backs, wrap = True)]
        self.tc.dataReceived('foo\r\n')
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_lineReceived_cleans_out_VT100_stuff(self):
        expected = [Metaline('foo', self.fores, self.backs, wrap = True)]
        self.tc.lineReceived('fooQ' + BS + VT)
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_lineReceived_decodes_data(self):
        #real-ish example that booted me :(
        self.f.encoding = 'cp1250'
        expected = [Metaline(u"bar\u2019baz", self.fores, self.backs, 
                             wrap = True)]
        self.tc.lineReceived('bar\x92baz')
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_receives_repeated_normal_CR_LF_in_broken_godwars_mode_fine(self):
        self.tc.fix_broken_godwars_line_endings = True
        self.tc.dataReceived("foo\r\n\r\n")
        expected = [simpleml("foo", fg_code(WHITE, False), bg_code(BLACK)),
                    simpleml("", fg_code(WHITE, False), bg_code(BLACK))]
        for ml in expected:
            ml.wrap = True
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_fixes_LF_CR_normally(self):
        self.tc.fix_broken_godwars_line_endings = True
        self.tc.dataReceived("foo\n\r")
        expected = [simpleml("foo", fg_code(WHITE, False), bg_code(BLACK))]
        expected[0].wrap = True
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        assert lines == expected, lines

    def test_fixes_LF_CR_at_start(self):
        self.tc.fix_broken_godwars_line_endings = True
        self.tc.dataReceived("\n\r")
        expected = [simpleml("", fg_code(WHITE, False), bg_code(BLACK))]
        expected[0].wrap = True
        lines = [line for ((line,), kwargs)
                 in self.e.metalineReceived.call_args_list]
        print expected
        assert lines == expected, lines