def test_from_real_git_stuff(self):
        listing = CodeListing(
            filename="file1.txt",
            contents=dedent(
                """
            file 1 line 2 amended
            file 1 line 3
            """
            ).lstrip(),
        )
        listing.commit_ref = "ch17l021"

        self.sourcetree.apply_listing_from_commit(listing)

        with open(self.sourcetree.tempdir + "/superlists/file1.txt") as f:
            assert (
                f.read()
                == dedent(
                    """
                file 1 line 1
                file 1 line 2 amended
                file 1 line 3
                """
                ).lstrip()
            )

        assert listing.was_written
    def test_with_diff_listing_failure_case(self):
        listing = CodeListing(
            filename="file2.txt",
            contents=dedent(
                """
            diff --git a/file2.txt b/file2.txt
            index 93f054e..519d518 100644
            --- a/file2.txt
            +++ b/file2.txt
            @@ -4,6 +4,5 @@ another line changed
             some duplicate lines coming up...

             hello
            -hello
            +something else

             one more line at end
             """
            ).lstrip(),
        )
        listing.commit_ref = "ch17l030"
        self._checkout_commit("ch17l029")

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_listing_doesnt_show_all_new_lines_in_diff(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 3
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
Beispiel #4
0
    def test_happy_with_lines_from_just_before_diff(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 1
            file 1 line 2 amended
            file 1 line 3
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_listing_lines_in_wrong_order(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 3
            file 1 line 2 amended
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_blank_lines(self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            file 2 line 1 changed

            another line changed
            """).lstrip())
        listing.commit_ref = 'ch17l024'
        self._checkout_commit('ch17l023')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_any_other_listing_lines_not_in_before_version(self):
        listing = CodeListing(filename='file1.txt',
                              contents=dedent("""
            what is this?
            file 1 line 2 amended
            file 1 line 3
            """).lstrip())
        listing.commit_ref = 'ch17l021'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_too_many_files_in_commit(self):
        listing = CodeListing(filename='file1.txt',
                              contents=dedent("""
            file 1 line 1
            file 1 line 2
            """).lstrip())
        listing.commit_ref = 'ch17l023'

        self._checkout_commit('ch17l022')
        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_lines_from_just_before_diff(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 1
            file 1 line 2 amended
            file 1 line 3
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_js_callouts(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            [...]
            file 1 line 2 amended //
            file 1 line 3 //
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #11
0
    def test_raises_if_listing_lines_in_wrong_order(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 3
            file 1 line 2 amended
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_js_callouts(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            [...]
            file 1 line 2 amended //
            file 1 line 3 //
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #13
0
    def test_leaves_staging_empty(self):
        listing = CodeListing(filename='file1.txt',
                              contents=dedent("""
            file 1 line 2 amended
            file 1 line 3
            """).lstrip())
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)

        staged = self.sourcetree.run_command('git diff --staged')
        assert staged == ''
    def test_raises_if_too_many_files_in_commit(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 1
            file 1 line 2
            """).lstrip()
        )
        listing.commit_ref = 'ch17l023'

        self._checkout_commit('ch17l022')
        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_blank_lines(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            file 2 line 1 changed

            another line changed
            """).lstrip()
        )
        listing.commit_ref = 'ch17l024'
        self._checkout_commit('ch17l023')

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #16
0
    def test_listings_showing_a_move_mean_can_ignore_commit_lines_added_and_removed_2(
            self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            hello

            one more line at end
            """).lstrip())
        listing.commit_ref = 'ch17l030'
        self._checkout_commit('ch17l029')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_any_other_listing_lines_not_in_before_version(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            what is this?
            file 1 line 2 amended
            file 1 line 3
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_listings_showing_a_move_mean_can_ignore_commit_lines_added_and_removed_2(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            hello

            one more line at end
            """).lstrip()
        )
        listing.commit_ref = 'ch17l030'
        self._checkout_commit('ch17l029')

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #19
0
    def test_raises_if_listing_line_not_in_after_version(self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            hello
            goodbye
            hello

            one more line at end
            """).lstrip())
        listing.commit_ref = 'ch17l028'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_leaves_staging_empty(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 2 amended
            file 1 line 3
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)

        staged = self.sourcetree.run_command('git diff --staged')
        assert staged == ''
Beispiel #21
0
    def test_handles_indents(self):
        listing = CodeListing(filename='pythonfile.py',
                              contents=dedent("""
            def method1(self):
                # amend method 1
                return 2

            [...]
            """).lstrip())
        listing.commit_ref = 'ch17l026'
        self._checkout_commit('ch17l025')

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #22
0
    def test_under_indentation_differences_are_picked_up(self):
        listing = CodeListing(filename='pythonfile.py',
                              contents=dedent("""
            def method1(self):
            # amend method 1
            return 2

            [...]
            """).lstrip())
        listing.commit_ref = 'ch17l026'
        self._checkout_commit('ch17l025')

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
Beispiel #23
0
    def test_line_ordering_check_isnt_confused_by_dupe_lines(self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            another line changed
            some duplicate lines coming up...

            hello
            goodbye
            hello
            """).lstrip())
        listing.commit_ref = 'ch17l027'
        self._checkout_commit('ch17l026')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_handles_indents(self):
        listing = CodeListing(filename='pythonfile.py', contents=dedent(
            """
            def method1(self):
                # amend method 1
                return 2

            [...]
            """).lstrip()
        )
        listing.commit_ref = 'ch17l026'
        self._checkout_commit('ch17l025')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_listing_line_not_in_after_version(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            hello
            goodbye
            hello

            one more line at end
            """).lstrip()
        )
        listing.commit_ref = 'ch17l028'

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_python_callouts(self):
        listing = CodeListing(
            filename="file1.txt",
            contents=dedent(
                """
            [...]
            file 1 line 2 amended #
            file 1 line 3 #
            """
            ).lstrip(),
        )
        listing.commit_ref = "ch17l021"

        self.sourcetree.apply_listing_from_commit(listing)
    def test_raises_if_wrong_file(self):
        listing = CodeListing(
            filename="file2.txt",
            contents=dedent(
                """
            file 1 line 1
            file 1 line 2 amended
            file 1 line 3
            """
            ).lstrip(),
        )
        listing.commit_ref = "ch17l021"

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_under_indentation_differences_are_picked_up(self):
        listing = CodeListing(filename='pythonfile.py', contents=dedent(
            """
            def method1(self):
            # amend method 1
            return 2

            [...]
            """).lstrip()
        )
        listing.commit_ref = 'ch17l026'
        self._checkout_commit('ch17l025')

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
Beispiel #29
0
    def test_listings_showing_a_move_mean_can_ignore_commit_lines_added_and_removed(
            self):
        listing = CodeListing(filename='pythonfile.py',
                              contents=dedent("""
            class NuKlass(object):

                def method1(self):
                    [...]
                    a = a + 3
                    [...]
            """).lstrip())
        listing.commit_ref = 'ch17l029'
        self._checkout_commit('ch17l028-1')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_listings_showing_a_move_mean_can_ignore_commit_lines_added_and_removed(self):
        listing = CodeListing(filename='pythonfile.py', contents=dedent(
            """
            class NuKlass(object):

                def method1(self):
                    [...]
                    a = a + 3
                    [...]
            """).lstrip()
        )
        listing.commit_ref = 'ch17l029'
        self._checkout_commit('ch17l028-1')

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #31
0
    def test_happy_with_lines_in_before_and_after_version(self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            file 2 line 1 changed
            [...]

            hello
            hello

            one more line at end
            """).lstrip())
        listing.commit_ref = 'ch17l028'
        self._checkout_commit('ch17l027')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_line_ordering_check_isnt_confused_by_dupe_lines(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            another line changed
            some duplicate lines coming up...

            hello
            goodbye
            hello
            """).lstrip()
        )
        listing.commit_ref = 'ch17l027'
        self._checkout_commit('ch17l026')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_happy_with_lines_in_before_and_after_version(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            file 2 line 1 changed
            [...]

            hello
            hello

            one more line at end
            """).lstrip()
        )
        listing.commit_ref = 'ch17l028'
        self._checkout_commit('ch17l027')

        self.sourcetree.apply_listing_from_commit(listing)
Beispiel #34
0
    def test_non_dupes_are_still_order_checked(self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            some duplicate lines coming up...

            hello

            one more line at end
            add a line with a dupe of existing
            goodbye
            hello
            """).lstrip())
        listing.commit_ref = 'ch17l031'
        self._checkout_commit('ch17l030')

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
Beispiel #35
0
    def test_raises_if_lines_not_in_order(self):
        actual_contents = dedent("""
            line 1
            line 2
            line 3
            line 4
            """)
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            line 1
            line 3
            line 2
            """).lstrip())
        listing.currentcontents = True

        with self.assertRaises(AssertionError):
            self.check_current_contents(listing, actual_contents)
Beispiel #36
0
    def test_line_ordering_check_isnt_confused_by_new_lines_that_dupe_existing(
            self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            some duplicate lines coming up...

            hello

            one more line at end
            add a line with a dupe of existing
            hello
            goodbye
            """).lstrip())
        listing.commit_ref = 'ch17l031'
        self._checkout_commit('ch17l030')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_line_ordering_check_isnt_confused_by_new_lines_that_dupe_existing(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            some duplicate lines coming up...

            hello

            one more line at end
            add a line with a dupe of existing
            hello
            goodbye
            """).lstrip()
        )
        listing.commit_ref = 'ch17l031'
        self._checkout_commit('ch17l030')

        self.sourcetree.apply_listing_from_commit(listing)
    def DONTtest_listings_must_use_elipsis_to_indicate_skipped_lines(self):
        # TODO!
        lines = ["file 1 line 1", "file 1 line 2 amended", "file 1 line 3", "file 1 line 4 inserted", "another line"]
        listing = CodeListing(filename="file1.txt", contents="")
        listing.commit_ref = "ch17l022"
        self._checkout_commit("ch17l021")

        listing.contents = "\n".join(lines)
        self.sourcetree.apply_listing_from_commit(listing)  # should not raise

        lines[1] = "[...]"
        listing.contents = "\n".join(lines)
        self.sourcetree.apply_listing_from_commit(listing)  # should not raise

        lines.pop(1)
        listing.contents = "\n".join(lines)
        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
    def test_non_dupes_are_still_order_checked(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            some duplicate lines coming up...

            hello

            one more line at end
            add a line with a dupe of existing
            goodbye
            hello
            """).lstrip()
        )
        listing.commit_ref = 'ch17l031'
        self._checkout_commit('ch17l030')

        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
