示例#1
0
 def test_mark_re(self):
     self.assertEqual(
         list(
             Chunk([
                 ((), 'xxx'),
                 ((), 'abc'),
                 ((), 'xxxab'),
                 ((), ''),
                 ((), 'cxxx'),
                 ((), 'abcxxx'),
                 ((), 'xxxabc'),
             ]).mark_re(re.compile('abc'), Chunk.tag_reverse)),
         list(
             Chunk([
                 ((), 'xxx'),
                 (('reverse', ), 'abc'),
                 ((), 'xxx'),
                 (
                     ('reverse', ),
                     ('ab'),
                 ),
                 (('reverse', ), ''),
                 (('reverse', ), 'c'),
                 ((), 'xxx'),
                 (('reverse', ), 'abc'),
                 ((), 'xxx'),
                 ((), 'xxx'),
                 (('reverse', ), 'abc'),
             ])))
示例#2
0
    def test(self):
        with mocks.mocked_up_actual_fe_window(window.Window,
                                              window.StatusLine) as w:
            s = w.context.status
            self.assertEqual([
                Chunk([(('visible', ), ''), ((), 'Window'), (('right', ), '1'),
                       ((), 'You'), ((), '                 '), ((), 'be'),
                       ((), '                  '), ((), 'this'),
                       ((), '                '), (('bold', ), '^Z'),
                       ((), ' suspend'), ((), '\n'), ((), "shouldn't"),
                       ((), '           '), ((), 'seeing'),
                       ((), '              '), (('bold', ), '^X^C'),
                       ((), ' quit'), ((), '           '), (('bold', ), '?'),
                       ((), ' help'), ((), '\n')])
            ], [chunk for (mark, chunk) in s.view(0)])

            w.context.conf['set'] = {'cheatsheet': False}
            w.fe.resize_statuswindow()
            self.assertEqual([
                Chunk([
                    (('visible', ), ''),
                    ((), 'Window'),
                    (('right', ), '1'),
                ])
            ], [chunk for (mark, chunk) in s.view(0)])

            s.message('X' * 80)
            self.assertEqual([
                Chunk([
                    ({'visible'}, ''),
                    ({'fg:white', 'bg:red'}, '…' + ('X' * 77)),
                    ({'right'}, '1'),
                ])
            ], [chunk.tagsets() for (mark, chunk) in s.view(0)])

            # defensiveness time

            class W2(window.Window):
                def modeline(self):
                    return None, []

            s.clear()
            w.fe.split_window(W2(w.fe), True)

            self.assertEqual([[
                ({'visible'}, ''),
            ]], [chunk for (mark, chunk) in s.view(0)])

            w.fe.output = 99
            self.assertEqual([
                Chunk([
                    (('visible', ), ''),
                    ((), 'StatusLine'),
                    (('right', ), '1'),
                ])
            ], [chunk for (mark, chunk) in s.view(0)])
示例#3
0
 def test_show_control(self):
     self.assertEqual(
         Chunk([((), 'foo bar')]).show_control().tagsets(),
         [((), 'foo bar')])
     self.assertEqual(
         Chunk([((), 'foo\007bar')]).show_control().tagsets(),
         [((), 'foo'), (Chunk.SHOW_CONTROL, '^G'), ((), 'bar')])
     self.assertEqual(
         Chunk([((), '\007bar')]).show_control().tagsets(),
         [(Chunk.SHOW_CONTROL, '^G'), ((), 'bar')])
     self.assertEqual(
         Chunk([((), 'foo\007')]).show_control().tagsets(),
         [((), 'foo'), (Chunk.SHOW_CONTROL, '^G')])
     self.assertEqual(
         Chunk([((), 'foo\177bar')]).show_control().tagsets(),
         [((), 'foo'), (Chunk.SHOW_CONTROL, '^?'), ((), 'bar')])
