def test_error(self):
     self.assertRaises(
         RuntimeError,
         gpr._run_shell_command,
         ["ls", "sureitdoesnoteixst"])
     gpr._run_shell_command(["ls", "sureitdoesnoteixst"],
                            raise_on_error=False)
Exemple #2
0
    def test_git_get_title_and_message(self):
        gpr._run_shell_command(
            ["git", "commit", "--allow-empty", "--no-edit", "-q", "-m", "Import"]
        )
        gpr._run_shell_command(
            ["git", "commit", "--allow-empty", "--no-edit", "-q", "-m", "First message"]
        )
        gpr._run_shell_command(
            [
                "git",
                "commit",
                "--allow-empty",
                "--no-edit",
                "-q",
                "-m",
                "Last message\n\nLong body, " "but not so long\n",
            ]
        )

        self.assertEqual(
            (1, "Last message", "Long body, but not so long"),
            gpr.git_get_title_and_message("master^", "master"),
        )

        self.assertEqual(
            (
                2,
                "Pull request for master",
                "## First message\n\n\n"
                "## Last message\n\nLong body, but not so long",
            ),
            gpr.git_get_title_and_message("master^^", "master"),
        )
 def setUp(self):
     self.tempdir = self.useFixture(fixtures.TempDir()).path
     os.chdir(self.tempdir)
     gpr._run_shell_command(["git", "init", "--quiet"])
     gpr._run_shell_command(["git", "remote", "add", "origin",
                             "https://github.com/jd/git-pull-request.git"])
     gpr._run_shell_command(["git", "config", "branch.master.merge",
                             "refs/heads/master"])
     gpr._run_shell_command(["git", "config", "branch.master.remote",
                             "origin"])
     gpr._run_shell_command(["git", "config", "user.name", "nobody"])
     gpr._run_shell_command(["git", "config", "user.email",
                             "*****@*****.**"])
 def setUp(self):
     self.tempdir = self.useFixture(fixtures.TempDir()).path
     os.chdir(self.tempdir)
     gpr._run_shell_command(["git", "init", "--quiet"])
     gpr.git_set_config_hosttype("github")
    def test_get_remote_for_branch(self):
        self.tempdir = self.useFixture(fixtures.TempDir()).path
        os.chdir(self.tempdir)
        gpr._run_shell_command(["git", "init", "--quiet"])
        gpr._run_shell_command(["git", "remote", "add", "origin",
                                "https://github.com/jd/git-pull-request.git"])
        gpr._run_shell_command(["git", "config", "branch.master.merge",
                                "refs/heads/master"])
        gpr._run_shell_command(["git", "config", "branch.master.remote",
                                "origin"])
        gpr._run_shell_command(["git", "config", "user.name", "nobody"])
        gpr._run_shell_command(["git", "config", "user.email",
                                "*****@*****.**"])

        gpr._run_shell_command(["git", "config",
                                "git-pull-request.setup-only", "yes"])
        gpr._run_shell_command(["git", "config",
                                "git-pull-request.fork", "never"])
        gpr._run_shell_command(["git", "config",
                                "git-pull-request.target-branch",
                                "awesome_branch"])
        args = gpr.build_parser().parse_args([])
        self.assertEqual(True, args.setup_only)
        self.assertEqual("never", args.fork)
        self.assertEqual("awesome_branch", args.target_branch)
 def test_output(self):
     output = gpr._run_shell_command(["echo", "arf"], output=True)
     self.assertEqual("arf", output)
 def test_ok(self):
     gpr._run_shell_command(["echo", "arf"])
    def test_git_get_title_and_message(self):
        gpr._run_shell_command(["git", "init", "--quiet"])
        gpr._run_shell_command(["git", "remote", "add", "origin",
                                "https://github.com/jd/git-pull-request.git"])
        gpr._run_shell_command(["git", "config", "branch.master.merge",
                                "refs/heads/master"])
        gpr._run_shell_command(["git", "config", "branch.master.remote",
                                "origin"])
        gpr._run_shell_command(["git", "config", "user.name", "nobody"])
        gpr._run_shell_command(["git", "config", "user.email",
                                "*****@*****.**"])
        gpr._run_shell_command(["git", "commit", "--allow-empty",
                                "--no-edit", "-q",
                                "-m", "Import"])
        gpr._run_shell_command(["git", "commit", "--allow-empty",
                                "--no-edit", "-q",
                                "-m", "First message"])
        gpr._run_shell_command(["git", "commit", "--allow-empty",
                                "--no-edit", "-q",
                                "-m", "Last message\n\nLong body, "
                                "but not so long\n"])

        with open(os.path.join(
                  self.tempdir,
                  "PULL_REQUEST_TEMPLATE.md"), "w+") as pr_template:
            pr_template.write("# test")

        self.assertEqual(
            (1,
             "Last message",
             "# test\n"
             "> ------------------------ >8 ------------------------\n"
             "> Do not modify or remove the line above.\n"
             "> Everything below it will be ignored.\n"
             "## Last message\n\n"
             "Long body, but not so long"),
            gpr.git_get_title_and_message("master^", "master"))
        self.assertEqual(
            (2,
             "Pull request for master",
             "# test\n"
             "> ------------------------ >8 ------------------------\n"
             "> Do not modify or remove the line above.\n"
             "> Everything below it will be ignored.\n"
             "## First message\n\n\n"
             "## Last message\n\n"
             "Long body, but not so long"),
            gpr.git_get_title_and_message("master^^", "master"))

        count, title, message = gpr.git_get_title_and_message(
            "master^^", "master",
        )

        assert gpr.parse_pr_message(message) == ("# test", "")
    def test_git_get_title_and_message(self):
        gpr._run_shell_command(["git", "init", "--quiet"])
        gpr._run_shell_command(["git", "remote", "add", "origin",
                                "https://github.com/jd/git-pull-request.git"])
        gpr._run_shell_command(["git", "config", "branch.master.merge",
                                "refs/heads/master"])
        gpr._run_shell_command(["git", "config", "branch.master.remote",
                                "origin"])
        gpr._run_shell_command(["git", "config", "user.name", "nobody"])
        gpr._run_shell_command(["git", "config", "user.email",
                                "*****@*****.**"])
        gpr._run_shell_command(["git", "commit", "--allow-empty",
                                "--no-edit", "-q",
                                "-m", "Import"])
        gpr._run_shell_command(["git", "commit", "--allow-empty",
                                "--no-edit", "-q",
                                "-m", "First message"])
        gpr._run_shell_command(["git", "commit", "--allow-empty",
                                "--no-edit", "-q",
                                "-m", "Last message\n\nLong body, "
                                "but not so long\n"])

        with open(os.path.join(
                  self.tempdir,
                  "PULL_REQUEST_TEMPLATE.md"), "w+") as pr_template:
            pr_template.write("# test")

        self.assertEqual((1, "Last message", "# test"),
                         gpr.git_get_title_and_message("master^", "master"))

        self.assertEqual((2, "Pull request for master", "# test"),
                         gpr.git_get_title_and_message("master^^", "master"))