Skip to content

Commit

Permalink
Merge pull request #15 from aliceinwire/pytest_update
Browse files Browse the repository at this point in the history
pytest: test  and update commit repo command
  • Loading branch information
aliceinwire authored Sep 25, 2024
2 parents 02ea927 + 7130af3 commit a09dccc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
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

0 comments on commit a09dccc

Please sign in to comment.