示例#4
0
文件: chunks_tests.py 项目: kcr/snipe
 def test_slice(self):
     X, Y, Z = {'x'}, {'y'}, {'z'}
     l = Chunk([(X, 'abc'), (Y, 'def'), (Z, 'ghi')])
     self.assertEqual(l.slice(0), (Chunk(), l))
     self.assertEqual(
         l.slice(1), (
             Chunk([(X, 'a')]),
             Chunk([(X, 'bc'), (Y, 'def'), (Z, 'ghi')])))
     self.assertEqual(
         l.slice(3), (
             Chunk([(X, 'abc')]),
             Chunk([(Y, 'def'), (Z, 'ghi')])))
     self.assertEqual(
         l.slice(4), (
             Chunk([(X, 'abc'), (Y, 'd')]),
             Chunk([(Y, 'ef'), (Z, 'ghi')])))
     self.assertEqual(
         l.slice(6), (
             Chunk([(X, 'abc'), (Y, 'def')]),
             Chunk([(Z, 'ghi')])))
     self.assertEqual(
         l.slice(7), (
             Chunk([(X, 'abc'), (Y, 'def'), (Z, 'g')]),
             Chunk([(Z, 'hi')])))
     self.assertEqual(l.slice(9), (l, Chunk()))
     self.assertEqual(
         Chunk([(X, 'abc'), (Y, ''), (Z, 'def')]).slice(3), (
             Chunk([(X, 'abc')]),
             Chunk([(Y, ''), (Z, 'def')])))
     self.assertEqual(
         Chunk([(X, ''), (Y, 'abc'), (Z, 'def')]).slice(3), (
             Chunk([(X, ''), (Y, 'abc')]),
             Chunk([(Z, 'def')])))
     self.assertEqual(
         Chunk([(X, ''), (Y, 'abc'), (Z, 'def')]).slice(0), (
             Chunk(),
             Chunk([(X, ''), (Y, 'abc'), (Z, 'def')])))
     self.assertEqual(Chunk().slice(0), (Chunk(), Chunk()))
示例#5
0
 def test_xhtml_to_chunk(self):
     self.assertEqual(
         text.xhtml_to_chunk('<blarf>foo</blarf>'),
         Chunk([(('bold', ), '<blarf>'), ((), 'foo'),
                (('bold', ), '</blarf>'), ((), '\n')]))
     self.assertEqual(text.xhtml_to_chunk('foo'), [(set(), 'foo\n')])
     self.assertEqual(
         text.xhtml_to_chunk('one\ntwo\n<pre>three\nfour\n</pre>'),
         [(set(), 'one two \nthree\nfour\n')])
     self.assertEqual(
         text.xhtml_to_chunk(
             '<blockquote><b><code>foo</code></b></blockquote>'),
         [({'bold', 'bg:#3d3d3d'}, '  foo'), (set(), '\n')])
     self.assertEqual(text.xhtml_to_chunk('<a>foo</a>'),
                      [({'fg:#6666ff', 'underline'}, 'foo'), (set(), '\n')])
     self.assertEqual(list(text.xhtml_to_chunk('<b>\none\ntwo\n</b>')),
                      [({'bold'}, ' one two '), (set(), '\n')])
     self.assertEqual(list(text.xhtml_to_chunk('<b>one<br/>two</b>')),
                      [({'bold'}, 'one\ntwo'), (set(), '\n')])
     self.assertEqual(
         list(text.xhtml_to_chunk('<code>' + 'aaa ' * 20 + '</code>')),
         [({'bg:#3d3d3d'}, 'aaa' + ' aaa' * 17), (set(), '\n'),
          ({'bg:#3d3d3d'}, 'aaa aaa '), (set(), '\n')])
