def check_final_diff(self, ignore=None, diff=None):
        if diff is None:
            diff = self.run_command(
                Command('git diff -w repo/{}'.format(self.chapter_name)))
        try:
            print('checking final diff', diff)
        except io.BlockingIOError:
            pass
        self.assertNotIn('fatal:', diff)
        start_marker = 'diff --git a/\n'
        commit = Commit.from_diff(start_marker + diff)

        if ignore is None:
            if commit.lines_to_add:
                self.fail('Found lines to add in diff:\n{}'.format(
                    commit.lines_to_add))
            if commit.lines_to_remove:
                self.fail('Found lines to remove in diff:\n{}'.format(
                    commit.lines_to_remove))
            return

        if "moves" in ignore:
            ignore.remove("moves")
            difference_lines = commit.deleted_lines + commit.new_lines
        else:
            difference_lines = commit.lines_to_add + commit.lines_to_remove

        for line in difference_lines:
            if any(ignorable in line for ignorable in ignore):
                continue
            self.fail('Found divergent line in diff:\n{}'.format(line))
Example #2
0
    def check_final_diff(self, ignore=None, diff=None):
        if diff is None:
            diff = self.run_command(
                Command('git diff -w repo/chapter_{0:02d}'.format(
                    self.chapter_no)))
        try:
            print('checking final diff', diff)
        except io.BlockingIOError:
            pass
        self.assertNotIn('fatal:', diff)
        start_marker = 'diff --git a/\n'
        commit = Commit.from_diff(start_marker + diff)
        error = AssertionError(
            'Final diff was not empty, was:\n{}'.format(diff))

        if ignore is None:
            if commit.lines_to_add or commit.lines_to_remove:
                raise error
            return

        if "moves" in ignore:
            ignore.remove("moves")
            difference_lines = commit.deleted_lines + commit.new_lines
        else:
            difference_lines = commit.lines_to_add + commit.lines_to_remove

        for line in difference_lines:
            if any(ignorable in line for ignorable in ignore):
                continue
            raise error
Example #3
0
    def check_final_diff(
        self, chapter, ignore_moves=False, ignore_secret_key=False,
        diff=None
    ):
        if diff is None:
            diff = self.run_command(Command(
                'git diff -b repo/chapter_{0:02d}'.format(chapter)
            ))
        try:
            print('checking final diff', diff)
        except io.BlockingIOError:
            pass
        self.assertNotIn('fatal:', diff)
        start_marker = 'diff --git a/\n'
        commit = Commit.from_diff(start_marker + diff)
        error = AssertionError('Final diff was not empty, was:\n{}'.format(diff))

        if ignore_secret_key:
            for line in commit.lines_to_add + commit.lines_to_remove:
                if 'SECRET_KEY' not in line:
                    raise error

        elif ignore_moves:
            if commit.deleted_lines or commit.new_lines:
                raise AssertionError(
                    'Found lines to delete or add in diff.\nto delete:\n{}\n\nto add:\n{}'.format(
                        '\n- '.join(commit.deleted_lines), '\n+'.join(commit.new_lines)
                    )
                )

        elif commit.lines_to_add or commit.lines_to_remove:
            raise error
Example #4
0
    def check_final_diff(self,
                         chapter,
                         ignore_moves=False,
                         ignore_secret_key=False,
                         diff=None):
        if diff is None:
            diff = self.run_command(
                Command('git diff -b repo/chapter_{0:02d}'.format(chapter)))
        try:
            print('checking final diff', diff)
        except io.BlockingIOError:
            pass
        self.assertNotIn('fatal:', diff)
        start_marker = 'diff --git a/\n'
        commit = Commit.from_diff(start_marker + diff)
        error = AssertionError(
            'Final diff was not empty, was:\n{}'.format(diff))

        if ignore_secret_key:
            for line in commit.lines_to_add + commit.lines_to_remove:
                if 'SECRET_KEY' not in line:
                    raise error

        elif ignore_moves:
            if commit.deleted_lines or commit.new_lines:
                raise AssertionError(
                    'Found lines to delete or add in diff.\nto delete:\n{}\n\nto add:\n{}'
                    .format('\n- '.join(commit.deleted_lines),
                            '\n+'.join(commit.new_lines)))

        elif commit.lines_to_add or commit.lines_to_remove:
            raise error
