Esempio n. 1
0
    def test_headline(self):
        Decor = zulip.ZulipMessage.Decor
        msg = mocks.Message(data={
            'timestamp': 0.0,
            'sender_email': 'baz',
        })
        msg._chat = 'foo'
        msg.sender = messages.SnipeAddress(mocks.Backend())
        os.environ['TZ'] = 'GMT'

        self.assertEqual(
            Decor.headline(msg).tagsets(), [({'bold'}, '·foo>'), ((), ' <'),
                                            ({'bold'}, 'baz'), ((), '>'),
                                            ({'right'}, ' 00:00:00\n')])

        msg.data['subject'] = 'zog'
        msg.data['sender_full_name'] = 'The Great Quux'

        self.assertEqual(
            Decor.headline(msg).tagsets(), [({'bold'}, '·foo>'),
                                            ((), ' zog <'), ({'bold'}, 'baz'),
                                            ((), '> The Great Quux'),
                                            ({'right'}, ' 00:00:00\n')])
Esempio n. 2
0
    def test(self):
        Decor = irccloud.IRCCloudMessage.Decor
        msg = mocks.Message(data={
            'type': 'buffer_msg',
            })
        msg.time = 0.0
        msg.channel = '#foo'
        msg.body = 'bar'
        msg.sender = messages.SnipeAddress(mocks.Backend())
        os.environ['TZ'] = 'GMT'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                (('bold',), 'mock'),
                (('fill',), ': bar'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'error'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'bar'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'banned'
        msg.data['server'] = 'quux'
        msg.data['reason'] = 'because'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'quux: because'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'hidden_host_set'
        msg.data['hidden_host'] = 'thing'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'quux: thing bar'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'myinfo'
        msg.data['version'] = '0'
        msg.data['user_modes'] = 'user'
        msg.data['channel_modes'] = 'b'
        msg.data['rest'] = 'a'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'quux: 0, user modes: user, channel modes: ab'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'connecting_failed'
        msg.data['hostname'] = 'jupiter'
        msg.data['port'] = 1999
        msg.data['ssl'] = True
        msg.data['reason'] = 'doubtful'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'jupiter:1999 (ssl) connection failed: doubtful'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'quit_server'
        msg.data['nick'] = 'She'
        msg.data['msg'] = 'umami'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'jupiter:1999 (ssl) She quit: umami'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'you_nickchange'
        msg.data['newnick'] = 'red'
        msg.data['oldnick'] = 'blue'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'you are now red (née blue)'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'channel_topic'
        msg.data['from_name'] = 'some luser'
        msg.data['topic'] = 'something boring'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'some luser set topic to '),
                (('bold',), 'something boring'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'channel_timestamp'
        msg.data['timestamp'] = 0

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'created Thu Jan  1 00:00:00 1970'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'user_channel_mode'
        msg.data['ops'] = {
            'add': [{'mode': 'mode', 'param': 'param'}],
            'remove': [{'mode': 'mode', 'param': 'param'}],
            }

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'some luser set '),
                (('bold',), '+mode param -mode param'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'user_mode'
        msg.data['from'] = 'droid'
        msg.data['diff'] = '9000'
        msg.data['newmode'] = 'ants'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'droid set '),
                (('bold',), '9000'),
                ((), ' ('),
                (('bold',), 'ants'),
                ((), ') on you'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'channel_mode_is'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'mode '),
                (('bold',), '9000'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'channel_url'
        msg.data['url'] = 'file:///'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'url: '),
                (('bold',), 'file:///'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'channel_mode_list_change'
        msg.data['url'] = 'file:///'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'channel mode '),
                (('bold',), '9000'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'joined_channel'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), '+ '),
                (('bold',), 'mock'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'parted_channel'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), '- '),
                (('bold',), 'mock'),
                ((), ': bar'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = 'nickchange'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'blue'),
                ((), ' -> '),
                (('bold',), 'mock'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data = {}

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), 'mock [no type] eid - bid - cid -\n{}'),
                (('right',), ' 00:00:00'),
                ]))
