• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sourcetree.SourceTree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_running_interactive_command

    def test_running_interactive_command(self):
        sourcetree = SourceTree()

        command = "python3 -c \"print('input please?'); a = input();print('OK' if a=='yes' else 'NO')\""
        output = sourcetree.run_command(command, user_input='no')
        assert 'NO' in output
        output = sourcetree.run_command(command, user_input='yes')
        assert 'OK' in output
开发者ID:hjwp,项目名称:Book-TDD-Web-Dev-Python,代码行数:8,代码来源:test_sourcetree.py


示例2: test_running_interactive_command

    def test_running_interactive_command(self):
        sourcetree = SourceTree()
        sourcetree.run_command("mkdir superlists", cwd=sourcetree.tempdir)

        command = "python3 -c \"print('input please?'); a = input();print('OK' if a=='yes' else 'NO')\""
        output = sourcetree.run_command(command, user_input="no")
        assert "NO" in output
        output = sourcetree.run_command(command, user_input="yes")
        assert "OK" in output
开发者ID:abunuwas,项目名称:Book-TDD-Web-Dev-Python,代码行数:9,代码来源:test_sourcetree.py


示例3: test_special_cases_fab_deploy

 def test_special_cases_fab_deploy(self, mock_subprocess):
     mock_subprocess.Popen.return_value.returncode = 0
     mock_subprocess.Popen.return_value.communicate.return_value = 'a', 'b'
     sourcetree = SourceTree()
     sourcetree.run_command('fab deploy:[email protected]')
     expected = (
         'cd deploy_tools &&'
         ' fab -D -i'
         ' ~/Dropbox/Book/.vagrant/machines/default/virtualbox/private_key'
         ' deploy:[email protected]'
     )
     assert mock_subprocess.Popen.call_args[0][0] == expected
开发者ID:hjwp,项目名称:Book-TDD-Web-Dev-Python,代码行数:12,代码来源:test_sourcetree.py


示例4: setUp

 def setUp(self):
     self.sourcetree = SourceTree()
     self.tempdir = self.sourcetree.tempdir
     self.processes = []
     self.pos = 0
     self.dev_server_running = False
     self.current_server_cd = None
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:7,代码来源:book_tester.py


示例5: setUp

 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')
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:8,代码来源:test_sourcetree.py


示例6: test_checks_out_repo_current_chapter_as_master

 def test_checks_out_repo_current_chapter_as_master(self):
     sourcetree = SourceTree()
     sourcetree.get_local_repo_path = lambda c: os.path.abspath(os.path.join(os.path.dirname(__file__), "testrepo"))
     sourcetree.start_with_checkout(21)
     remotes = sourcetree.run_command("git remote").split()
     assert remotes == ["repo"]
     branch = sourcetree.run_command("git branch").strip()
     assert branch == "* master"
     diff = sourcetree.run_command("git diff repo/chapter_20").strip()
     assert diff == ""
开发者ID:abunuwas,项目名称:Book-TDD-Web-Dev-Python,代码行数:10,代码来源:test_sourcetree.py


示例7: test_checks_out_repo_chapter_as_master

 def test_checks_out_repo_chapter_as_master(self):
     sourcetree = SourceTree()
     sourcetree.get_local_repo_path = lambda c: os.path.abspath(os.path.join(
         os.path.dirname(__file__), 'testrepo'
     ))
     sourcetree.start_with_checkout('chapter_17', 'chapter_16')
     remotes = sourcetree.run_command('git remote').split()
     assert remotes == ['repo']
     branch = sourcetree.run_command('git branch').strip()
     assert branch == '* master'
     diff = sourcetree.run_command('git diff repo/chapter_16').strip()
     assert diff == ''
开发者ID:hjwp,项目名称:Book-TDD-Web-Dev-Python,代码行数:12,代码来源:test_sourcetree.py


