Exemple #1
0
    def test_environ_editor(self):
        file_dict = {self.fb: ['1\n', '2\n', '3\n']}
        diff_dict = {}
        subprocess.call = self.fake_edit
        with open(self.fb, 'w') as handle:
            handle.writelines(file_dict[self.fb])
        result = Result.from_values('origin', 'msg', self.fb)

        # Some users have the ``EDITOR`` environment variable set, so
        # we should remove that temporarily.
        if 'EDITOR' in os.environ:
            del os.environ['EDITOR']
            reload(coalib.results.result_actions.OpenEditorAction)

        # Currently an ``editor`` param is required, so this will raise
        # a ``TypeError``.
        from coalib.results.result_actions.OpenEditorAction import (
            OpenEditorAction)
        action = OpenEditorAction()
        with self.assertRaises(TypeError):
            action.apply(result, file_dict, diff_dict)

        # If we reload the module after setting the ``$EDITOR`` variable,
        # we should be able apply the action without an explicit variable.
        os.environ['EDITOR'] = 'vim'
        reload(coalib.results.result_actions.OpenEditorAction)
        from coalib.results.result_actions.OpenEditorAction import (
            OpenEditorAction)
        action = OpenEditorAction()
        action.apply(result, file_dict, diff_dict)
Exemple #2
0
    def test_environ_editor(self):
        old_environ = os.environ

        file_dict = {self.fb: ['1\n', '2\n', '3\n']}
        diff_dict = {}
        subprocess.call = self.fake_edit
        with open(self.fb, 'w') as handle:
            handle.writelines(file_dict[self.fb])
        result = Result.from_values('origin', 'msg', self.fb)

        # Currently an ``editor`` param is required, so this will raise
        # a ``TypeError``.
        from coalib.results.result_actions.OpenEditorAction import (
            OpenEditorAction)
        action = OpenEditorAction()
        with self.assertRaises(TypeError):
            action.apply(result, file_dict, diff_dict)

        # If we reload the module after setting the ``$EDITOR`` variable,
        # we should be able apply the action without an explicit variable.
        os.environ['EDITOR'] = 'vim'
        reload(coalib.results.result_actions.OpenEditorAction)
        from coalib.results.result_actions.OpenEditorAction import (
            OpenEditorAction)
        action = OpenEditorAction()
        action.apply(result, file_dict, diff_dict)

        os.environ = old_environ
Exemple #3
0
 def test_open_files_at_position_vim(self):
     uut = OpenEditorAction()
     result_mock = Result.from_values(
         'test', '', self.fa, line=12, column=8,
     )
     with unittest.mock.patch('subprocess.call') as call:
         uut.apply(result_mock, {self.fa: ''}, {}, editor='vim')
         call.assert_called_with(
             ['vim', self.fa, '+12']
         )
Exemple #4
0
 def test_open_files_at_position_no_position(self):
     uut = OpenEditorAction()
     result_mock = Result.from_values(
         'test', '', self.fa, line=None, column=None,
     )
     with unittest.mock.patch('subprocess.call') as call:
         uut.apply(result_mock, {self.fa: ''}, {}, editor='subl')
         call.assert_called_with(
             ['subl', '--wait', '{0}:1:1'.format(self.fa)],
             stdout=subprocess.PIPE
         )
Exemple #5
0
    def test_unknown_editor_warning(self):
        logger = logging.getLogger()
        uut = OpenEditorAction()
        result_mock = Result.from_values(
            'test', '', self.fa, line=None, column=None,
        )
        with unittest.mock.patch('subprocess.call'):
            with self.assertLogs(logger, 'WARNING') as log:
                uut.apply(result_mock, {self.fa: ''}, {}, editor='gouda-edit')

                self.assertEqual(1, len(log.output))
                self.assertIn(
                    'The editor "gouda-edit" is unknown to coala.',
                    log.output[0]
                )