X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=test%2Fintegration%2Ftestlib%2Fcheck.py;h=0f3b414b0f4fa972718231c594ce5ab2e4f3f1a1;hb=c6a15e27d934e90a1f3a26438dddb395bdc9de19;hp=524ca623f949bb86274271a67d9b17f8115ea6d5;hpb=3d787920d51a35e74e442c7265be3b13b69ad8e4;p=tinc diff --git a/test/integration/testlib/check.py b/test/integration/testlib/check.py index 524ca623..0f3b414b 100755 --- a/test/integration/testlib/check.py +++ b/test/integration/testlib/check.py @@ -10,6 +10,12 @@ Val = T.TypeVar("Val") Num = T.TypeVar("Num", int, float) +def blank(value: T.AnyStr) -> None: + """Check that value is an empty or blank string.""" + if not isinstance(value, str) or value.strip(): + raise ValueError(f'expected "{value!r}" to be a blank string') + + def false(value: T.Any) -> None: """Check that value is falsy.""" if value: @@ -52,6 +58,13 @@ def in_range(value: Num, gte: Num, lte: Num) -> None: raise ValueError(f"value {value} must be between {gte} and {lte}") +def lines(text: T.AnyStr, num: int) -> None: + """Check that text splits into `num` lines.""" + rows = text.splitlines() + if len(rows) != num: + raise ValueError(f"expected {num} lines, got {len(rows)}: {rows}") + + def is_in(needle: Val, *haystacks: T.Container[Val]) -> None: """Check that at least one haystack includes needle.""" for haystack in haystacks: @@ -91,6 +104,12 @@ def files_eq(path0: str, path1: str) -> None: def file_exists(path: T.Union[str, Path]) -> None: - """Check that file or directory exists.""" - if not os.path.exists(path): - raise ValueError("expected path '{path}' to exist") + """Check that file exists.""" + if not os.path.isfile(path): + raise ValueError(f"expected file '{path}' to exist") + + +def dir_exists(path: T.Union[str, Path]) -> None: + """Check that directory exists.""" + if not os.path.isdir(path): + raise ValueError(f"expected directory '{path}' to exist")