示例8: test_cleanup_kills_backgrounded_processes_and_rmdirs

    def test_cleanup_kills_backgrounded_processes_and_rmdirs(self):
        sourcetree = SourceTree()
        sourcetree.run_command('python -c"import time; time.sleep(5)" & #runserver', cwd=sourcetree.tempdir)
        assert len(sourcetree.processes) == 1
        sourcetree_pid = sourcetree.processes[0].pid
        pids = subprocess.check_output('pgrep -f time.sleep', shell=True).decode('utf8').split()
        print('sourcetree_pid', sourcetree_pid)
        print('pids', pids)
        sids = []
        for pid in reversed(pids):
            print('checking', pid)
            cmd = 'ps -o sid --no-header -p %s' % (pid,)
            print(cmd)
            try:
                sid = subprocess.check_output(cmd, shell=True)
                print('sid', sid)
                sids.append(sid)
                assert sourcetree_pid == int(sid)
            except subprocess.CalledProcessError:
                pass
        assert sids

        sourcetree.cleanup()
        assert 'time.sleep' not in subprocess.check_output('ps auxf', shell=True).decode('utf8')
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:24,代码来源:test_sourcetree.py


示例9: test_special_cases_wget_bootstrap

 def test_special_cases_wget_bootstrap(self):
     sourcetree = SourceTree()
     sourcetree.run_command("mkdir superlists", cwd=sourcetree.tempdir)
     with patch("sourcetree.subprocess") as mock_subprocess:
         mock_subprocess.Popen.return_value.communicate.return_value = ("bla bla", None)
         sourcetree.run_command(BOOTSTRAP_WGET)
         assert not mock_subprocess.Popen.called
     assert os.path.exists(os.path.join(sourcetree.tempdir, "superlists", "bootstrap.zip"))
     diff = sourcetree.run_command(
         "diff %s bootstrap.zip" % (os.path.join(os.path.dirname(__file__), "..", "downloads", "bootstrap-3.0.zip"))
     )
     assert diff == ""
开发者ID:abunuwas,项目名称:Book-TDD-Web-Dev-Python,代码行数:12,代码来源:test_sourcetree.py


示例10: test_special_cases_wget_bootstrap

 def test_special_cases_wget_bootstrap(self):
     sourcetree = SourceTree()
     sourcetree.run_command('mkdir superlists', cwd=sourcetree.tempdir)
     with patch('sourcetree.subprocess') as mock_subprocess:
         mock_subprocess.Popen.return_value.communicate.return_value = (
                 'bla bla', None
         )
         sourcetree.run_command(BOOTSTRAP_WGET)
         assert not mock_subprocess.Popen.called
     assert os.path.exists(os.path.join(sourcetree.tempdir, 'superlists', 'bootstrap.zip'))
     diff = sourcetree.run_command('diff %s bootstrap.zip' % (
         os.path.join(os.path.dirname(__file__), '..', 'downloads', 'bootstrap.zip'))
     )
     assert diff == ''
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:14,代码来源:test_sourcetree.py


示例11: test_doesnt_raise_for_some_things_where_a_return_code_is_ok

 def test_doesnt_raise_for_some_things_where_a_return_code_is_ok(self):
     sourcetree = SourceTree()
     sourcetree.run_command('diff foo bar', cwd=sourcetree.tempdir)
     sourcetree.run_command('python test.py', cwd=sourcetree.tempdir)
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:4,代码来源:test_sourcetree.py


示例12: test_environment_variables

 def test_environment_variables(self):
     sourcetree = SourceTree()
     os.environ['TEHFOO'] = 'baz'
     output = sourcetree.run_command('echo $TEHFOO', cwd=sourcetree.tempdir)
     assert output.strip() == 'baz'
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:5,代码来源:test_sourcetree.py


示例13: test_raises_on_errors

 def test_raises_on_errors(self):
     sourcetree = SourceTree()
     with self.assertRaises(Exception):
         sourcetree.run_command('synt!tax error', cwd=sourcetree.tempdir)
     sourcetree.run_command('synt!tax error', cwd=sourcetree.tempdir, ignore_errors=True)
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:5,代码来源:test_sourcetree.py


示例14: test_returns_output

 def test_returns_output(self):
     sourcetree = SourceTree()
     output = sourcetree.run_command('echo hello', cwd=sourcetree.tempdir)
     assert output == 'hello\n'
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:4,代码来源:test_sourcetree.py