Beispiel #40
0
    def test_from_real_git_stuff(self):
        listing = CodeListing(filename='file1.txt',
                              contents=dedent("""
            file 1 line 2 amended
            file 1 line 3
            """).lstrip())
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)

        with open(self.sourcetree.tempdir + '/superlists/file1.txt') as f:
            assert f.read() == dedent("""
                file 1 line 1
                file 1 line 2 amended
                file 1 line 3
                """).lstrip()

        assert listing.was_written
Beispiel #41
0
 def test_checks_elipsis_blocks_separately(self):
     actual_contents = dedent("""
         line 1
         line 2
         line 3
         line 4
         line 5
         """)
     listing = CodeListing(filename='file2.txt',
                           contents=dedent("""
         line 1
         line 2
         [...]
         line 4
         """).lstrip())
     listing.currentcontents = True
     self.check_current_contents(listing,
                                 actual_contents)  # should not raise
Beispiel #42
0
    def test_with_diff_listing_passing_case(self):
        listing = CodeListing(filename='file2.txt',
                              contents=dedent("""
            diff --git a/file2.txt b/file2.txt
            index 93f054e..519d518 100644
            --- a/file2.txt
            +++ b/file2.txt
            @@ -4,6 +4,5 @@ another line changed
             some duplicate lines coming up...

             hello
            -hello

             one more line at end
             """).lstrip())
        listing.commit_ref = 'ch17l030'
        self._checkout_commit('ch17l029')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_with_diff_listing_passing_case(self):
        listing = CodeListing(filename='file2.txt', contents=dedent(
            """
            diff --git a/file2.txt b/file2.txt
            index 93f054e..519d518 100644
            --- a/file2.txt
            +++ b/file2.txt
            @@ -4,6 +4,5 @@ another line changed
             some duplicate lines coming up...

             hello
            -hello

             one more line at end
             """).lstrip()
        )
        listing.commit_ref = 'ch17l030'
        self._checkout_commit('ch17l029')

        self.sourcetree.apply_listing_from_commit(listing)
    def test_from_real_git_stuff(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 2 amended
            file 1 line 3
            """).lstrip()
        )
        listing.commit_ref = 'ch17l021'

        self.sourcetree.apply_listing_from_commit(listing)


        with open(self.sourcetree.tempdir + '/file1.txt') as f:
            assert f.read() == dedent(
                """
                file 1 line 1
                file 1 line 2 amended
                file 1 line 3
                """).lstrip()

        assert listing.was_written
Beispiel #45
0
 def test_indentation_is_ignored(self):
     actual_contents = dedent("""
         line 0
             line 1
         line 2
         line 3
         """)
     listing = CodeListing(filename='file2.txt',
                           contents=dedent("""
         line 1
         line 2
         line 3
         """).lstrip())
     self.check_current_contents(listing, actual_contents)
Beispiel #46
0
 def test_raises_for_any_line_not_in_actual_contents(self):
     actual_contents = dedent("""
         line 0
         line 1
         line 2
         line 3
         line 4
         """)
     listing = CodeListing(filename='file2.txt',
                           contents=dedent("""
         line 3
         line 4
         line 5
         """).lstrip())
     with self.assertRaises(AssertionError):
         self.check_current_contents(listing, actual_contents)
Beispiel #47
0
 def test_ok_for_correct_current_contents(self):
     actual_contents = dedent("""
         line 0
         line 1
         line 2
         line 3
         line 4
         """)
     listing = CodeListing(filename='file2.txt',
                           contents=dedent("""
         line 1
         line 2
         line 3
         """).lstrip())
     self.check_current_contents(listing,
                                 actual_contents)  # should not raise
Beispiel #48
0
    def DONTtest_listings_must_use_elipsis_to_indicate_skipped_lines(self):
        # TODO!
        lines = [
            "file 1 line 1",
            "file 1 line 2 amended",
            "file 1 line 3",
            "file 1 line 4 inserted",
            "another line",
        ]
        listing = CodeListing(filename='file1.txt', contents='')
        listing.commit_ref = 'ch17l022'
        self._checkout_commit('ch17l021')

        listing.contents = '\n'.join(lines)
        self.sourcetree.apply_listing_from_commit(listing)  # should not raise

        lines[1] = "[...]"
        listing.contents = '\n'.join(lines)
        self.sourcetree.apply_listing_from_commit(listing)  # should not raise

        lines.pop(1)
        listing.contents = '\n'.join(lines)
        with self.assertRaises(ApplyCommitException):
            self.sourcetree.apply_listing_from_commit(listing)
 def test_stringify(self):
     c = CodeListing(filename='a.py', contents='abc\ndef')
     assert 'abc' in str(c)
     assert 'a.py' in str(c)
     assert c.is_server_listing is False
 def test_server_codelisting(self):
     c = CodeListing(filename='server: a_filename.py', contents='foo')
     assert c.contents == 'foo'
     assert c.filename == 'a_filename.py'
     assert c.is_server_listing is True