Exemplo n.º 1
0
    def test_strict_and_force_with_stash_pop_error(self, m_get_lines, m_sortimports, m_stash_unstaged, m_check_call):
        m_get_lines.return_value = [
            'file1.py',
            'file2.py',
        ]
        # Make the stash report as being unable to pop cleanly.
        m_stash_unstaged.__enter__.return_value = mock.Mock(success=False)

        # Strict is enabled, so should return the errors
        errors = isort_git_hook(strict=True, force=True)

        assert m_get_lines.called

        m_sortimports.assert_has_calls([
            # Should only be called once - inside the context
            # manager. Should not apply these again outside after the
            # stash-pop as it did not apply cleanly. We do not want to
            # run isort on a file with conflicts.
            mock.call('file1.py'),
            mock.call('file2.py'),
        ])

        m_check_call.assert_has_calls([
            mock.call(['git', 'add', 'file1.py']),
            mock.call(['git', 'add', 'file2.py']),
        ])

        assert m_stash_unstaged.called_with(is_needed=True)

        assert errors == 0
Exemplo n.º 2
0
    def test_not_strict_not_force_with_no_errors(self, m_get_lines, m_sortimports, m_get_output, m_stash_unstaged):
        m_get_lines.return_value = [
            'file1.py',
            'file2.py',
        ]
        m_stash_unstaged.__enter__.return_value = mock.Mock(success=True)

        errors = isort_git_hook(strict=False, force=False)

        assert m_get_lines.called

        m_get_output.assert_has_calls([
            mock.call('git show :file1.py'),
            mock.call('git show :file2.py'),
        ])

        m_sortimports.assert_has_calls([
            mock.call(
                file_path='file1.py',
                file_contents=u'content',
                check=True),
            mock.call(
                file_path='file2.py',
                file_contents=u'content',
                check=True),
        ])

        assert m_stash_unstaged.called_with(is_needed=False)

        assert errors == 0
Exemplo n.º 3
0
    def test_strict_and_force_with_no_errors(self, m_get_lines, m_sortimports, m_stash_unstaged, m_check_call):
        m_get_lines.return_value = [
            'file1.py',
            'file2.py',
        ]
        m_stash_unstaged.__enter__.return_value = mock.Mock(success=True)

        # Strict is enabled, so should return the errors
        errors = isort_git_hook(strict=True, force=True)

        assert m_get_lines.called

        m_sortimports.assert_has_calls([
            # Should get called twice, once when sorting inside the
            # context manager, then again outside after the stash is
            # popped.
            mock.call('file1.py'),
            mock.call('file2.py'),
            mock.call('file1.py'),
            mock.call('file2.py'),
        ])

        m_check_call.assert_has_calls([
            mock.call(['git', 'add', 'file1.py']),
            mock.call(['git', 'add', 'file2.py']),
        ])

        assert m_stash_unstaged.called_with(is_needed=True)

        assert errors == 0