Example #5
0
    def check_final_diff(self, ignore=None, diff=None):
        if diff is None:
            diff = self.run_command(Command(
                'git diff -w repo/chapter_{0:02d}'.format(self.chapter_no)
            ))
        try:
            print('checking final diff', diff)
        except io.BlockingIOError:
            pass
        self.assertNotIn('fatal:', diff)
        start_marker = 'diff --git a/\n'
        commit = Commit.from_diff(start_marker + diff)
        error = AssertionError('Final diff was not empty, was:\n{}'.format(diff))

        if ignore is None:
            if commit.lines_to_add or commit.lines_to_remove:
                raise error
            return

        if "moves" in ignore:
            ignore.remove("moves")
            difference_lines = commit.deleted_lines + commit.new_lines
        else:
            difference_lines = commit.lines_to_add + commit.lines_to_remove

        for line in difference_lines:
            if any(ignorable in line for ignorable in ignore):
                continue
            raise error
    def check_final_diff(self, ignore=None, diff=None):
        if diff is None:
            diff = self.run_command(Command(
                'git diff -w repo/{}'.format(self.chapter_name)
            ))
        try:
            print('checking final diff', diff)
        except io.BlockingIOError:
            pass
        self.assertNotIn('fatal:', diff)
        start_marker = 'diff --git a/\n'
        commit = Commit.from_diff(start_marker + diff)

        if ignore is None:
            if commit.lines_to_add:
                self.fail('Found lines to add in diff:\n{}'.format(commit.lines_to_add))
            if commit.lines_to_remove:
                self.fail('Found lines to remove in diff:\n{}'.format(commit.lines_to_remove))
            return

        if "moves" in ignore:
            ignore.remove("moves")
            difference_lines = commit.deleted_lines + commit.new_lines
        else:
            difference_lines = commit.lines_to_add + commit.lines_to_remove

        for line in difference_lines:
            if any(ignorable in line for ignorable in ignore):
                continue
            self.fail('Found divergent line in diff:\n{}'.format(line))
