コード例 #1
0
    def test_performs_correct_action_when_deleted_staged_file_is_to_be_unstaged(self):
        orig_entry = IndexEntry('A', 'file.txt')
        new_entry = IndexEntry('D', 'file.txt')

        reflect_index_change(orig_entry, new_entry)

        self.perform_git_action.assert_called_once_with('reset', 'file.txt')
コード例 #2
0
    def test_performs_correct_action_when_modified_file_is_to_be_added(self):
        orig_entry = IndexEntry('M', 'file.txt')
        new_entry = IndexEntry('A', 'file.txt')

        reflect_index_change(orig_entry, new_entry)

        self.perform_git_action.assert_called_once_with(['add', '-f'], 'file.txt')
コード例 #3
0
    def test_str_returns_correct_representation_when_there_are_entries(self):
        index = Index([
            IndexEntry('M', 'file1.txt'),
            IndexEntry('?', 'file2.txt'),
            IndexEntry('!', 'file3.txt')
        ])

        # The last entry has to end with a newline. Otherwise, some editors may
        # have problems displaying it.
        self.assertEqual(str(index), 'M file1.txt\n? file2.txt\n! file3.txt\n')
コード例 #4
0
    def test_calls_reflect_index_change_for_correct_entries(self):
        entry1 = IndexEntry('M', 'file1.txt')
        entry2 = IndexEntry('M', 'file2.txt')
        entry3 = IndexEntry('?', 'file1.txt')
        orig_index = Index([entry1, entry2])
        new_index = Index([entry3, entry2])

        reflect_index_changes(orig_index, new_index)

        self.reflect_index_change.assert_called_once_with(entry1, entry3)
コード例 #5
0
    def test_performs_correct_action_when_modified_staged_file_is_to_be_partially_reset(self):
        orig_entry = IndexEntry('A', 'file.txt')
        new_entry = IndexEntry('P', 'file.txt')

        reflect_index_change(orig_entry, new_entry)

        self.perform_git_action.assert_called_once_with(
            ['reset', '--patch'],
            'file.txt',
            ignore_stdout=False
        )
コード例 #6
0
    def test_performs_correct_action_when_modified_file_is_to_be_reset(self):
        orig_entry = IndexEntry('M', 'file.txt')
        new_entry = NoIndexEntry('file.txt')

        reflect_index_change(orig_entry, new_entry)

        self.perform_git_action.assert_called_once_with('checkout', 'file.txt')
コード例 #7
0
    def test_performs_correct_action_when_ignored_file_is_to_be_deleted(self):
        orig_entry = IndexEntry('!', 'file.txt')
        new_entry = NoIndexEntry('file.txt')

        reflect_index_change(orig_entry, new_entry)

        self.remove.assert_called_once_with('file.txt')
        self.assertFalse(self.perform_git_action.called)
コード例 #8
0
    def test_does_not_reflect_changes_when_changes_should_not_be_reflected_on_empty_buffer(self):
        self.current_index.return_value = Index([IndexEntry('M', 'file.txt')])
        self.edit_index.return_value = Index()
        self.should_reflect_changes_on_empty_buffer.return_value = False

        main(['git-edit-index'])

        self.assertTrue(self.should_reflect_changes_on_empty_buffer.called)
        self.assertFalse(self.reflect_index_changes.called)
コード例 #9
0
    def test_performs_correct_actions_when_staged_file_is_to_be_reset(self):
        orig_entry = IndexEntry('A', 'file.txt')
        new_entry = NoIndexEntry('file.txt')

        reflect_index_change(orig_entry, new_entry)

        self.perform_git_action.assert_has_calls([
            mock.call('reset', 'file.txt'),
            mock.call('checkout', 'file.txt', ignore_stderr=True)
        ])
コード例 #10
0
    def test_shows_editor_to_user_and_reflects_changes_when_index_is_nonempty(self):
        orig_index = Index([IndexEntry('M', 'file.txt')])
        self.current_index.return_value = orig_index

        main(['git-edit-index'])

        self.edit_index.assert_called_once_with(orig_index)
        self.reflect_index_changes.assert_called_once_with(
            orig_index, self.edit_index.return_value
        )
