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


Python SourceTree.get_contents方法代码示例

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


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

示例1: ChapterTest

# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import get_contents [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

示例2: test_get_contents

# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import get_contents [as 别名]
 def test_get_contents(self):
     sourcetree = SourceTree()
     os.makedirs(sourcetree.tempdir + "/superlists")
     with open(sourcetree.tempdir + "/superlists/foo.txt", "w") as f:
         f.write("bla bla")
     assert sourcetree.get_contents("foo.txt") == "bla bla"
开发者ID:abunuwas,项目名称:Book-TDD-Web-Dev-Python,代码行数:8,代码来源:test_sourcetree.py

示例3: ChapterTest

# 需要导入模块: from sourcetree import SourceTree [as 别名]
# 或者: from sourcetree.SourceTree import get_contents [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.get_contents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。