Esempio n. 3
0
    def test(self):
        Decor = slack.SlackMessage.Decor
        msg = mocks.Message(data={
            'type': 'message',
            'subtype': 'me_message',
            'edited': '?',
            'is_starred': True,
            'pinned_to': True,
            'text': 'baz',
            })
        msg.time = 0.0
        msg.channel = '#foo'
        msg.body = 'bar'
        msg.sender = messages.SnipeAddress(mocks.Backend())
        os.environ['TZ'] = 'GMT'
        msg.slackmarkup = lambda text, tags: [(tags, text)]

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), '~'),
                ((), '*'),
                ((), '+'),
                (('bold',), 'mock'),
                ((), ' '),
                ((), 'baz'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['is_starred'] = False
        msg.data['pinned_to'] = False
        del msg.data['edited']
        msg.data['subtype'] = ''

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                (('bold',), 'mock'),
                ((), ': '),
                ((), 'baz'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['file'] = {'url': 'file:///'}

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                (('bold',), 'mock'),
                ((), ': '),
                ((), 'baz'),
                ((), '\nfile:///'),
                (('right',), ' 00:00:00'),
                ]))

        del msg.data['file']

        msg.data['reactions'] = [{'name': 'over', 'count': 9000}]

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                (('bold',), 'mock'),
                ((), ': '),
                ((), 'baz'),
                ((), '\n:over: 9000'),
                (('right',), ' 00:00:00'),
                ]))

        del msg.data['reactions']
        msg.data['attachments'] = [
            {
                'color': 'danger',
                'title_link': 'file:///',
                'text': 'things',
                'fields': [{'title': 'key', 'value': 'value'}],
            }, {
                'color': 'f0f0f0',
                'text': 'stuff',
            }]

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                (('bold',), 'mock'),
                ((), ': '),
                ((), 'baz'),
                ((), '\n'),
                (('bg:red',), ' '),
                ((), ' '),
                ((), 'file:///'),
                ((), '\n'),
                (('bg:red',), ' '),
                ((), ' '),
                ((), 'things'),
                ((), '\n'),
                (('bg:red',), ' '),
                ((), ' '),
                (('bold',), 'key'),
                ((), '\n'),
                (('bg:red',), ' '),
                ((), ' '),
                ((), 'value'),
                ((), '\n'),
                (('bg:#f0f0f0',), ' '),
                ((), ' '),
                ((), 'stuff'),
                (('right',), ' 00:00:00'),
                ]))

        del msg.data['attachments']

        msg.data['type'] = 'presence_change'
        msg.data['presence'] = 'active'

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), '+ '),
                (('bold',), 'mock'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['presence'] = 'passive'  # ?

        self.assertEqual(
            Decor.headline(msg), Chunk([
                (('bold',), '#foo '),
                ((), '- '),
                (('bold',), 'mock'),
                (('right',), ' 00:00:00'),
                ]))

        msg.data['type'] = None

        self.assertEqual(
            Decor.headline(msg, {'fg:white', 'bg:blue'}), [
                    ({'fg:white', 'bg:blue', 'bold'}, 'followup'),
                    ({'fg:white', 'bg:blue'}, ' : '),
                    ({'fg:white', 'bg:blue', 'bold'}, 'mock'),
                    ({'fg:white', 'bg:blue', 'right'}, ' 00:00:00'),
                    ({'fg:white', 'bg:blue'}, 'bar\n')
                ])
Esempio n. 4
0
    def test_headline(self):
        Decor = roost.RoostMessage.Decor
        msg = mocks.Message(data={
            'class': 'foo',
            'instance': 'bar',
            'recipient': '',
            'opcode': 'baz',
            'time': 0.0,
            })
        msg.sender = messages.SnipeAddress(mocks.Backend())
        os.environ['TZ'] = 'GMT'

        self.assertEqual(
            Decor.headline(msg).tagsets(), [
                ((), '-c '),
                ({'bold'}, 'foo'),
                ((), ' -i bar [baz] <'),
                ({'bold'}, 'mock'),
                ((), '>'),
                ({'right'}, ' 00:00:00')])

        msg.data['recipient'] = '@QUUX'

        self.assertEqual(
            Decor.headline(msg).tagsets(), [
                ((), '-c '),
                ({'bold'}, 'foo'),
                ((), ' -i bar'),
                ({'bold'}, ' @QUUX'),
                ((), ' [baz] <'),
                ({'bold'}, 'mock'),
                ((), '>'),
                ({'right'}, ' 00:00:00')])

        msg.data['recipient'] = 'someone'
        msg.personal = True

        self.assertEqual(
            Decor.headline(msg).tagsets(), [
                ({'bold'}, '<personal)'),
                ((), '-c '),
                ({'bold'}, 'foo'),
                ((), ' -i bar [baz] <'),
                ({'bold'}, 'mock'),
                ((), '>'),
                ({'right'}, ' 00:00:00')])

        msg.outgoing = True

        self.assertEqual(
            Decor.headline(msg).tagsets(), [
                ({'bold'}, '(personal> <>'),
                ((), '-c '),
                ({'bold'}, 'foo'),
                ((), ' -i bar [baz] <'),
                ({'bold'}, 'mock'),
                ((), '>'),
                ({'right'}, ' 00:00:00')])

        msg.data['opcode'] = ''
        msg.data['recipient'] = ''
        msg.personal = False
        msg.outgoing = False

        msg.data['signature'] = '@{The Great Quux}'

        msg.backend.format_zsig = 'format'

        self.assertEqual(
            Decor.headline(msg).tagsets(), [
                ((), '-c '),
                ({'bold'}, 'foo'),
                ((), ' -i bar <'),
                ({'bold'}, 'mock'),
                ((), '> The Great Quux'),
                ({'right'}, ' 00:00:00')])

        msg.backend.format_zsig = 'strip'

        self.assertEqual(
            Decor.headline(msg).tagsets(), [
                ((), '-c '),
                ({'bold'}, 'foo'),
                ((), ' -i bar <'),
                ({'bold'}, 'mock'),
                ((), '> The Great Quux'),
                ({'right'}, ' 00:00:00')])
Esempio n. 5
0
    def test_composer(self):
        result = None

        def cb(s):
            nonlocal result
            result = s

        fe = mocks.FE()
        mockirc = mocks.Backend()
        mockirc.name = 'irccloud'
        fe.context.backends._backends.append(mockirc)

        w = prompt.Composer(fe,
                            content='mock; foobar',
                            completer=interactive.Completer([
                                'mock; foobar', 'mock; foobaz', 'mock; fooquux'
                            ]),
                            callback=cb)

        w.beginning_of_line(interactive=True)
        w.kill_to_end_of_line(None)
        self.assertEqual(w.input(), '')
        w.after_command()

        w.insert('irccloud; foo bar')
        w.after_command()
        w.insert_newline()
        w.after_command()
        self.assertEqual(w.fill_column, 0)
        w.insert_newline()
        w.after_command()
        self.assertEqual(w.fill_column, 0)

        w.beginning_of_buffer(interactive=True)
        w.after_command()
        w.kill_to_end_of_line(count=None)
        w.after_command()
        w.insert('m; foobar')
        w.after_command()
        w.end_of_buffer()
        w.after_command()
        self.assertEqual(w.fill_column, w.default_fill_column)
        w.insert('blob')

        w.destroy()
        del w

        w = prompt.Composer(fe,
                            content='mock; foobaz',
                            completer=interactive.Completer([
                                'mock; foobar', 'mock; foobaz', 'mock; fooquux'
                            ]),
                            callback=cb)

        self.assertEqual([(0, [
            ({'bold'}, '> '),
            ((), 'mock; foobaz'),
            ({'cursor', 'visible'}, ''),
        ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        w.previous_history_full()

        self.assertEqual([
            (0, [({'bold'}, '> '), ((), 'm; foobar\n')]),
            (12, [((), '\n')]),
            (13, [
                ((), 'blob'),
                ({'cursor', 'visible'}, ''),
            ]),
        ], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        w.next_history_full()

        self.assertEqual([(0, [
            ({'bold'}, '> '),
            ((), 'mock; foobaz'),
            ({'cursor', 'visible'}, ''),
        ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        w.beginning_of_buffer(interactive=True)
        p0 = w.cursor.point
        w.end_of_line()
        self.assertEqual(w.buf[p0:w.cursor.point], 'mock; foobaz')
        w.cursor.point = p0
        w.previous_history()
        w.end_of_line()
        self.assertEqual(w.buf[p0:w.cursor.point], 'm; foobar')
        w.previous_history()
        self.assertEqual(w.buf[p0:w.cursor.point], 'm; foobar')
        w.cursor.point = p0
        w.next_history()
        w.end_of_line()
        self.assertEqual(w.buf[p0:w.cursor.point], 'mock; foobaz')

        w.previous_history_full()
        w.line_next()
        w.next_history()

        self.assertEqual([
            (0, [
                ({'bold'}, '> '),
                ((), 'm; foobar\n'),
            ]),
            (12, [({'cursor', 'visible'}, '')]),
        ], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        w.destroy()
        del w

        w = prompt.Composer(fe,
                            completer=interactive.Completer([
                                'mock; foobar', 'mock; foobaz', 'mock; fooquux'
                            ]),
                            callback=cb)

        self.assertEqual([(0, [
            ({'bold'}, '> '),
            ({'cursor', 'visible'}, ''),
            ((), ' {'),
            ({'bold'}, 'mock; foobar'),
            ((), '|mock; foobaz|mock; fooquux}\n'),
        ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])
        w.previous_history()

        self.assertEqual([
            (0, [
                ({'bold'}, '> '),
                ((), 'm; foobar'),
                ({'cursor', 'visible'}, ''),
                ((), ' {}\n'),
            ]),
            (12, [((), '')]),
        ], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        w.destroy()
        del w

        w = prompt.Composer(fe,
                            completer=interactive.Completer([
                                'mock; foobar', 'mock; foobaz', 'mock; fooquux'
                            ]),
                            callback=cb)

        self.assertEqual([(0, [
            ({'bold'}, '> '),
            ({'cursor', 'visible'}, ''),
            ((), ' {'),
            ({'bold'}, 'mock; foobar'),
            ((), '|mock; foobaz|mock; fooquux}\n'),
        ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        do(w.roll_or_search_forward())

        self.assertEqual([(0, [
            ({'bold'}, '> '),
            ({'cursor', 'visible'}, ''),
            ((), ' {'),
            ({'bold'}, 'mock; foobaz'),
            ((), '|mock; fooquux|mock; foobar}\n'),
        ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        do(w.roll_or_search_backward('bar'))

        self.assertEqual([(0, [
            ({'bold'}, '> '),
            ({'cursor', 'visible'}, ''),
            ((), ' {'),
            ({'bold'}, 'mock; foobar'),
            ((), '|mock; foobaz|mock; fooquux}\n'),
        ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])

        w.insert('foobar')
        w.insert_newline()
        w.insert('abc\ndef\nghi\n')
        do(w.roll_or_search_backward('abc'))
        self.assertEqual(w.buf[w.cursor.point:w.cursor.point + 3], 'abc')
        do(w.roll_or_search_forward('ghi'))
        self.assertEqual(w.buf[w.cursor.point:w.cursor.point + 3], 'ghi')