コード例 #11
0
    def test_stores_index_to_file_and_shows_it_to_user_and_returns_new_index(self):
        index = Index([IndexEntry('M', 'file.txt')])
        self.editor_cmd.return_value = ['vim']
        tmp_fd = 123
        tmp_path = 'git-edit-index-temp'
        self.tempfile.mkstemp.return_value = tmp_fd, tmp_path
        tmp_f1 = self.os.fdopen.return_value.__enter__.return_value
        tmp_f2 = self.open.return_value.__enter__.return_value
        tmp_f2.read.return_value = 'A file.txt\n'

        new_index = edit_index(index)

        self.assertEqual(len(new_index), 1)
        self.assertEqual(new_index[0].status, 'A')
        self.assertEqual(new_index[0].file, 'file.txt')
        tmp_f1.write.assert_called_once_with('M file.txt\n')
        self.subprocess.call.assert_called_once_with(
            self.editor_cmd() + [tmp_path]
        )
        tmp_f2.read.assert_called_once_with()
        self.os.remove.assert_called_once_with(tmp_path)
コード例 #12
0
 def test_from_line_returns_none_for_empty_line(self):
     self.assertIsNone(IndexEntry.from_line(''))
コード例 #13
0
    def test_entry_for_returns_correct_entry_when_it_exists(self):
        entry = IndexEntry('M', 'file1.txt')
        index = Index([entry])

        self.assertEqual(index.entry_for('file1.txt'), entry)
コード例 #14
0
    def test_from_line_returns_correct_entry_for_custom_patch_status(self):
        entry = IndexEntry.from_line('P file.txt')

        self.assertEqual(entry.status, 'P')
        self.assertEqual(entry.file, 'file.txt')
コード例 #15
0
    def test_from_line_returns_correct_entry_for_untracked_file_git_format(self):
        entry = IndexEntry.from_line('?? file.txt')

        self.assertEqual(entry.status, '?')
        self.assertEqual(entry.file, 'file.txt')
コード例 #16
0
 def test_from_line_returns_none_for_unknown_status(self):
     self.assertIsNone(IndexEntry.from_line('# file.txt'))
コード例 #17
0
    def test_from_line_returns_correct_entry_for_modified_file_git_format(self):
        entry = IndexEntry.from_line(' M file.txt')

        self.assertEqual(entry.status, 'M')
        self.assertEqual(entry.file, 'file.txt')
コード例 #18
0
    def test_from_line_returns_correct_entry_for_custom_patch_status(self):
        entry = IndexEntry.from_line('P file.txt')

        self.assertEqual(entry.status, 'P')
        self.assertEqual(entry.file, 'file.txt')
コード例 #19
0
    def test_from_line_returns_correct_entry_for_untracked_file_git_format(self):
        entry = IndexEntry.from_line('?? file.txt')

        self.assertEqual(entry.status, '?')
        self.assertEqual(entry.file, 'file.txt')
コード例 #20
0
    def test_str_returns_correct_representation(self):
        entry = IndexEntry('M', 'file.txt')

        self.assertEqual(str(entry), 'M file.txt')
コード例 #21
0
    def test_from_line_ignores_case_of_status(self):
        entry = IndexEntry.from_line('a file.txt')

        self.assertEqual(entry.status, 'A')
        self.assertEqual(entry.file, 'file.txt')
コード例 #22
0
 def test_from_line_returns_none_for_unknown_status(self):
     self.assertIsNone(IndexEntry.from_line('# file.txt'))
コード例 #23
0
 def test_from_line_returns_none_for_empty_line(self):
     self.assertIsNone(IndexEntry.from_line(''))
コード例 #24
0
    def test_from_line_returns_correct_entry_for_modified_file_git_format(self):
        entry = IndexEntry.from_line(' M file.txt')

        self.assertEqual(entry.status, 'M')
        self.assertEqual(entry.file, 'file.txt')
コード例 #25
0
    def test_status_and_file_are_accessible_after_creation(self):
        entry = IndexEntry('M', 'file.txt')

        self.assertEqual(entry.status, 'M')
        self.assertEqual(entry.file, 'file.txt')
コード例 #26
0
    def test_from_line_returns_correct_entry_for_ignored_file_our_format(self):
        entry = IndexEntry.from_line('! file.txt')

        self.assertEqual(entry.status, '!')
        self.assertEqual(entry.file, 'file.txt')
コード例 #27
0
    def test_from_line_returns_correct_entry_for_ignored_file_our_format(self):
        entry = IndexEntry.from_line('! file.txt')

        self.assertEqual(entry.status, '!')
        self.assertEqual(entry.file, 'file.txt')
コード例 #28
0
    def test_from_line_ignores_case_of_status(self):
        entry = IndexEntry.from_line('a file.txt')

        self.assertEqual(entry.status, 'A')
        self.assertEqual(entry.file, 'file.txt')
コード例 #29
0
    def test_repr_returns_correct_representation(self):
        index = Index([IndexEntry('M', 'file1.txt')])

        self.assertEqual(repr(index), "Index([IndexEntry('M', 'file1.txt')])")