python类init()的实例源码

test_release.py 文件源码 项目:maintain 作者: kylef 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_git_release_with_remote(self):
        with git_bare_repo() as bare_repo:
            with temp_directory():
                with open('VERSION', 'w') as fp:
                    fp.write('1.0.0\n')

                repo = Repo.init()
                repo.index.add(['VERSION'])
                repo.index.commit('Initial commit')
                repo.create_remote('origin', url=bare_repo)
                repo.remotes.origin.push(repo.refs.master)

                result = self.runner.invoke(release, ['2.0.0'])
                self.assertIsNone(result.exception)
                self.assertEqual(result.exit_code, 0)

                with open('VERSION') as fp:
                    self.assertEqual(fp.read(), '2.0.0\n')

                self.assertEqual(repo.refs.master.commit.message, 'Release 2.0.0')
                self.assertEqual(repo.tags['2.0.0'].commit, repo.refs.master.commit)
                self.assertFalse(repo.is_dirty())

            bare_repo = Repo(bare_repo)
            self.assertEqual(bare_repo.commit('master').message, 'Release 2.0.0')
            self.assertEqual(bare_repo.tags['2.0.0'].commit, bare_repo.refs.master.commit)
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_get_commits(self, tmpdir):
        """Verify that we can get commits for a repo."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        for x in range(0, 10):
            file = p / "test{0}.txt".format(x)
            file.write_text(u"Test", encoding='utf-8')
            repo.index.add(['test{0}.txt'.format(x)])
            repo.index.commit("Commit #{0}".format(x))

        commits = osa_differ.get_commits(path, 'HEAD~2', 'HEAD')
        assert len(list(commits)) == 2
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_get_commits_hide_merges(self, tmpdir):
        """Verify that we can get commits for a repo."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        for x in range(0, 10):
            file = p / "test{0}.txt".format(x)
            file.write_text(u"Test", encoding='utf-8')
            repo.index.add(['test{0}.txt'.format(x)])
            repo.index.commit("Merge #{0}".format(x))

        commits = osa_differ.get_commits(path, 'HEAD~2', 'HEAD',
                                         hide_merges=True)
        assert len(list(commits)) == 0
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_get_commits_include_merges(self, tmpdir):
        """Verify that we can get commits for a repo."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        for x in range(0, 10):
            file = p / "test{0}.txt".format(x)
            file.write_text(u"Test", encoding='utf-8')
            repo.index.add(['test{0}.txt'.format(x)])
            repo.index.commit("Merge #{0}".format(x))

        commits = osa_differ.get_commits(path, 'HEAD~2', 'HEAD',
                                         hide_merges=False)
        assert len(list(commits)) == 2
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_commit_invalid(self, tmpdir):
        """Verify that we can find valid commits."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        file = p / 'test.txt'
        file.write_text(u'Testing', encoding='utf-8')
        repo.index.add(['test.txt'])
        repo.index.commit('Testing')

        with raises(Exception):
            osa_differ.validate_commits(path, ['HEAD~1'])
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_commit_range_not_valid(self, tmpdir):
        """Verify that we can test a commit range for validity."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        file = p / 'test.txt'
        file.write_text(u'Testing1', encoding='utf-8')
        repo.index.add(['test.txt'])
        repo.index.commit('Testing 1')
        file.write_text(u'Testing2', encoding='utf-8')
        repo.index.add(['test.txt'])
        repo.index.commit('Testing 2')

        with raises(Exception):
            osa_differ.validate_commit_range(path, 'HEAD~2', 'HEAD')
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_render_template(self, tmpdir):
        """Verify that we can render a jinja template."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        for x in range(0, 10):
            file = p / "test{0}.txt".format(x)
            file.write_text(u"Test", encoding='utf-8')
            repo.index.add(['test{0}.txt'.format(x)])
            repo.index.commit("Commit #{0}".format(x))

        commits = osa_differ.get_commits(path, 'HEAD~2', 'HEAD')

        template_vars = {
            'repo': 'openstack-ansible',
            'commits': commits,
            'commit_base_url': 'http://example.com',
            'old_sha': 'HEAD~10',
            'new_sha': 'HEAD~1'
        }
        template_filename = "offline-repo-changes.j2"
        rst = osa_differ.render_template(template_filename,
                                         template_vars)
        assert "openstack-ansible" in rst
        assert "2 commits were found" in rst
        assert "http://example.com" in rst
        assert "HEAD~10" in rst
        assert "HEAD~1" in rst
test_osa_differ.py 文件源码 项目:osa_differ 作者: major 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_repo_update_update(self, tmpdir):
        """Verify that update_repo tries to update the repo."""
        p = tmpdir.mkdir('test')
        path = str(p)
        repo = Repo.init(path)
        file = p / 'test.txt'
        file.write_text(u'Testing', encoding='utf-8')
        repo.index.add(['test.txt'])
        repo.index.commit('Testing')

        result = osa_differ.update_repo(path, path)

        assert result.active_branch.name == 'master'
        assert not result.is_dirty()
test_lambda.py 文件源码 项目:col-aws-clients 作者: collectrium 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_lambda_deployment(self):
        aws_lambda_config={
                'roma_api_function': {
                    'role_name': 'lambda_basic_execution',
                    'handler': 'lambda_module.lambda_handler',
                    'event_sources': {
                        'api_gateway': {},
                    },
                    'ignored_packages': ['ipython', 'pudb']
                }
        }
        git_repo = Repo.init(path=tempfile.mkdtemp())
        zip_file = LambdaPackage(
            aws_lambda_config, git_repo.git_dir
        ).create_deployment_package()
        lambda_deployer = LambdaDeployer(
            region_name=self.region_name,
            aws_access_key_id=self.aws_access_key_id,
            aws_secret_access_key=self.aws_secret_access_key,
            zip_file=zip_file,
            version='development',
            aws_lambda_config=aws_lambda_config
        )

        lambda_deployer.deploy()
        lambda_deployer.deploy()
abs_test_class.py 文件源码 项目:coon 作者: comtihon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def set_git_url(path: str, url: str):
    repo = Repo.init(path)
    repo.index.add(listdir(path))
    repo.index.commit("First commit")
    repo.create_head('master')
    repo.create_remote('origin', url=url + '.git')


问题


面经


文章

微信
公众号

扫码关注公众号