Commit 566a87d0 authored by Matthias Bernt's avatar Matthias Bernt
Browse files

fix type annotations for assertions

the functions always get a str (from the xml attributes)
parent a15fd1fc
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
from math import inf
from typing import (
    Any,
    Callable,
    Optional
)

from galaxy.util import asbool
from galaxy.util.bytesize import parse_bytesize


def _assert_number(count, n, delta, min, max, negate, n_text, min_max_text):
def _assert_number(
    count,
    n: Optional[str],
    delta: str,
    min: Optional[str],
    max: Optional[str],
    negate: str,
    n_text,
    min_max_text
):
    """
    helper function for assering that count is in
    - [n-delta:n+delta]
@@ -26,12 +40,12 @@ def _assert_number(count, n, delta, min, max, negate, n_text, min_max_text):
        )
    if min is not None or max is not None:
        if min is None:
            min = -inf  # also replacing min/max for output
            min = "-inf"  # also replacing min/max for output
            min_bytes = -inf
        else:
            min_bytes = parse_bytesize(min)
        if max is None:
            max = inf
            max = "inf"
            max_bytes = inf
        else:
            max_bytes = parse_bytesize(max)
@@ -42,7 +56,18 @@ def _assert_number(count, n, delta, min, max, negate, n_text, min_max_text):


def _assert_presence_number(
    output, text, n, delta, min, max, negate, check_presence_foo, count_foo, presence_text, n_text, min_max_text
    output,
    text,
    n: Optional[str],
    delta: str,
    min: Optional[str],
    max: Optional[str],
    negate: str,
    check_presence_foo: Callable[[Any, Any], bool],
    count_foo: Callable[[Any, Any], int],
    presence_text: str,
    n_text: str,
    min_max_text: str
):
    """
    helper function to assert that
+6 −6
Original line number Diff line number Diff line
@@ -55,12 +55,12 @@ def assert_has_archive_member(
    path,
    verify_assertions_function,
    children,
    all="false",
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    all="False",
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """Recursively checks the specified children assertions against the text of
    the first element matching the specified path found within the archive.
+5 −5
Original line number Diff line number Diff line
@@ -5,11 +5,11 @@ from ._util import _assert_number

def assert_has_size(
    output_bytes,
    value: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    value: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """
    Asserts the specified output has a size of the specified value,
+5 −5
Original line number Diff line number Diff line
@@ -20,13 +20,13 @@ def get_first_line(output, comment):

def assert_has_n_columns(
    output,
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    sep="\t",
    comment="",
    negate: bool = False,
    negate: str = "False",
):
    """Asserts the tabular output contains n columns. The optional
    sep argument specifies the column seperator used to determine the
+25 −25
Original line number Diff line number Diff line
@@ -10,11 +10,11 @@ from ._util import (
def assert_has_text(
    output,
    text,
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """Asserts specified output contains the substring specified by
    the argument text. The exact number of occurrences can be
@@ -46,11 +46,11 @@ def assert_not_has_text(output, text):
def assert_has_line(
    output,
    line,
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """Asserts the specified output contains the line specified by the
    argument line. The exact number of occurrences can be optionally
@@ -74,11 +74,11 @@ def assert_has_line(

def assert_has_n_lines(
    output,
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """Asserts the specified output contains ``n`` lines allowing
    for a difference in the number of lines (delta)
@@ -100,11 +100,11 @@ def assert_has_n_lines(
def assert_has_text_matching(
    output,
    expression,
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """Asserts the specified output contains text matching the
    regular expression specified by the argument expression.
@@ -130,11 +130,11 @@ def assert_has_text_matching(
def assert_has_line_matching(
    output,
    expression,
    n: Optional[int] = None,
    delta: int = 0,
    min: Optional[int] = None,
    max: Optional[int] = None,
    negate: bool = False,
    n: Optional[str] = None,
    delta: str = "0",
    min: Optional[str] = None,
    max: Optional[str] = None,
    negate: str = "False",
):
    """Asserts the specified output contains a line matching the
    regular expression specified by the argument expression. If n is given
Loading