Пример #1
0
class TestServer(unittest.TestCase):
    """
    Tests the other functions of Server class. Some functions are only
    appropriate for functional tests.
    """
    def setUp(self):
        self.vim = Server()

    def tearDown(self):
        try:
            # not all tests start a vim server
            self.vim.kill()
        except AttributeError:
            # no vim server was started in this test case
            pass

    def test_start_creates_server(self):
        try:
            # these try:except have increased by 4 times the testing time
            # because of timeout....
            self.vim.start(timeout=5)
        except RuntimeError:
            # raised because timeout expires - no server exists, because
            # we're testing
            pass
        # .start() creates a runtime attribute: server
        self.assertTrue(hasattr(self.vim, 'server'))

    def test_server_arguments(self):
        "Test the default arguments that are sent to multiprocessing.Process."
        try:
            self.vim.start(testing=True)
        except RuntimeError:
            # raised because timeout expires - no server exists, because
            # we're testing
            pass
        self.assertTrue(find_executable('vim') in self.vim.cmd)
        self.assertTrue('-n' in self.vim.cmd)
        self.assertTrue('--noplugin' in self.vim.cmd)
        self.assertTrue('--servername' in self.vim.cmd)

    def test_start_headless(self):
        try:
            self.vim.start_headless(testing=False, timeout=5)
        except RuntimeError:
            return
        self.assertTrue(self.vim.is_running())
        self.vim.quit()
        self.assertFalse(self.vim.is_running())

    def test_start_gvim(self):
        #self.vim.start(testing=True)
        # this test might pass or not, depending if the user has gvim installed
        try:
            path = check_output(['which', 'gvim'])
            path = path.decode('utf-8').strip('\n')
        except subprocess.CalledProcessError:
            return unittest.skip("gvim might not be installed, so this test "
                                 "won't pass")
        # TODO: self.vim.start_gvim()

    def test_kill_called_before_start(self):
        """Can't kill server because it is created after .start() is called.
        """
        self.assertRaises(AttributeError, self.vim.kill)

    def test_no_vimrunner_in_server_list(self):
        # No vimrunner server is started
        vimrunner_list = [server for server in self.vim.server_list()
                          if server.startswith('VIMRUNNER#')]
        self.assertEqual(vimrunner_list, [])

    def test_is_running_when_no_server_exists(self):
        self.assertFalse(self.vim.is_running())

    def test_is_running_when_server_exists(self):
        "This test also tests when vim is started in other terminal"
        #self.vim.start()
        self.vim.start_in_other_terminal()
        self.assertTrue(self.vim.is_running())
        time.sleep(2)
        self.vim.quit()
        pass

    def test_start(self):
        #self.vim.start()
        pass
Пример #2
0
class TestServer(unittest.TestCase):
    """
    Tests the other functions of Server class. Some functions are only
    appropriate for functional tests.
    """
    def setUp(self):
        self.vim = Server()

    def tearDown(self):
        try:
            # not all tests start a vim server
            self.vim.kill()
        except AttributeError:
            # no vim server was started in this test case
            pass

    def test_start_creates_server(self):
        try:
            # these try:except have increased by 4 times the testing time
            # because of timeout....
            self.vim.start(testing=True, timeout=5)
        except RuntimeError:
            # raised because timeout expires - no server exists, because
            # we're testing
            pass
        # .start() creates a runtime attribute: server
        self.assertTrue(hasattr(self.vim, 'server'))

    def test_server_arguments(self):
        "Test the default arguments that are sent to multiprocessing.Process."
        try:
            self.vim.start(testing=True)
        except RuntimeError:
            # raised because timeout expires - no server exists, because
            # we're testing
            pass
        self.assertTrue('/usr/bin/vim' in self.vim.server._args[0])
        self.assertTrue('-n' in self.vim.server._args[0])
        self.assertTrue('--noplugin' in self.vim.server._args[0])
        self.assertTrue('--servername' in self.vim.server._args[0])
        # server._args is a tuple which needs unpacking to get a list

    def test_start_gvim(self):
        #self.vim.start(testing=True)
        # this test might pass or not, depending if the user has gvim installed
        try:
            path = subprocess.check_output(['which', 'gvim'])
            path = path.decode('utf-8').strip('\n')
        except subprocess.CalledProcessError:
            return unittest.skip("gvim might not be installed, so this test "
                                 "won't pass")
        # TODO: self.vim.start_gvim()

    def test_kill_called_before_start(self):
        """Can't kill server because it is created after .start() is called.
        """
        self.assertRaises(AttributeError, self.vim.kill)

    def test_server_list_is_empty(self):
        # server is not started yet
        self.assertEqual([''], self.vim.server_list())

    def test_is_running_when_no_server_exists(self):
        self.assertFalse(self.vim.is_running())

    def test_is_running_when_server_exists(self):
        "This test also tests when vim is started in other terminal"
        #self.vim.start()
        self.vim.start_in_other_terminal()
        self.assertTrue(self.vim.is_running())
        time.sleep(2)
        self.vim.quit()
        pass

    def test_start(self):
        #self.vim.start()
        pass