2022-05-17 10:50:42 +02:00
|
|
|
load("@bazel_skylib//lib:paths.bzl", "paths")
|
|
|
|
|
2020-08-30 14:09:34 +08:00
|
|
|
# py_test_module_list creates a py_test target for each
|
2020-08-06 10:58:42 -07:00
|
|
|
# Python file in `files`
|
2022-05-19 21:46:55 -07:00
|
|
|
|
2022-07-19 12:21:19 +08:00
|
|
|
def py_test_module_list(files, size, deps, extra_srcs=[], name_suffix="", **kwargs):
|
2020-08-30 14:09:34 +08:00
|
|
|
for file in files:
|
|
|
|
# remove .py
|
2022-05-17 10:50:42 +02:00
|
|
|
name = paths.split_extension(file)[0] + name_suffix
|
|
|
|
if name == file:
|
|
|
|
basename = basename + "_test"
|
2020-08-30 14:09:34 +08:00
|
|
|
native.py_test(
|
|
|
|
name = name,
|
|
|
|
size = size,
|
2020-12-20 14:54:18 -08:00
|
|
|
main = file,
|
2020-08-30 14:09:34 +08:00
|
|
|
srcs = extra_srcs + [file],
|
2022-07-19 12:21:19 +08:00
|
|
|
deps = deps,
|
2020-08-30 14:09:34 +08:00
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
|
|
|
def py_test_run_all_subdirectory(include, exclude, extra_srcs, **kwargs):
|
2022-05-17 10:50:42 +02:00
|
|
|
for file in native.glob(include = include, exclude = exclude, allow_empty=False):
|
2020-08-30 14:09:34 +08:00
|
|
|
print(file)
|
2022-05-17 10:50:42 +02:00
|
|
|
basename = paths.split_extension(file)[0]
|
|
|
|
if basename == file:
|
|
|
|
basename = basename + "_test"
|
2020-08-30 14:09:34 +08:00
|
|
|
native.py_test(
|
2022-05-17 10:50:42 +02:00
|
|
|
name = basename,
|
2020-08-30 14:09:34 +08:00
|
|
|
srcs = extra_srcs + [file],
|
|
|
|
**kwargs
|
|
|
|
)
|
2022-02-27 08:07:34 +01:00
|
|
|
|
|
|
|
# Runs all included notebooks as py_test targets, by first converting them to .py files with "test_myst_doc.py".
|
2022-07-09 19:47:21 -07:00
|
|
|
def py_test_run_all_notebooks(include, exclude, allow_empty=False, **kwargs):
|
|
|
|
for file in native.glob(include = include, exclude = exclude, allow_empty=allow_empty):
|
2022-02-27 08:07:34 +01:00
|
|
|
print(file)
|
2022-05-17 10:50:42 +02:00
|
|
|
basename = paths.split_extension(file)[0]
|
|
|
|
if basename == file:
|
|
|
|
basename = basename + "_test"
|
2022-02-27 08:07:34 +01:00
|
|
|
native.py_test(
|
2022-05-17 10:50:42 +02:00
|
|
|
name = basename,
|
2022-02-27 08:07:34 +01:00
|
|
|
main = "test_myst_doc.py",
|
2022-05-17 10:50:42 +02:00
|
|
|
srcs = ["//doc:test_myst_doc.py"],
|
|
|
|
# --find-recursively will look for file in all
|
|
|
|
# directories inside cwd recursively if it cannot
|
|
|
|
# find it right away. This allows to deal with
|
|
|
|
# mismatches between `name` and `data` args.
|
|
|
|
args = ["--find-recursively", "--path", file],
|
2022-02-27 08:07:34 +01:00
|
|
|
**kwargs
|
|
|
|
)
|