示例#1
0
 def test_init_readline(self, mock_readline):
     pymp = pythonrc.ImprovedConsole()
     for method in [
             mock_readline.set_history_length, mock_readline.parse_and_bind,
             mock_readline.set_completer, mock_readline.set_pre_input_hook,
             mock_readline.read_init_file
     ]:
         method.assert_called_once()
示例#2
0
 def setUp(self):
     _, pythonrc.config.HISTFILE = tempfile.mkstemp()
     self.pymp = pythonrc.ImprovedConsole()
     pythonrc.config.EDITOR = 'vi'
     pythonrc.config.EDIT_CMD = r'\e'
     pythonrc.config.LIST_CMD = r'\l'
     # py27 compatibility
     if not hasattr(self, 'assertRegex'):
         self.assertRegex = self.assertRegexpMatches
示例#3
0
    def test_exec_from_file(self):
        """Test exec from file with multiple newlines in code blocks"""
        pymp = pythonrc.ImprovedConsole()
        tempfl = StringIO(EDIT_CMD_TEST_LINES)
        with patch.object(sys, 'stderr', new_callable=StringIO):
            pymp._exec_from_file(tempfl)

        self.assertIn('Foo', pymp.locals)
        self.assertIn('first', pymp.locals['Foo'].__dict__)
        self.assertIn('second', pymp.locals['Foo'].__dict__)
        self.assertIn('x', pymp.locals)
        self.assertIn('f', pymp.locals)
        self.assertEqual(pymp.locals['x'], 43)
        self.assertNotIn('z', pymp.locals)

        with tempfile.NamedTemporaryFile(mode='w') as tempfl:
            pythonrc.readline.write_history_file(tempfl.name)
            expected = filter(None, EDIT_CMD_TEST_LINES.splitlines()[:-1])
            recieved = filter(None, map(str.rstrip, open(tempfl.name)))
            self.assertEqual(list(expected), list(recieved))
示例#4
0
    def test_exec_from_file(self):
        """Test exec from file with multiple newlines in code blocks"""
        pymp = pythonrc.ImprovedConsole()
        with tempfile.NamedTemporaryFile(mode='w', delete=False) as tempfl:
            tempfl.write(EDIT_CMD_TEST_LINES)
            tempfl.close()
            pymp._exec_from_file(tempfl.name)
            os.unlink(tempfl.name)

            self.assertIn('Foo', pymp.locals)
            self.assertIn('first', pymp.locals['Foo'].__dict__)
            self.assertIn('second', pymp.locals['Foo'].__dict__)
            self.assertIn('x', pymp.locals)
            self.assertIn('f', pymp.locals)
            self.assertEqual(pymp.locals['x'], 43)

        with tempfile.NamedTemporaryFile(mode='w') as tempfl:
            pythonrc.readline.write_history_file(tempfl.name)
            expected = filter(None, EDIT_CMD_TEST_LINES.splitlines())
            recieved = filter(None, map(str.rstrip, open(tempfl.name)))
            self.assertEqual(list(expected), list(recieved))
示例#5
0
 def setUp(self):
     _, pythonrc.config['HISTFILE'] = tempfile.mkstemp()
     self.pymp = pythonrc.ImprovedConsole()
示例#6
0
 def test_libedit_readline(self, mock_readline):
     mock_readline.__doc__ = 'libedit'
     pythonrc.ImprovedConsole()
     mock_readline.parse_and_bind.assert_called_once_with(
         'bind ^I rl_complete')
示例#7
0
 def setUp(self):
     _, pythonrc.config['HISTFILE'] = tempfile.mkstemp()
     self.pymp = pythonrc.ImprovedConsole()
     pythonrc.config['EDITOR'] = 'vi'
     pythonrc.config['EDIT_CMD'] = '\e'
     pythonrc.config['LIST_CMD'] = '\l'