def test_simple_expand(self): self.repl.s = "f" self.cpos = 0 self.repl.matches_iter = mock.Mock() self.repl.matches_iter.is_cseq.return_value = True self.repl.matches_iter.substitute_cseq.return_value = (3, "foo") self.repl.print_line = mock.Mock() self.repl.tab() self.assertEqual(self.repl.s, "foo")
def test_normal_tab(self): """make sure pressing the tab key will still in some cases add a tab""" self.repl.s = "" self.repl.config = mock.Mock() self.repl.config.tab_length = 4 self.repl.complete = mock.Mock() self.repl.print_line = mock.Mock() self.repl.tab() self.assertEqual(self.repl.s, " ")
def test_back_parameter(self): self.repl.matches_iter = mock.Mock() self.repl.matches_iter.matches = True self.repl.matches_iter.previous.return_value = "previtem" self.repl.matches_iter.is_cseq.return_value = False self.repl.show_list = mock.Mock() self.repl.argspec = mock.Mock() self.repl.matches_iter.cur_line.return_value = (None, "previtem") self.repl.print_line = mock.Mock() self.repl.s = "foo" self.repl.cpos = 0 self.repl.tab(back=True) self.assertTrue(self.repl.matches_iter.previous.called) self.assertTrue(self.repl.s, "previtem")
def completer( self, matches, ): mock_completer = autocomplete.BaseCompletionType() mock_completer.matches = mock.Mock(return_value=matches) return mock_completer
def test_simple_tab_complete(self): self.repl.matches_iter = MagicIterMock() if py3: self.repl.matches_iter.__bool__.return_value = False else: self.repl.matches_iter.__nonzero__.return_value = False self.repl.complete = mock.Mock() self.repl.print_line = mock.Mock() self.repl.matches_iter.is_cseq.return_value = False self.repl.show_list = mock.Mock() self.repl.argspec = mock.Mock() self.repl.matches_iter.cur_line.return_value = (None, "foobar") self.repl.s = "foo" self.repl.tab() self.assertTrue(self.repl.complete.called) self.repl.complete.assert_called_with(tab=True) self.assertEqual(self.repl.s, "foobar")
def setUp(self): self.repl = create_repl() self.repl.matches_iter = MagicIterMock() def add_matches(*args, **kwargs): self.repl.matches_iter.matches = ['aaa', 'aab', 'aac'] self.repl.complete = mock.Mock(side_effect=add_matches, return_value=True)
def test_addstr(self): self.repl.complete = mock.Mock(True) self.repl.s = "foo" self.repl.addstr("bar") self.assertEqual(self.repl.s, "foobar") self.repl.cpos = 3 self.repl.addstr('buzz') self.assertEqual(self.repl.s, "foobuzzbar")
def test_update(self): slice = islice(self.matches_iterator, 0, 3) self.assertEqual(list(slice), self.matches) newmatches = ['string', 'str', 'set'] completer = mock.Mock() completer.locate.return_value = (0, 1, 's') self.matches_iterator.update(1, 's', newmatches, completer) newslice = islice(newmatches, 0, 3) self.assertNotEqual(list(slice), self.matches) self.assertEqual(list(newslice), newmatches)
def test_cur_line(self): completer = mock.Mock() completer.locate.return_value = ( 0, self.matches_iterator.orig_cursor_offset, self.matches_iterator.orig_line) self.matches_iterator.completer = completer self.assertRaises(ValueError, self.matches_iterator.cur_line) self.assertEqual(next(self.matches_iterator), self.matches[0]) self.assertEqual(self.matches_iterator.cur_line(), (len(self.matches[0]), self.matches[0]))
def test_runsource_bytes_over_128_syntax_error_py3(self): i = interpreter.Interp(encoding='latin-1') i.showsyntaxerror = mock.Mock(return_value=None) i.runsource("a = b'\xfe'", encode=True) i.showsyntaxerror.assert_called_with(mock.ANY)
def setUp(self): self.module = ModuleChangedEventHandler([], 1) self.module.observer = mock.Mock()
def test_bytes(self): out = FakeOutput(mock.Mock(), self.assert_unicode, None) out.write("native string type")