-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathkeen.py
More file actions
157 lines (116 loc) · 3.4 KB
/
keen.py
File metadata and controls
157 lines (116 loc) · 3.4 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os
import shutil
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).parent.resolve()
VENV_DIR = ROOT / ".venv"
VENV_PYTHON = VENV_DIR / "Scripts" / "python.exe" if os.name == "nt" else VENV_DIR / "bin" / "python"
# -----------------------------
# Utilities
# -----------------------------
def run(cmd, cwd=None):
print(f"\n>>> {' '.join(map(str, cmd))}")
result = subprocess.run(cmd, cwd=cwd)
if result.returncode != 0:
sys.exit(result.returncode)
def safe_rmtree(path):
if path.exists():
print(f"Removing {path}")
shutil.rmtree(path, ignore_errors=True)
def copy_tree(src, dst):
if src.exists():
shutil.copytree(src, dst, dirs_exist_ok=True)
# -----------------------------
# Tasks
# -----------------------------
def cleanup():
safe_rmtree(ROOT / "result")
safe_rmtree(ROOT / "build")
safe_rmtree(ROOT / "dist")
safe_rmtree(ROOT / "keywords")
safe_rmtree(ROOT / "robotframework_flaui.egg-info")
def venv():
if not VENV_DIR.exists():
run([sys.executable, "-m", "venv", str(VENV_DIR)])
run([str(VENV_PYTHON), "-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel"])
run([str(VENV_PYTHON), "-m", "pip", "install", "-r", "requirements-dev.txt"])
def build():
cleanup()
venv()
run([str(VENV_PYTHON), "-m", "build"])
run([str(VENV_PYTHON), "libdoc.py"])
def install():
build()
run([str(VENV_PYTHON), "-m", "pip", "install", "."])
def test_uia2():
run([
str(VENV_PYTHON),
"-m", "robot",
"--name", "UIA2",
"--variable", "UIA:UIA2",
"--outputdir", "../result/uia2",
"."
], cwd=ROOT / "atests")
def test_uia3():
run([
str(VENV_PYTHON),
"-m", "robot",
"--name", "UIA3",
"--variable", "UIA:UIA3",
"--outputdir", "../result/uia3",
"."
], cwd=ROOT / "atests")
def pylint():
(ROOT / "result").mkdir(exist_ok=True)
run([str(VENV_PYTHON), "-m", "pylint", "src"])
def robocop():
run([str(VENV_PYTHON), "robocop_lint.py"])
def test():
install()
robocop()
pylint()
test_uia2()
test_uia3()
run([
str(VENV_PYTHON),
"-m", "robot.rebot",
"--name", "ATests",
"--outputdir", "result",
"-x", "rebot_xunit.xml",
"result/uia2/output.xml",
"result/uia3/output.xml",
])
# Merge screenshots
copy_tree(ROOT / "result/uia2/screenshots", ROOT / "result/screenshots")
copy_tree(ROOT / "result/uia3/screenshots", ROOT / "result/screenshots")
for path in (ROOT / "result/uia2").rglob("*.jpg"):
shutil.copy(path, ROOT / "result")
for path in (ROOT / "result/uia3").rglob("*.jpg"):
shutil.copy(path, ROOT / "result")
run([str(VENV_PYTHON), "parsly.py"])
# -----------------------------
# CLI Dispatcher
# -----------------------------
TASKS = {
"cleanup": cleanup,
"venv": venv,
"build": build,
"install": install,
"test": test,
"test_uia2": test_uia2,
"test_uia3": test_uia3,
"pylint": pylint,
"robocop": robocop,
}
if __name__ == "__main__":
print("Running:", __file__)
print("Args:", sys.argv)
if len(sys.argv) < 2:
print(f"Available tasks: {', '.join(TASKS)}")
sys.exit(1)
task = sys.argv[1]
if task not in TASKS:
print(f"Unknown task: {task}")
sys.exit(1)
TASKS[task]()