示例15: test_running_simple_command

 def test_running_simple_command(self):
     sourcetree = SourceTree()
     sourcetree.run_command('touch foo', cwd=sourcetree.tempdir)
     assert os.path.exists(os.path.join(sourcetree.tempdir, 'foo'))
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:4,代码来源:test_sourcetree.py


示例16: test_get_contents

 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,代码行数:6,代码来源:test_sourcetree.py


示例17: ChapterTest

class ChapterTest(unittest.TestCase):
    maxDiff = None

    def setUp(self):
        self.sourcetree = SourceTree()
        self.tempdir = self.sourcetree.tempdir
        self.processes = []
        self.pos = 0
        self.dev_server_running = False
        self.current_server_cd = None


    def tearDown(self):
        self.sourcetree.cleanup()


    def parse_listings(self):
        base_dir = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
        filename = 'chapter_{0:02d}.html'.format(self.chapter_no)
        with open(os.path.join(base_dir, filename), encoding='utf-8') as f:
            raw_html = f.read()
        parsed_html = html.fromstring(raw_html)
        listings_nodes = parsed_html.cssselect('div.listingblock')
        self.listings = [p for n in listings_nodes for p in parse_listing(n)]


    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


    def write_to_file(self, codelisting):
        self.assertEqual(
            type(codelisting), CodeListing,
            "passed a non-Codelisting to write_to_file:\n%s" % (codelisting,)
        )
        print('writing to file', codelisting.filename)
        write_to_file(codelisting, os.path.join(self.tempdir, 'superlists'))
        filenames = codelisting.filename.split(', ')
        for filename in filenames:
            with open(os.path.join(self.tempdir, 'superlists', filename)) as f:
                print('wrote:')
                print(f.read())


    def apply_patch(self, codelisting):
        tf = tempfile.NamedTemporaryFile(delete=False)
        tf.write(codelisting.contents.encode('utf8'))
        tf.write('\n'.encode('utf8'))
        tf.close()
        print('patch:\n', codelisting.contents)
        patch_output = self.run_command(
            Command('patch --fuzz=3 --no-backup-if-mismatch %s %s' % (codelisting.filename, tf.name))
        )
        print(patch_output)
        self.assertNotIn('malformed', patch_output)
        self.assertNotIn('failed', patch_output.lower())
        codelisting.was_checked = True
        with open(os.path.join(self.tempdir, 'superlists', codelisting.filename)) as f:
            print(f.read())
        os.remove(tf.name)
        self.pos += 1
        codelisting.was_written = True


    def run_command(self, command, cwd=None, user_input=None, ignore_errors=False):
        self.assertEqual(
            type(command), Command,
            "passed a non-Command to run-command:\n%s" % (command,)
        )
        if command == 'git push':
#.........这里部分代码省略.........
开发者ID:Lamhot,项目名称:book-tdd-python,代码行数:101,代码来源:book_tester.py


示例18: test_default_directory_is_superlists

 def test_default_directory_is_superlists(self):
     sourcetree = SourceTree()
     os.makedirs(os.path.join(sourcetree.tempdir, "superlists"))
     sourcetree.run_command("touch foo")
     assert os.path.exists(os.path.join(sourcetree.tempdir, "superlists", "foo"))
开发者ID:abunuwas,项目名称:Book-TDD-Web-Dev-Python,代码行数:5,代码来源:test_sourcetree.py


示例19: test_default_directory_is_tempdir

 def test_default_directory_is_tempdir(self):
     sourcetree = SourceTree()
     sourcetree.run_command('touch foo')
     assert os.path.exists(os.path.join(sourcetree.tempdir, 'foo'))
开发者ID:hjwp,项目名称:Book-TDD-Web-Dev-Python,代码行数:4,代码来源:test_sourcetree.py


示例20: ApplyFromGitRefTest

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,代码行数:101,代码来源:test_sourcetree.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _minhash.MinHash类代码示例发布时间:2022-05-27
下一篇:
Python models.SourceVersion类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap