-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_kcidev.py
102 lines (82 loc) · 2.59 KB
/
test_kcidev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import os
import shutil
from subprocess import PIPE, run
import git
import pytest
def test_prepare():
# prepare enviroment
os.system("cp .kci-dev.toml.example .kci-dev.toml")
assert os.path.exists(".kci-dev.toml")
def test_kcidev_help():
command = ["poetry", "run", "kci-dev", "--help"]
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 == 0
def test_kcidev_commit_help():
command = ["poetry", "run", "kci-dev", "commit", "--help"]
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 == 0
def test_kcidev_patch_help():
command = ["poetry", "run", "kci-dev", "patch", "--help"]
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 == 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
def test_main():
from subcommands.commit import api_connection
print(api_connection("test"))
pass
def test_clean():
# clean enviroment
shutil.rmtree("my-new-repo/")
if os.path.isfile(".kci-dev.toml"):
os.remove(".kci-dev.toml")
else:
print("File does not exist")