Exemplo n.º 1
0
def test_Metaline_delete():
    fores = RunLengthList([(0, 'F'), (4, 'B'), (7, 'Z')])
    backs = RunLengthList([(0, 'F'), (4, 'B'), (7, 'Z')])
    m = Metaline('foobarbaz', fores, backs)
    m.delete(3, 6)
    assert m.line == 'foobaz', m.line
    assert m.fores.items() == m.backs.items() == [(0, 'F'), (3, 'B'), (4, 'Z')]
Exemplo n.º 2
0
def test_Metaline_insert_adjustsindices_beyond_span():
    fores = RunLengthList([(0, 'F'), (5, 'B')])
    backs = RunLengthList([(0, 'F'), (5, 'B')])
    m = Metaline('foobar', fores, backs)
    m.insert(3, 'baz')
    assert m.fores.items() == [(0, 'F'), (8, 'B')], m.fores.items()
    assert m.backs.items() == [(0, 'F'), (8, 'B')], m.backs.items()
Exemplo n.º 3
0
def test_insert_metaline():
    ml_one = Metaline('foo baz', RunLengthList([(0, 'foo'), (4, 'baz')]),
                      RunLengthList([(0, 'foo'), (4, 'baz')]))
    ml_two = simpleml('bar ', 'bar', 'bar')
    ml_one.insert_metaline(4, ml_two)
    assert ml_one == Metaline(
        "foo bar baz", RunLengthList([(0, 'foo'), (4, 'bar'), (8, 'baz')]),
        RunLengthList([(0, 'foo'), (4, 'bar'), (8, 'baz')]))
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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)]
Exemplo n.º 6
0
 def test_insert_metaline(self):
     ml_one = simpleml('foo', 'foo', 'foo')
     self.la.insert_metaline(1, simpleml('bar', 'bar', 'bar'))
     res = self.la.apply(ml_one)
     assert res == Metaline(
         'fbaroo', RunLengthList([(0, 'foo'), (1, 'bar'), (4, 'foo')]),
         RunLengthList([(0, 'foo'), (1, 'bar'), (4, 'foo')]))
Exemplo n.º 7
0
 def test_change_fore_with_no_right_bound(self):
     ml = Metaline("foobarbaz", RunLengthList([(0, fg_code(WHITE, False))]),
                   RunLengthList([(0, None)]))
     self.la.change_fore(3, None, fg_code(RED, False))
     res = self.la.apply(ml)
     assert res.fores.items() == [(0, fg_code(WHITE, False)),
                                  (3, fg_code(RED, False))]
Exemplo n.º 8
0
 def test_metalineReceived_sets_fore_and_back_for_overruns(self):
     colours = []
     self.o.change_colour = lambda: colours.append(
         (self.o.fore, self.o.back))
     self.o.metalineReceived(
         Metaline("foo", RunLengthList([(0, self.f1), (3, self.f2)]),
                  RunLengthList([(0, self.b1), (6, self.b2)])))
     assert colours == [(self.f1, self.b1), (self.f2, self.b2)]
Exemplo n.º 9
0
 def test_metalineReceived_calls_change_colour_for_overrun_colours(self):
     self.o.metalineReceived(
         Metaline("foo", RunLengthList([(0, self.f1), (3, self.f2)]),
                  RunLengthList([(0, self.b1), (6, self.b2)])))
     print self.o.method_calls
     assert self.o.method_calls == [("change_colour", (), {}),
                                    ("write_out_span", ("foo", ), {}),
                                    ("change_colour", (), {})]
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 def test_target_seen_highlighting(self):
     ml = Metaline('bar foo baz', RunLengthList([(0, 'foo')]),
                   RunLengthList([(0, 'bar')]))
     ti = TriggerMatchingRealm(ml, self.r, self.r, Mock())
     a = ti.alterer
     self.t.target_seen.func(mobj, ti)
     res = a.apply(ml)
     assert res.fores.items() == [(0, 'foo'), (4, fg_code(RED, True)),
                                  (7, 'foo')]
Exemplo n.º 13
0
 def test_metalineReceived_change_colour_mid_span_calls_change_colour(self):
     self.o.metalineReceived(
         Metaline("foobarbaz", RunLengthList([(0, self.f1), (3, self.f2)]),
                  RunLengthList([(0, self.b1), (6, self.b2)])))
     assert self.o.method_calls == [("change_colour", (), {}),
                                    ("write_out_span", ("foo", ), {}),
                                    ("change_colour", (), {}),
                                    ("write_out_span", ("bar", ), {}),
                                    ("change_colour", (), {}),
                                    ("write_out_span", ("baz", ), {})]
