19"""Test that the `--help` option works for all scripts in this package
25from pathlib
import Path
26from subprocess
import check_call
34CONDA_BUILD_TEST = os.getenv(
"CONDA_BUILD_STATE") ==
"TEST"
37DEFAULT_PYTEST_ARGUMENTS = [
40 "--junit-xml=junit-scripts.xml",
44HERE = Path(__file__).parent.absolute()
45BUILDDIR = (HERE / Path(
".")).resolve()
46SRCDIR = (HERE / Path(
".")).resolve()
47TOPBUILDDIR = (HERE / Path(
"../..")).resolve()
48if PACKAGE ==
"lalapps":
51 BINDIR = TOPBUILDDIR /
"bin"
54EXCLUDEFILE = SRCDIR /
"exclude-scripts.txt"
60 """Read all excluded file paths from the given source file
64 with open(str(source),
"r")
as fobj:
66 if isinstance(line, bytes):
67 line = line.decode(
"utf-8")
68 content = line.strip().split(
"#", 1)[0].strip()
71 except FileNotFoundError
as exc:
72 warnings.warn(str(exc))
77 """Yield script names from the relevant Makefile list variable.
79 with path.open(
"r")
as makefile:
84 if line.startswith(var):
87 value = line.split(
"=", 1)[1].rstrip(
" \\")
91 elif not line
or line.endswith(
"$(END_OF_LIST)"):
96 yield line.rstrip(
"\\").strip()
100 """Yields the script names of python files in the given directory.
102 This is just the file name
with the trailing ``.py`` extension removed.
104 for pyf
in path.glob(
"*.py"):
108 shf = Path(str(pyf)[:-3])
118except (FileNotFoundError, ValueError, TypeError):
127 @pytest.mark.parametrize('script', SCRIPTS)
129 """Test that `<script> --help` can be executed for the named script.
131 if script
in EXCLUDE:
132 pytest.skip(
"excluded {}".format(str(script)))
134 check_call([script,
"--help"], shell=
False)
136 startdir = os.getcwd()
137 os.chdir(str(BINDIR))
139 check_call(
"./{} --help".format(script), shell=
True)
147if __name__ ==
"__main__":
148 args = sys.argv[1:]
or DEFAULT_PYTEST_ARGUMENTS
149 code = pytest.main(args=[__file__] + args)
def test_help(script)
Test that <script> --help can be executed for the named script.
def parse_pybin_scripts(path, var="pybin_scripts")
Yield script names from the relevant Makefile list variable.
def find_scripts(path)
Yields the script names of python files in the given directory.
def read_exclude_file(source)
Read all excluded file paths from the given source file.