示例#6
0
文件: chunks_tests.py 项目: kcr/snipe
 def test(self):
     self.assertEqual(repr(Chunk()), 'Chunk([])')
     self.assertEqual(list(Chunk([((), 'foo')])), [(set(), 'foo')])
     self.assertEqual(Chunk([((), 'foo')]), [(set(), 'foo')])
     self.assertEqual(Chunk([((), 'foo')])[:], Chunk([(set(), 'foo')]))
     self.assertRaises(ValueError, lambda: Chunk().extend([()]))
     c = Chunk()
     self.assertRaises(IndexError, lambda: c[5])
     c.extend([((), 'a'), ({'bold'}, 'b')])
     self.assertEqual(c[:], [(set(), 'a'), ({'bold'}, 'b')])
     self.assertEqual(c[0], (set(), 'a'))
     self.assertRaises(ValueError, lambda: c.__setitem__(0, ()))
     self.assertRaises(
         ValueError, lambda: c.__setitem__(slice(0, 10, 5), []))
     c[0] = (), 'c'
     self.assertEqual(c[:], [(set(), 'c'), ({'bold'}, 'b')])
     self.assertEqual(str(c), 'cb')
     self.assertEqual(len(c), 2)
     c[:] = [((), 'd')]
     self.assertEqual(c[:], [(set(), 'd')])
     self.assertEqual(len(c), 1)
     self.assertEqual(
         str(Chunk([(set(), 'x')]) + Chunk([(set(), 'y')])), 'xy')
     c = Chunk([((), 'foo')])
     c += Chunk([((), 'bar')])
     self.assertEqual(str(c), 'foobar')
     c += [((), 'baz')]
     self.assertEqual(str(c), 'foobarbaz')
     d = [((), 'zog')] + c
     self.assertEqual(str(d), 'zogfoobarbaz')
     del d[0]
     self.assertEqual(str(d), '')
     e = Chunk([((), 'foo'), ({'bold'}, 'baz'), ((), 'bar')])
     self.assertEqual(str(e), 'foobazbar')
     self.assertEqual(len(e), 3)
     del e[1]
     self.assertEqual(str(e), 'foobar')
     self.assertEqual(len(e), 1)
示例#7
0
 def test(self):
     self.assertEqual(repr(Chunk()), 'Chunk([])')
     self.assertEqual(list(Chunk([((), 'foo')])), [(set(), 'foo')])
     self.assertEqual(Chunk([((), 'foo')]), [(set(), 'foo')])
     self.assertEqual(Chunk([((), 'foo')])[:], Chunk([(set(), 'foo')]))
     self.assertRaises(ValueError, lambda: Chunk().extend([()]))
     c = Chunk()
     self.assertRaises(IndexError, lambda: c[5])
     c.extend([((), 'a'), ({'bold'}, 'b')])
     self.assertEqual(c[:], [(set(), 'a'), ({'bold'}, 'b')])
     self.assertEqual(c[0], (set(), 'a'))
     self.assertRaises(ValueError, lambda: c.__setitem__(0, ()))
     self.assertRaises(ValueError,
                       lambda: c.__setitem__(slice(0, 10, 5), []))
     c[0] = (), 'c'
     self.assertEqual(c[:], [(set(), 'c'), ({'bold'}, 'b')])
     self.assertEqual(str(c), 'cb')
     self.assertEqual(len(c), 2)
     c[:] = [((), 'd')]
     self.assertEqual(c[:], [(set(), 'd')])
     self.assertEqual(len(c), 1)
     self.assertEqual(str(Chunk([(set(), 'x')]) + Chunk([(set(), 'y')])),
                      'xy')
     c = Chunk([((), 'foo')])
     c += Chunk([((), 'bar')])
     self.assertEqual(str(c), 'foobar')
     c += [((), 'baz')]
     self.assertEqual(str(c), 'foobarbaz')
     d = [((), 'zog')] + c
     self.assertEqual(str(d), 'zogfoobarbaz')
     del d[0]
     self.assertEqual(str(d), '')
     e = Chunk([((), 'foo'), ({'bold'}, 'baz'), ((), 'bar')])
     self.assertEqual(str(e), 'foobazbar')
     self.assertEqual(len(e), 3)
     del e[1]
     self.assertEqual(str(e), 'foobar')
     self.assertEqual(len(e), 1)
示例#8
0
 def test_endswith(self):
     self.assertTrue(
         Chunk([({'bold'}, 'foo'), ({'italic'}, 'bar')]).endswith('foobar'))
示例#9
0
 def test_tagsets(self):
     self.assertEqual(Chunk().tagsets(), [])
     self.assertEqual(Chunk([((), 'foo')]).tagsets(), [((), 'foo')])
     self.assertEqual(
         Chunk([((), 'foo'), ({'bar'}, 'baz')]).tagsets(),
         [((), 'foo'), ({'bar'}, 'baz')])