Exemplo n.º 14
0
 def test_highlights(self):
     m = Metaline("foo", RunLengthList([(0, 'foo')]),
                  RunLengthList([(0, 'bar')]))
     root = RootRealm(Mock(spec=TelnetClientFactory))
     realm = TriggerMatchingRealm(m, root, root, Mock())
     match = re.search('foobar', 'foobar')
     self.trig.func(match, realm)
     res = realm.alterer.apply(m)
     assert res.fores.items() == \
             [(0, HexFGCode(0x80, 0xFF, 0x80)),
              (6, 'foo')]
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 def parseline(self, line):
     """Interpret the VT100 codes in line and returns a Metaline, replete
     with RunLengthLists, that splits the text, foreground and background
     into three separate channels.
     """
     fores, backs, cleanline = self._parseline(line)
     rlfores = RunLengthList(((length, fg_code(colour, bold))
                              for (length, (colour, bold)) in fores),
                             _normalised=True)
     rlbacks = RunLengthList(
         ((length, bg_code(colour)) for (length, colour) in backs),
         _normalised=True)
     return Metaline(cleanline, rlfores, rlbacks)
Exemplo n.º 19
0
 def test_change_fore_with_trailing_colours(self):
     #don't know why, but this test exposed what looked like a quasi-random
     #failure...
     ml = Metaline(
         'foobars eggs.',
         RunLengthList([(0, fg_code(CYAN, False)),
                        (13, fg_code(WHITE, False))]),
         RunLengthList([(0, None)]))
     self.la.change_fore(0, 7, fg_code(RED, True))
     res = self.la.apply(ml)
     expected = [(0, fg_code(RED, True)), (7, fg_code(CYAN, False)),
                 (13, fg_code(WHITE, False))]
     assert res.fores.items() == expected, \
            res.fores.items()
Exemplo n.º 20
0
def test_health_update_matching():
    a = Autosipper(10, 10)
    ml = Metaline(' Health   : 5/5     Reserves : 5/5', None, None)
    assert list(a.health_update.match(ml))
Exemplo n.º 21
0
 def test_matches_on_equilibrium(self):
     assert list(
         self.trig.match(
             Metaline("You have recovered equilibrium.", None, None)))
Exemplo n.º 22
0
 def test_matches_on_balance(self):
     assert list(
         self.trig.match(
             Metaline("You have recovered balance on "
                      "all limbs.", None, None)))
Exemplo n.º 23
0
def test_returns_nothing_if_regex_is_None():
    f = non_binding_trigger(None)(None)
    res = list(f().match(Metaline('foobar', None, None)))
    assert not res
Exemplo n.º 24
0
 def setUp(self):
     self.la = LineAlterer()
     self.ml = Metaline('spam eggs ham',
                        RunLengthList([(0, 'A'), (2, 'B'), (4, 'C')]),
                        RunLengthList([(0, 'D'), (2, 'E'), (4, 'F')]))
Exemplo n.º 25
0
 def test_tell_received_matches_on_tells_in_languages(self):
     ml = Metaline('Foo tells you in Foolang, "Bar."',
                   None, None)
     assert list(self.tc.tell_received.match(ml))
Exemplo n.º 26
0
 def test_prompt_trigger_matches_on_prompt(self):
     ml = Metaline('42h, 23m, 5e, 17w cexkdb@-', None, None)
     assert list(self.rt.prompt_trigger.match(ml))
Exemplo n.º 27
0
 def test_herb_trigger_matches_multiple_times(self):
     ml = Metaline('[ 100] goldenseal root  [   2] ginseng root', None,
                   None)
     assert len(list(self.rt.herb_trigger.match(ml))) == 2
Exemplo n.º 28
0
 def test_herb_trigger_matches(self):
     ml = Metaline('[ 100] goldenseal root', None, None)
     assert list(self.rt.herb_trigger.match(ml))
Exemplo n.º 29
0
 def test_tell_sent_matches_on_tells_in_languages(self):
     ml = Metaline('You tell Mister Foo in Barlang, "Qux."',
                   None, None)
     assert list(self.tc.tell_sent.match(ml))
Exemplo n.º 30
0
 def test_tell_sent_pattern_is_not_greedy(self):
     ml = Metaline('You tell Foo, "Bar, "baz.""', None, None)
     match = list(self.tc.tell_sent.match(ml))
     assert match[0].group(1) == 'Foo'