Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest: test and update commit repo command #15

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions kci-dev/subcommands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def api_connection(host):
return host


def find_diff(path, branch, repository):
def find_diff(path, branch, origin, repository):
repo = Repo(path)
assert not repo.bare
hcommit = repo.iter_commits("origin/master.." + branch)
hcommit = repo.iter_commits(origin + ".." + branch)
commits = []
for i in hcommit:
commits.append(repo.git.show(i))
return commits
return commits[0]


def send_build(url, patch, branch, treeurl, token):
Expand All @@ -48,6 +48,7 @@ def send_build(url, patch, branch, treeurl, token):
help="define the kernel upstream repository where to test local changes",
)
@click.option("--branch", default="master", help="define the repository branch")
@click.option("--origin", default="master", help="define the origin repository branch")
@click.option(
"--private",
default=False,
Expand All @@ -60,11 +61,11 @@ def send_build(url, patch, branch, treeurl, token):
help="define the directory of the local tree with local changes",
)
@click.pass_context
def commit(ctx, repository, branch, private, path):
def commit(ctx, repository, branch, origin, private, path):
config = ctx.obj.get("CFG")
instance = ctx.obj.get("INSTANCE")
url = api_connection(config[instance]["host"])
diff = find_diff(path, branch, repository)
diff = find_diff(path, branch, origin, repository)
send_build(url, diff, branch, repository, config[instance]["token"])


Expand Down
42 changes: 42 additions & 0 deletions tests/test_kcidev.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
from subprocess import PIPE, run

import git
import pytest


def test_prepare():
os.system("cp .kci-dev.toml.example .kci-dev.toml")
Expand Down Expand Up @@ -38,3 +41,42 @@ def test_kcidev_patch_help():
print("#### stderr ####")
print(result.stderr)
assert result.returncode == 0


def test_create_repo():
repo_dir = os.path.join("my-new-repo")
file_name = os.path.join(repo_dir, "new-file")
file_name2 = os.path.join(repo_dir, "new-file2")
r = git.Repo.init(repo_dir)
open(file_name, "wb").close()
r.index.add("new-file")
r.index.commit("initial commit")
test_branch = r.create_head("test")
r.head.reference = test_branch
open(file_name2, "wb").close()
r.index.add("new-file2")
r.index.commit("test")


def test_kcidev_commit():
command = [
"poetry",
"run",
"kci-dev",
"commit",
"--repository",
"linux-next",
"--origin",
"master",
"--branch",
"test",
"--path",
"my-new-repo",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout)
print("#### stderr ####")
print(result.stderr)
assert result.returncode == 1
Loading