Skip to content

Commit af98484

Browse files
committed
Fix test case
1 parent 70a9bcd commit af98484

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

tests/python/unittest/test_ci.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,18 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import os
1918
import pathlib
20-
import pytest
21-
import shutil
2219
import subprocess
23-
import tempfile
24-
import json
2520
import sys
21+
import tempfile
2622

2723
import pytest
2824

2925
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent.parent
3026

3127

3228
def test_skip_ci():
33-
skip_ci_script = REPO_ROOT / "tests" / "scripts" / "git_skip_ci.sh"
29+
skip_ci_script = REPO_ROOT / "tests" / "scripts" / "git_skip_ci.py"
3430

3531
class TempGit:
3632
def __init__(self, cwd):
@@ -47,14 +43,17 @@ def test(commands, should_skip, why):
4743
# Jenkins git is too old and doesn't have 'git init --initial-branch'
4844
git.run("init")
4945
git.run("checkout", "-b", "main")
46+
git.run("remote", "add", "origin", "https://github.com/apache/tvm.git")
5047
git.run("config", "user.name", "ci")
5148
git.run("config", "user.email", "[email protected]")
5249
git.run("commit", "--allow-empty", "--message", "base commit")
5350
for command in commands:
5451
git.run(*command)
5552
pr_number = "1234"
56-
proc = subprocess.run([str(skip_ci_script), pr_number], cwd=dir)
57-
expected = 1 if should_skip else 0
53+
proc = subprocess.run(
54+
[str(skip_ci_script), "--pr", pr_number, "--pr-title", "[skip ci] test"], cwd=dir
55+
)
56+
expected = 0 if should_skip else 1
5857
assert proc.returncode == expected, why
5958

6059
test(

tests/scripts/git_skip_ci.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def git(command):
7474
parser = argparse.ArgumentParser(description=help)
7575
parser.add_argument("--pr", required=True)
7676
parser.add_argument("--remote", default="origin", help="ssh remote to parse")
77+
parser.add_argument("--pr-title", help="(testing) PR title to use instead of fetching from GitHub")
7778
args = parser.parse_args()
7879

7980
branch = git(["rev-parse", "--abbrev-ref", "HEAD"])
@@ -83,10 +84,15 @@ def git(command):
8384
def check_pr_title():
8485
remote = git(["config", "--get", f"remote.{args.remote}.url"])
8586
user, repo = parse_remote(remote)
86-
github = GitHubRepo(token=os.environ["TOKEN"], user=user, repo=repo)
87-
pr = github.get(f"pulls/{args.pr}")
88-
print("pr title:", pr["title"])
89-
return pr["title"].startswith("[skip ci]")
87+
88+
if args.pr_title:
89+
title = args.pr_title
90+
else:
91+
github = GitHubRepo(token=os.environ["TOKEN"], user=user, repo=repo)
92+
pr = github.get(f"pulls/{args.pr}")
93+
title = pr["title"]
94+
print("pr title:", title)
95+
return title.startswith("[skip ci]")
9096

9197
if (
9298
args.pr != "null"

0 commit comments

Comments
 (0)