Example #7
0
    def test_init_from_example(self):
        example = dedent("""
            commit 9ecbb2c2222b9b31ab21e51e42ed8179ec79b273
            Author: Harry <*****@*****.**>
            Date:   Thu Aug 22 20:26:09 2013 +0100

                Some comment text. --ch09l021--

                Conflicts:
                    lists/tests/test_views.py

            diff --git a/lists/tests/test_views.py b/lists/tests/test_views.py
            index 8e18d77..03fc675 100644
            --- a/lists/tests/test_views.py
            +++ b/lists/tests/test_views.py
            @@ -55,36 +55,6 @@ class NewListTest(TestCase):



            -class NewItemTest(TestCase):
            -
            -    def test_can_save_a_POST_request_to_an_existing_list(self):
            -        other_list = List.objects.create()
            -        correct_list = List.objects.create()
            -        self.assertEqual(new_item.list, correct_list)
            -
            -
            -    def test_redirects_to_list_view(self):
            -        other_list = List.objects.create()
            -        correct_list = List.objects.create()
            -        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))
            -
            -
            -
             class ListViewTest(TestCase):

                 def test_list_view_passes_list_to_list_template(self):
            @@ -112,3 +82,29 @@ class ListViewTest(TestCase):
                     self.assertNotContains(response, 'other list item 1')
                     self.assertNotContains(response, 'other list item 2')

            +
            +    def test_can_save_a_POST_request_to_an_existing_list(self):
            +        other_list = List.objects.create()
            +        correct_list = List.objects.create()
            +        self.assertEqual(new_item.list, correct_list)
            +
            +
            +    def test_POST_redirects_to_list_view(self):
            +        other_list = List.objects.create()
            +        correct_list = List.objects.create()
            +        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))
            + """)

        commit = Commit.from_diff(example)

        assert commit.info == example

        assert commit.lines_to_add == [
            "    def test_can_save_a_POST_request_to_an_existing_list(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertEqual(new_item.list, correct_list)",
            "    def test_POST_redirects_to_list_view(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))",
        ]

        assert commit.lines_to_remove == [
            "class NewItemTest(TestCase):",
            "    def test_can_save_a_POST_request_to_an_existing_list(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertEqual(new_item.list, correct_list)",
            "    def test_redirects_to_list_view(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))",
        ]

        assert commit.moved_lines == [
            "    def test_can_save_a_POST_request_to_an_existing_list(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertEqual(new_item.list, correct_list)",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))",
        ]

        assert commit.deleted_lines == [
            "class NewItemTest(TestCase):",
            "    def test_redirects_to_list_view(self):",
        ]

        assert commit.new_lines == [
            "    def test_POST_redirects_to_list_view(self):",
        ]
    def test_init_from_example(self):
        example = dedent(
            """
            commit 9ecbb2c2222b9b31ab21e51e42ed8179ec79b273
            Author: Harry <*****@*****.**>
            Date:   Thu Aug 22 20:26:09 2013 +0100

                Some comment text. --ch09l021--

                Conflicts:
                    lists/tests/test_views.py

            diff --git a/lists/tests/test_views.py b/lists/tests/test_views.py
            index 8e18d77..03fc675 100644
            --- a/lists/tests/test_views.py
            +++ b/lists/tests/test_views.py
            @@ -55,36 +55,6 @@ class NewListTest(TestCase):



            -class NewItemTest(TestCase):
            -
            -    def test_can_save_a_POST_request_to_an_existing_list(self):
            -        other_list = List.objects.create()
            -        correct_list = List.objects.create()
            -        self.assertEqual(new_item.list, correct_list)
            -
            -
            -    def test_redirects_to_list_view(self):
            -        other_list = List.objects.create()
            -        correct_list = List.objects.create()
            -        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))
            -
            -
            -
             class ListViewTest(TestCase):

                 def test_list_view_passes_list_to_list_template(self):
            @@ -112,3 +82,29 @@ class ListViewTest(TestCase):
                     self.assertNotContains(response, 'other list item 1')
                     self.assertNotContains(response, 'other list item 2')

            +
            +    def test_can_save_a_POST_request_to_an_existing_list(self):
            +        other_list = List.objects.create()
            +        correct_list = List.objects.create()
            +        self.assertEqual(new_item.list, correct_list)
            +
            +
            +    def test_POST_redirects_to_list_view(self):
            +        other_list = List.objects.create()
            +        correct_list = List.objects.create()
            +        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))
            + """
        )

        commit = Commit.from_diff(example)

        assert commit.info == example

        assert commit.lines_to_add == [
            "    def test_can_save_a_POST_request_to_an_existing_list(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertEqual(new_item.list, correct_list)",
            "    def test_POST_redirects_to_list_view(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))",
        ]

        assert commit.lines_to_remove == [
            "class NewItemTest(TestCase):",
            "    def test_can_save_a_POST_request_to_an_existing_list(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertEqual(new_item.list, correct_list)",
            "    def test_redirects_to_list_view(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))",
        ]

        assert commit.moved_lines == [
            "    def test_can_save_a_POST_request_to_an_existing_list(self):",
            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertEqual(new_item.list, correct_list)",

            "        other_list = List.objects.create()",
            "        correct_list = List.objects.create()",
            "        self.assertRedirects(response, '/lists/%d/' % (correct_list.id,))",
        ]

        assert commit.deleted_lines == [
            "class NewItemTest(TestCase):",
            "    def test_redirects_to_list_view(self):",
        ]

        assert commit.new_lines == [
            "    def test_POST_redirects_to_list_view(self):",
        ]