2021-04-11 19:58:37 +00:00
|
|
|
"""acceptance testing"""
|
|
|
|
# Copyright 2021 ipydrawio contributors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2020-08-16 20:33:33 +00:00
|
|
|
import shutil
|
2021-01-26 04:41:26 +00:00
|
|
|
import subprocess
|
2020-08-16 20:33:33 +00:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from . import project as P
|
|
|
|
|
2021-01-26 04:41:26 +00:00
|
|
|
PABOT_DEFAULTS = [
|
|
|
|
"--testlevelsplit",
|
|
|
|
"--processes",
|
2021-01-29 15:02:28 +00:00
|
|
|
P.ATEST_PROCS,
|
2021-01-26 04:41:26 +00:00
|
|
|
"--artifactsinsubfolders",
|
|
|
|
"--artifacts",
|
2021-01-29 15:02:28 +00:00
|
|
|
"png,log,txt,dio,svg,xml,pdf,ipynb",
|
2021-01-26 04:41:26 +00:00
|
|
|
]
|
2020-08-16 20:33:33 +00:00
|
|
|
|
|
|
|
|
2021-01-26 04:41:26 +00:00
|
|
|
def run_tests(attempt=0, extra_args=None):
|
|
|
|
extra_args = extra_args or []
|
2020-08-16 20:33:33 +00:00
|
|
|
|
2021-01-26 04:41:26 +00:00
|
|
|
stem = P.get_atest_stem(attempt=attempt, extra_args=extra_args)
|
|
|
|
out_dir = P.ATEST_OUT / stem
|
2020-08-16 20:33:33 +00:00
|
|
|
|
2021-01-26 04:41:26 +00:00
|
|
|
if attempt > 1:
|
|
|
|
prev_stem = P.get_atest_stem(attempt=attempt - 1, extra_args=extra_args)
|
|
|
|
previous = P.ATEST_OUT / prev_stem / P.ATEST_OUT_XML
|
2020-08-16 20:33:33 +00:00
|
|
|
if previous.exists():
|
|
|
|
extra_args += ["--rerunfailed", str(previous)]
|
|
|
|
|
2021-01-26 04:41:26 +00:00
|
|
|
runner = ["pabot", *PABOT_DEFAULTS]
|
|
|
|
|
|
|
|
if "--dryrun" in extra_args:
|
|
|
|
runner = ["robot"]
|
2020-08-16 20:33:33 +00:00
|
|
|
|
2021-07-06 13:40:08 +00:00
|
|
|
try:
|
|
|
|
__import__("jupyterlite")
|
|
|
|
except Exception as err:
|
|
|
|
print("skipping lite tests because", err)
|
|
|
|
extra_args += ["--exclude", "app:lite"]
|
|
|
|
|
2020-08-16 20:33:33 +00:00
|
|
|
args = [
|
2021-01-26 04:41:26 +00:00
|
|
|
*runner,
|
|
|
|
*extra_args,
|
2020-08-16 20:33:33 +00:00
|
|
|
"--name",
|
2021-01-29 15:02:28 +00:00
|
|
|
f"""{P.PLATFORM[:3]}{P.PY_MAJOR}""",
|
2020-08-16 20:33:33 +00:00
|
|
|
"--outputdir",
|
|
|
|
out_dir,
|
|
|
|
"--variable",
|
|
|
|
f"OS:{P.PLATFORM}",
|
|
|
|
"--variable",
|
|
|
|
f"PY:{P.PY_MAJOR}",
|
2021-07-06 13:40:08 +00:00
|
|
|
"--variable",
|
|
|
|
f"DEMO:{P.DEMO}",
|
2020-08-16 20:33:33 +00:00
|
|
|
"--randomize",
|
|
|
|
"all",
|
2021-01-26 04:41:26 +00:00
|
|
|
"--xunit",
|
|
|
|
".".join(["xunit", "xml"]),
|
|
|
|
".",
|
2020-08-16 20:33:33 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
if out_dir.exists():
|
2021-01-26 04:41:26 +00:00
|
|
|
print(">>> trying to clean out {}".format(out_dir), flush=True)
|
2020-08-16 20:33:33 +00:00
|
|
|
try:
|
|
|
|
shutil.rmtree(out_dir)
|
|
|
|
except Exception as err:
|
2021-01-26 04:41:26 +00:00
|
|
|
print(
|
|
|
|
"... error, hopefully harmless: {}".format(err),
|
|
|
|
flush=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
if not out_dir.exists():
|
|
|
|
print(">>> trying to prepare output directory: {}".format(out_dir), flush=True)
|
|
|
|
try:
|
|
|
|
out_dir.mkdir(parents=True)
|
|
|
|
except Exception as err:
|
|
|
|
print(
|
|
|
|
"... Error, hopefully harmless: {}".format(err),
|
|
|
|
flush=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
str_args = [*map(str, args)]
|
|
|
|
print(">>> ", " ".join(str_args), flush=True)
|
|
|
|
|
|
|
|
proc = subprocess.Popen(str_args, cwd=P.ATEST)
|
2020-08-16 20:33:33 +00:00
|
|
|
|
|
|
|
try:
|
2021-01-26 04:41:26 +00:00
|
|
|
return proc.wait()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
proc.kill()
|
|
|
|
return proc.wait()
|
|
|
|
|
|
|
|
|
|
|
|
def attempt_atest_with_retries(extra_args=None):
|
|
|
|
"""retry the robot tests a number of times"""
|
|
|
|
extra_args = list(extra_args or [])
|
2020-08-16 20:33:33 +00:00
|
|
|
attempt = 0
|
|
|
|
error_count = -1
|
|
|
|
|
2021-01-29 15:02:28 +00:00
|
|
|
retries = P.ATEST_RETRIES
|
|
|
|
extra_args += P.ATEST_ARGS
|
2020-08-16 20:33:33 +00:00
|
|
|
|
|
|
|
while error_count != 0 and attempt <= retries:
|
|
|
|
attempt += 1
|
2021-01-26 04:41:26 +00:00
|
|
|
print("attempt {} of {}...".format(attempt, retries + 1), flush=True)
|
2020-08-16 20:33:33 +00:00
|
|
|
start_time = time.time()
|
2021-01-26 04:41:26 +00:00
|
|
|
error_count = run_tests(attempt=attempt, extra_args=extra_args)
|
|
|
|
print(
|
|
|
|
error_count,
|
|
|
|
"errors in",
|
|
|
|
int(time.time() - start_time),
|
|
|
|
"seconds",
|
|
|
|
flush=True,
|
|
|
|
)
|
2020-08-16 20:33:33 +00:00
|
|
|
|
|
|
|
return error_count
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-01-26 04:41:26 +00:00
|
|
|
sys.exit(attempt_atest_with_retries(extra_args=sys.argv[1:]))
|