示例#10
0
    def test_at_add(self):
        x = Chunk([((), 'abcdef')])

        y = x + Chunk([(('bar', ), '')])
        self.assertEqual(
            y.at_add(6, {'foo'}).tagsets(), [
                ((), 'abcdef'),
                ({'bar', 'foo'}, ''),
            ])

        y = Chunk(x)
        self.assertEqual(
            y.at_add(3, {'foo'}).tagsets(), [((), 'abc'), ({'foo'}, 'def')])

        y = Chunk(x)
        self.assertEqual(y.at_add(0, {'foo'}).tagsets(), [({'foo'}, 'abcdef')])

        y = Chunk(x)
        self.assertEqual(
            y.at_add(6, {'foo'}).tagsets(), [((), 'abcdef'), ({'foo'}, '')])

        y = Chunk([(('bar', ), '')]) + x
        self.assertEqual(
            y.at_add(0, {'foo'}).tagsets(), [({'bar', 'foo'}, ''),
                                             ((), 'abcdef')])

        x = Chunk([((), 'abcdef'), (('bar', ), 'ghijkl')])
        self.assertEqual(
            x.at_add(9, {'foo'}).tagsets(), [
                ((), 'abcdef'),
                ({'bar'}, 'ghi'),
                ({'bar', 'foo'}, 'jkl'),
            ])
示例#11
0
it in ``~/.snipe/netrc`` like so: ::

 machine myslack.slack.com login [email protected] password frob-9782504613-8396512704-9784365210-7960cf


(You need to have already signed up for the relevant slack instance by other
means.)

filler
------

