当前位置: 首页>>代码示例>>Python>>正文


Python SourceTree.apply_listing_from_commit方法代码示例

本文整理汇总了Python中sourcetree.SourceTree.apply_listing_from_commit方法的典型用法代码示例。如果您正苦于以下问题:Python SourceTree.apply_listing_from_commit方法的具体用法?Python SourceTree.apply_listing_from_commit怎么用?Python SourceTree.apply_listing_from_commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sourcetree.SourceTree的用法示例。


在下文中一共展示了SourceTree.apply_listing_from_commit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ApplyFromGitRefTest

# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import apply_listing_from_commit [as 别名]
class ApplyFromGitRefTest(unittest.TestCase):

    def setUp(self):
        self.sourcetree = SourceTree()
        self.sourcetree.get_local_repo_path = lambda c: os.path.abspath(os.path.join(
            os.path.dirname(__file__), 'testrepo'
        ))
        self.sourcetree.start_with_checkout(17)
        self.sourcetree.run_command('git checkout test-start')
        self.sourcetree.run_command('git reset')


    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_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_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 _checkout_commit(self, commit):
        commit_spec = self.sourcetree.get_commit_spec(commit)
        self.sourcetree.run_command('git checkout ' + commit_spec)
        self.sourcetree.run_command('git reset')


    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_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)


    def test_raises_if_listing_lines_in_wrong_order(self):
        listing = CodeListing(filename='file1.txt', contents=dedent(
            """
            file 1 line 3
#.........这里部分代码省略.........
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:103,代码来源:test_sourcetree.py

示例2: ChapterTest

# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import apply_listing_from_commit [as 别名]

#.........这里部分代码省略.........
                self.pos += 1
            if next_output is not None:
                self.pos += 2
                next_output.was_checked = True
                first_input.was_run = True
                next_input.was_run = True



        elif listing.type == 'tree':
            print("TREE")
            self.assert_directory_tree_correct(listing)
            self.pos += 1

        elif listing.type == 'server command':
            server_output = self.run_server_command(listing)
            listing.was_run = True
            self.pos += 1
            next_listing = self.listings[self.pos]
            if next_listing.type == 'output' and not next_listing.skip:
                for line in next_listing.split('\n'):
                    assert line.strip() in server_output
                next_listing.was_checked = True
                self.pos += 1

        elif listing.type == 'other command':
            print("A COMMAND")
            output = self.run_command(listing)
            next_listing = self.listings[self.pos + 1]
            if next_listing.type == 'output' and not next_listing.skip:
                ls = listing.startswith('ls')
                self.assert_console_output_correct(output, next_listing, ls=ls)
                next_listing.was_checked = True
                listing.was_checked = True
                self.pos += 2
            elif 'tree' in listing and next_listing.type == 'tree':
                self.assert_console_output_correct(output, next_listing)
                next_listing.was_checked = True
                listing.was_checked = True
                self.pos += 2
            else:
                listing.was_checked = True
                self.pos += 1

        elif listing.type == 'diff':
            print("DIFF")
            self.apply_patch(listing)

        elif listing.type == 'code listing currentcontents':
            actual_contents = self.sourcetree.get_contents(
                listing.filename
            )
            print("CHECK CURRENT CONTENTS")
            stripped_actual_lines = [l.strip() for l in actual_contents.split('\n')]
            listing_contents = re.sub(r' +#$', '', listing.contents, flags=re.MULTILINE)
            for line in listing_contents.split('\n'):
                if line and not '[...]' in line:
                    self.assertIn(line.strip(), stripped_actual_lines)
            listing.was_written = True
            self.pos += 1

        elif listing.type == 'code listing':
            print("CODE")
            self.write_to_file(listing)
            self.pos += 1

        elif listing.type == 'code listing with git ref':
            print("CODE FROM GIT REF")
            self.sourcetree.apply_listing_from_commit(listing)
            self.pos += 1

        elif listing.type == 'server code listing':
            print("SERVER CODE")
            self.write_file_on_server(listing.filename, listing.contents)
            self.pos += 1

        elif listing.type == 'qunit output':
            self.check_qunit_output(listing)
            self.pos += 1

        elif listing.type == 'output':
            self._strip_out_any_pycs()
            test_run = self.run_unit_tests()
            if 'OK' in test_run and not 'OK' in listing:
                print('unit tests pass, must be an FT:\n', test_run)
                test_run = self.run_fts()
            try:
                self.assert_console_output_correct(test_run, listing)
            except AssertionError as e:
                if 'OK' in test_run and 'OK' in listing:
                    print('got error when checking unit tests', e)
                    test_run = self.run_fts()
                    self.assert_console_output_correct(test_run, listing)
                else:
                    raise

            self.pos += 1

        else:
            self.fail('not implemented for ' + str(listing))
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:104,代码来源:book_tester.py

示例3: ChapterTest

# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import apply_listing_from_commit [as 别名]

#.........这里部分代码省略.........
                server_output = self.run_server_command(listing)
            listing.was_run = True
            self.pos += 1
            next_listing = self.listings[self.pos]
            if next_listing.type == 'output' and not next_listing.skip:
                if DO_SERVER_COMMANDS:
                    for line in next_listing.split('\n'):
                        line = line.split('[...]')[0].strip()
                        line = re.sub(r'\s+', ' ', line)
                        server_output = re.sub(r'\s+', ' ', server_output)
                        self.assertIn(line, server_output)
                next_listing.was_checked = True
                self.pos += 1

        elif listing.type == 'against staging':
            print("AGAINST STAGING")
            next_listing = self.listings[self.pos + 1]
            if DO_SERVER_COMMANDS:
                output = self.run_command(listing, ignore_errors=listing.ignore_errors)
                listing.was_checked = True
            else:
                listing.skip = True
            if next_listing.type == 'output' and not next_listing.skip:
                if DO_SERVER_COMMANDS:
                    self.assert_console_output_correct(output, next_listing)
                    next_listing.was_checked = True
                else:
                    next_listing.skip = True
                self.pos += 2

        elif listing.type == 'other command':
            print("A COMMAND")
            output = self.run_command(listing, ignore_errors=listing.ignore_errors)
            next_listing = self.listings[self.pos + 1]
            if next_listing.type == 'output' and not next_listing.skip:
                ls = listing.startswith('ls')
                self.assert_console_output_correct(output, next_listing, ls=ls)
                next_listing.was_checked = True
                listing.was_checked = True
                self.pos += 2
            elif 'tree' in listing and next_listing.type == 'tree':
                self.assert_console_output_correct(output, next_listing)
                next_listing.was_checked = True
                listing.was_checked = True
                self.pos += 2
            else:
                listing.was_checked = True
                self.pos += 1

        elif listing.type == 'diff':
            print("DIFF")
            self.apply_patch(listing)

        elif listing.type == 'code listing currentcontents':
            actual_contents = self.sourcetree.get_contents(
                listing.filename
            )
            self.check_current_contents(listing, actual_contents)
            self.pos += 1

        elif listing.type == 'code listing':
            print("CODE")
            self.write_to_file(listing)
            self.pos += 1

        elif listing.type == 'code listing with git ref':
            print("CODE FROM GIT REF")
            self.sourcetree.apply_listing_from_commit(listing)
            self.pos += 1

        elif listing.type == 'server code listing':
            print("SERVER CODE")
            self.write_file_on_server(listing.filename, listing.contents)
            listing.was_written = True
            self.pos += 1

        elif listing.type == 'qunit output':
            self.check_qunit_output(listing)
            self.pos += 1

        elif listing.type == 'output':
            self._strip_out_any_pycs()
            test_run = self.run_unit_tests()
            if 'OK' in test_run and 'OK' not in listing:
                print('unit tests pass, must be an FT:\n', test_run)
                test_run = self.run_fts()
            try:
                self.assert_console_output_correct(test_run, listing)
            except AssertionError as e:
                if 'OK' in test_run and 'OK' in listing:
                    print('got error when checking unit tests', e)
                    test_run = self.run_fts()
                    self.assert_console_output_correct(test_run, listing)
                else:
                    raise

            self.pos += 1

        else:
            self.fail('not implemented for ' + str(listing))
开发者ID:hjwp,项目名称:Book-TDD-Web-Dev-Python,代码行数:104,代码来源:book_tester.py


注:本文中的sourcetree.SourceTree.apply_listing_from_commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。