Exemple #1
0
    def test_can_create(self, loadtargets_mock):
        instance = stackide.StackIDE(
            mock_window([cur_dir + '/mocks/helloworld/']), test_settings, FakeBackend())
        self.assertIsNotNone(instance)
        self.assertTrue(instance.is_active)
        self.assertTrue(instance.is_alive)

        # it got the load targets
        self.assertEqual(2, len(instance.include_targets))
Exemple #2
0
    def test_handle_welcome_stack_ide_outdated(self, loadtargets_mock):

        backend = MagicMock()
        welcome = {
                  "tag": "ResponseWelcome",
                  "contents": [0, 0, 0]
                  }

        instance = stackide.StackIDE(mock_window([cur_dir + '/projects/helloworld/']), test_settings, backend)
        instance.handle_response(welcome)
        self.assertEqual(sublime.current_error, "Please upgrade stack-ide to a newer version.")
Exemple #3
0
 def test_can_send_source_errors_request(self, loadtargets_mock):
     backend = FakeBackend()
     backend.send_request = Mock()
     instance = stackide.StackIDE(
         mock_window([cur_dir + '/mocks/helloworld/']), test_settings, backend)
     self.assertIsNotNone(instance)
     self.assertTrue(instance.is_active)
     self.assertTrue(instance.is_alive)
     req = Req.get_source_errors()
     instance.send_request(req)
     backend.send_request.assert_called_with(req)
Exemple #4
0
 def test_can_shutdown(self, loadtargets_mock):
     backend = FakeBackend()
     backend.send_request = Mock()
     instance = stackide.StackIDE(
         mock_window([cur_dir + '/projects/helloworld/']), test_settings, backend)
     self.assertIsNotNone(instance)
     self.assertTrue(instance.is_active)
     self.assertTrue(instance.is_alive)
     instance.end()
     self.assertFalse(instance.is_active)
     self.assertFalse(instance.is_alive)
     backend.send_request.assert_called_with(
         Req.get_shutdown())
Exemple #5
0
    def test_retains_live_instances(self):

        window = mock_window(['.'])
        sublime.add_window(window)

        StackIDEManager.check_windows()
        self.assertEqual(1, len(StackIDEManager.ide_backend_instances))

        # substitute a 'live' instance
        instance = stack_ide.StackIDE(window, test_settings, FakeBackend())
        StackIDEManager.ide_backend_instances[window.id()] = instance

        # instance should still exist.
        StackIDEManager.check_windows()
        self.assertEqual(1, len(StackIDEManager.ide_backend_instances))
        self.assertEqual(instance, StackIDEManager.ide_backend_instances[window.id()])

        sublime.destroy_windows()
Exemple #6
0
    def test_kills_live_orphans(self):
        window = sublime.create_window('.')
        StackIDEManager.check_windows()
        self.assertEqual(1, len(StackIDEManager.ide_backend_instances))

        # substitute a 'live' instance
        backend = MagicMock()
        stack_ide.stack_ide_loadtargets = Mock(return_value=['app/Main.hs', 'src/Lib.hs'])
        instance = stack_ide.StackIDE(window, test_settings, backend)
        StackIDEManager.ide_backend_instances[window.id()] = instance

        # close the window
        sublime.destroy_windows()

        # instance should be killed
        StackIDEManager.check_windows()
        self.assertEqual(0, len(StackIDEManager.ide_backend_instances))
        self.assertFalse(instance.is_alive)
        backend.send_request.assert_called_with(Req.get_shutdown())
Exemple #7
0
    def test_reset(self):
        window = mock_window(['.'])
        sublime.add_window(window)

        StackIDEManager.check_windows()
        self.assertEqual(1, len(StackIDEManager.ide_backend_instances))

        # substitute a 'live' instance
        backend = MagicMock()
        stack_ide.stack_ide_loadtargets = Mock(return_value=['app/Main.hs', 'src/Lib.hs'])
        instance = stack_ide.StackIDE(window, test_settings, backend)
        StackIDEManager.ide_backend_instances[window.id()] = instance

        StackIDEManager.reset()

        # instances should be shut down.
        self.assertEqual(1, len(StackIDEManager.ide_backend_instances))
        self.assertFalse(instance.is_alive)
        backend.send_request.assert_called_with(Req.get_shutdown())

        sublime.destroy_windows()
Exemple #8
0
 def test_handle_progress_update(self, loadtargets_mock):
     backend = MagicMock()
     instance = stackide.StackIDE(mock_window([cur_dir + '/projects/helloworld/']), test_settings, backend)
     instance.handle_response(status_progress_1)
     self.assertEqual(sublime.current_status, "Compiling Lib")