Lorem ipsum dolor sit amet, consecteturadipiscingelit,seddoeiusmodtemporincididuntutlaboreetdoloremagnaaliqua.Utenimadminimveniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
'''  # noqa: E501

TEXT_rendered = [
    (0, Chunk([((), ''), (('bold', ), 'a Title'), ((), '\n')])),
    (8, Chunk([((), '\n')])),
    (9,
     Chunk([((), 'Here is some text.  Here is some more text.  Blah blah blah.'
             '  Foo.\n')])),
    (76,
     Chunk([((), 'Bar.  Flarb. (The previous should get wrapped if everything'
             ' is good.)\n')])),
    (146, Chunk([((), '\n')])),
    (147,
     Chunk([((), 'One. Two. Three. (The above shold end up on one'
             ' line.)\n')])),
    (202, Chunk([((), '\n')])),
    (203,
     Chunk([((), 'myslack.slack.com).  You add '),
            (('bold', ), '.slack name=myname'), ((), ' to the '),
示例#12
0
    def test_view(self):
        w = help.HelpBrowser(None)

        w.pages['TESTPAGE'] = PAGE
        w.load('TESTPAGE')

        self.assertEqual([
            (0,
             Chunk([(('cursor', 'visible'), ''), (('bold', ), 'snipe'),
                    ((), '\n')])),
            (6, Chunk([((), '\n')])),
            (7,
             Chunk([((), 'snipe is a text-oriented (currently curses-based)'
                     ' "instant" messaging\n')])),
            (77,
             Chunk([((), 'client intended for services with persistence.\n')
                    ])),
            (124, Chunk([((), '\n')])),
            (125,
             Chunk([((), 'It is known that there are bugs and missing features'
                     ' everywhere.  I\n')])),
            (193,
             Chunk([((), 'would mostly characterize this as "demoable" but not'
                     ' yet "usable".  As\n')])),
            (264,
             Chunk([((), 'always, if it breaks you get to keep both pieces.\n')
                    ])),
            (314, Chunk([((), '\n')])),
            (315,
             Chunk([((), '* '), (('fg:#6666ff', 'underline'), 'Help browser'),
                    ((), '\n')])),
            (330,
             Chunk([((), '* '),
                    (('fg:#6666ff', 'underline'),
                     'Common commands in all windows'), ((), '\n')])),
            (363, Chunk([((), '\n')])),
        ], [(int(mark), chunk) for (mark, chunk) in w.view(0)])

        w.line_next()
        self.assertEqual([
            (0, Chunk([((), ''), (('bold', ), 'snipe'), ((), '\n')])),
            (6, Chunk([(('cursor', 'visible'), '\n')])),
            (7,
             Chunk([((), 'snipe is a text-oriented (currently curses-based)'
                     ' "instant" messaging\n')])),
            (77,
             Chunk([((), 'client intended for services with persistence.\n')
                    ])),
            (124, Chunk([((), '\n')])),
            (125,
             Chunk([((), 'It is known that there are bugs and missing features'
                     ' everywhere.  I\n')])),
            (193,
             Chunk([((), 'would mostly characterize this as "demoable" but not'
                     ' yet "usable".  As\n')])),
            (264,
             Chunk([((), 'always, if it breaks you get to keep both pieces.\n')
                    ])),
            (314, Chunk([((), '\n')])),
            (315,
             Chunk([((), '* '), (('fg:#6666ff', 'underline'), 'Help browser'),
                    ((), '\n')])),
            (330,
             Chunk([((), '* '),
                    (('fg:#6666ff', 'underline'),
                     'Common commands in all windows'), ((), '\n')])),
            (363, Chunk([((), '\n')])),
        ], [(int(mark), chunk) for (mark, chunk) in w.view(0)])

        w.end_of_buffer()
        self.assertEqual([
            (0, Chunk([((), ''), (('bold', ), 'snipe'), ((), '\n')])),
            (6, Chunk([((), '\n')])),
            (7,
             Chunk([((), 'snipe is a text-oriented (currently curses-based)'
                     ' "instant" messaging\n')])),
            (77,
             Chunk([((), 'client intended for services with persistence.\n')
                    ])), (124, Chunk([((), '\n')])),
            (125,
             Chunk([((), 'It is known that there are bugs and missing features'
                     ' everywhere.  I\n')])),
            (193,
             Chunk([((), 'would mostly characterize this as "demoable" but not'
                     ' yet "usable".  As\n')])),
            (264,
             Chunk([((), 'always, if it breaks you get to keep both pieces.\n')
                    ])), (314, Chunk([((), '\n')])),
            (315,
             Chunk([((), '* '), (('fg:#6666ff', 'underline'), 'Help browser'),
                    ((), '\n')])),
            (330,
             Chunk([((), '* '),
                    (('fg:#6666ff', 'underline'),
                     'Common commands in all windows'), ((), '\n')])),
            (363, Chunk([((), '\n'), (('cursor', 'visible'), '')]))
        ], [(int(mark), chunk) for (mark, chunk) in w.view(0)])
示例#13
0
            (264,
             Chunk([((), 'always, if it breaks you get to keep both pieces.\n')
                    ])), (314, Chunk([((), '\n')])),
            (315,
             Chunk([((), '* '), (('fg:#6666ff', 'underline'), 'Help browser'),
                    ((), '\n')])),
            (330,
             Chunk([((), '* '),
                    (('fg:#6666ff', 'underline'),
                     'Common commands in all windows'), ((), '\n')])),
            (363, Chunk([((), '\n'), (('cursor', 'visible'), '')]))
        ], [(int(mark), chunk) for (mark, chunk) in w.view(0)])


PAGE = ([
    View(0, Chunk([((), ''), (('bold', ), 'snipe'), ((), '\n')])),
    View(6, Chunk([((), '\n')])),
    View(
        7,
        Chunk([((),
                'snipe is a text-oriented (currently curses-based) "instant"'
                ' messaging\n')])),
    View(77,
         Chunk([((), 'client intended for services with persistence.\n')])),
    View(124, Chunk([((), '\n')])),
    View(
        125,
        Chunk([((), 'It is known that there are bugs and missing features'
                ' everywhere.  I\n')])),
    View(
        193,
示例#14
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')
                ])
示例#15
0
 def test_slice(self):
     X, Y, Z = {'x'}, {'y'}, {'z'}
     l = Chunk([(X, 'abc'), (Y, 'def'), (Z, 'ghi')])
     self.assertEqual(l.slice(0), (Chunk(), l))
     self.assertEqual(
         l.slice(1),
         (Chunk([(X, 'a')]), Chunk([(X, 'bc'), (Y, 'def'), (Z, 'ghi')])))
     self.assertEqual(l.slice(3),
                      (Chunk([(X, 'abc')]), Chunk([(Y, 'def'),
                                                   (Z, 'ghi')])))
     self.assertEqual(l.slice(4),
                      (Chunk([(X, 'abc'),
                              (Y, 'd')]), Chunk([(Y, 'ef'), (Z, 'ghi')])))
     self.assertEqual(l.slice(6),
                      (Chunk([(X, 'abc'),
                              (Y, 'def')]), Chunk([(Z, 'ghi')])))
     self.assertEqual(l.slice(7), (Chunk([(X, 'abc'), (Y, 'def'),
                                          (Z, 'g')]), Chunk([(Z, 'hi')])))
     self.assertEqual(l.slice(9), (l, Chunk()))
     self.assertEqual(
         Chunk([(X, 'abc'), (Y, ''), (Z, 'def')]).slice(3),
         (Chunk([(X, 'abc')]), Chunk([(Y, ''), (Z, 'def')])))
     self.assertEqual(
         Chunk([(X, ''), (Y, 'abc'), (Z, 'def')]).slice(3),
         (Chunk([(X, ''), (Y, 'abc')]), Chunk([(Z, 'def')])))
     self.assertEqual(
         Chunk([(X, ''), (Y, 'abc'), (Z, 'def')]).slice(0),
         (Chunk(), Chunk([(X, ''), (Y, 'abc'), (Z, 'def')])))
     self.assertEqual(Chunk().slice(0), (Chunk(), Chunk()))
示例#16
0
 def test_slice_point_tags(self):
     self.assertEqual(
         Chunk([({'cursor'}, 'foobar')]).slice(3),
         (Chunk([({'cursor'}, 'foo')]), Chunk([((), 'bar')])))
     self.assertEqual(
         Chunk([({'cursor'}, 'foobar')]).slice(0),
         (Chunk(), Chunk([({'cursor'}, 'foobar')])))
     self.assertEqual(
         Chunk([((), 'foo'), ({'cursor'}, 'bar')]).slice(3),
         (Chunk([((), 'foo')]), Chunk([({'cursor'}, 'bar')])))
     self.assertEqual(
         Chunk([((), 'foo'), ({'cursor'}, ''), ((), 'bar')]).slice(3),
         (Chunk([((), 'foo')]), Chunk([({'cursor'}, ''), ((), 'bar')])))
示例#17
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'),
                ]))
示例#18
0
文件: chunks_tests.py 项目: kcr/snipe
    def test_at_add(self):
        x = Chunk([((), 'abcdef')])

        y = x + Chunk([(('bar',), '')])
        self.assertEqual(y.at_add(6, {'foo'}).tagsets(), [
            ((), 'abcdef'),
            ({'bar', 'foo'}, ''),
            ])

        y = Chunk(x)
        self.assertEqual(
            y.at_add(3, {'foo'}).tagsets(), [((), 'abc'), ({'foo'}, 'def')])

        y = Chunk(x)
        self.assertEqual(y.at_add(0, {'foo'}).tagsets(), [({'foo'}, 'abcdef')])

        y = Chunk(x)
        self.assertEqual(
            y.at_add(6, {'foo'}).tagsets(), [((), 'abcdef'), ({'foo'}, '')])

        y = Chunk([(('bar',), '')]) + x
        self.assertEqual(
            y.at_add(0, {'foo'}).tagsets(),
            [({'bar', 'foo'}, ''), ((), 'abcdef')])

        x = Chunk([((), 'abcdef'), (('bar',), 'ghijkl')])
        self.assertEqual(x.at_add(9, {'foo'}).tagsets(), [
            ((), 'abcdef'),
            ({'bar'}, 'ghi'),
            ({'bar', 'foo'}, 'jkl'),
            ])