Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kentkr committed Aug 12, 2023
1 parent e518fce commit 9e6d5a5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 38 deletions.
82 changes: 44 additions & 38 deletions test/unit/test_graph_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def id_macro(arg):
(["1+Y.f"], [], {"m.X.c", "m.Y.f"}),
# childrens parents
(["@X.c"], [], {"m.X.a", "m.X.c", "m.Y.f", "m.X.g"}),
(["[email protected]"], [], {"m.X.a", "m.X.c", "m.Y.f", "m.X.g"}),
# multiple selection/exclusion
(["tag:abc", "tag:bcef"], [], {"m.X.a", "m.Y.b", "m.X.c", "m.X.e", "m.Y.f"}),
(["tag:abc", "tag:bcef"], ["tag:efg"], {"m.X.a", "m.Y.b", "m.X.c"}),
Expand Down Expand Up @@ -138,48 +139,51 @@ def test_run_specs(include, exclude, expected):


param_specs = [
("a", False, None, False, None, "fqn", "a", False),
("+a", True, None, False, None, "fqn", "a", False),
("256+a", True, 256, False, None, "fqn", "a", False),
("a+", False, None, True, None, "fqn", "a", False),
("a+256", False, None, True, 256, "fqn", "a", False),
("+a+", True, None, True, None, "fqn", "a", False),
("16+a+32", True, 16, True, 32, "fqn", "a", False),
("@a", False, None, False, None, "fqn", "a", True),
("a.b", False, None, False, None, "fqn", "a.b", False),
("+a.b", True, None, False, None, "fqn", "a.b", False),
("256+a.b", True, 256, False, None, "fqn", "a.b", False),
("a.b+", False, None, True, None, "fqn", "a.b", False),
("a.b+256", False, None, True, 256, "fqn", "a.b", False),
("+a.b+", True, None, True, None, "fqn", "a.b", False),
("16+a.b+32", True, 16, True, 32, "fqn", "a.b", False),
("@a.b", False, None, False, None, "fqn", "a.b", True),
("a.b.*", False, None, False, None, "fqn", "a.b.*", False),
("+a.b.*", True, None, False, None, "fqn", "a.b.*", False),
("256+a.b.*", True, 256, False, None, "fqn", "a.b.*", False),
("a.b.*+", False, None, True, None, "fqn", "a.b.*", False),
("a.b.*+256", False, None, True, 256, "fqn", "a.b.*", False),
("+a.b.*+", True, None, True, None, "fqn", "a.b.*", False),
("16+a.b.*+32", True, 16, True, 32, "fqn", "a.b.*", False),
("@a.b.*", False, None, False, None, "fqn", "a.b.*", True),
("tag:a", False, None, False, None, "tag", "a", False),
("+tag:a", True, None, False, None, "tag", "a", False),
("256+tag:a", True, 256, False, None, "tag", "a", False),
("tag:a+", False, None, True, None, "tag", "a", False),
("tag:a+256", False, None, True, 256, "tag", "a", False),
("+tag:a+", True, None, True, None, "tag", "a", False),
("16+tag:a+32", True, 16, True, 32, "tag", "a", False),
("@tag:a", False, None, False, None, "tag", "a", True),
("source:a", False, None, False, None, "source", "a", False),
("source:a+", False, None, True, None, "source", "a", False),
("source:a+1", False, None, True, 1, "source", "a", False),
("source:a+32", False, None, True, 32, "source", "a", False),
("@source:a", False, None, False, None, "source", "a", True),
("a", False, None, False, None, "fqn", "a", False, None),
("+a", True, None, False, None, "fqn", "a", False, None),
("256+a", True, 256, False, None, "fqn", "a", False, None),
("a+", False, None, True, None, "fqn", "a", False, None),
("a+256", False, None, True, 256, "fqn", "a", False, None),
("+a+", True, None, True, None, "fqn", "a", False, None),
("16+a+32", True, 16, True, 32, "fqn", "a", False, None),
("@a", False, None, False, None, "fqn", "a", True, None),
("20@a", False, None, False, None, "fqn", "a", True, 20),
("a.b", False, None, False, None, "fqn", "a.b", False, None),
("+a.b", True, None, False, None, "fqn", "a.b", False, None),
("256+a.b", True, 256, False, None, "fqn", "a.b", False, None),
("a.b+", False, None, True, None, "fqn", "a.b", False, None),
("a.b+256", False, None, True, 256, "fqn", "a.b", False, None),
("+a.b+", True, None, True, None, "fqn", "a.b", False, None),
("16+a.b+32", True, 16, True, 32, "fqn", "a.b", False, None),
("@a.b", False, None, False, None, "fqn", "a.b", True, None),
("[email protected]", False, None, False, None, "fqn", "a.b", True, 5),
("a.b.*", False, None, False, None, "fqn", "a.b.*", False, None),
("+a.b.*", True, None, False, None, "fqn", "a.b.*", False, None),
("256+a.b.*", True, 256, False, None, "fqn", "a.b.*", False, None),
("a.b.*+", False, None, True, None, "fqn", "a.b.*", False, None),
("a.b.*+256", False, None, True, 256, "fqn", "a.b.*", False, None),
("+a.b.*+", True, None, True, None, "fqn", "a.b.*", False, None),
("16+a.b.*+32", True, 16, True, 32, "fqn", "a.b.*", False, None),
("@a.b.*", False, None, False, None, "fqn", "a.b.*", True, None),
("[email protected].*", False, None, False, None, "fqn", "a.b.*", True, 12),
("tag:a", False, None, False, None, "tag", "a", False, None),
("+tag:a", True, None, False, None, "tag", "a", False, None),
("256+tag:a", True, 256, False, None, "tag", "a", False, None),
("tag:a+", False, None, True, None, "tag", "a", False, None),
("tag:a+256", False, None, True, 256, "tag", "a", False, None),
("+tag:a+", True, None, True, None, "tag", "a", False, None),
("16+tag:a+32", True, 16, True, 32, "tag", "a", False, None),
("3@tag:a", False, None, False, None, "tag", "a", True, 3),
("source:a", False, None, False, None, "source", "a", False, None),
("source:a+", False, None, True, None, "source", "a", False, None),
("source:a+1", False, None, True, 1, "source", "a", False, None),
("source:a+32", False, None, True, 32, "source", "a", False, None),
("1@source:a", False, None, False, None, "source", "a", True, 1),
]


@pytest.mark.parametrize(
"spec,parents,parents_depth,children,children_depth,filter_type,filter_value,childrens_parents",
"spec,parents,parents_depth,children,children_depth,filter_type,filter_value,childrens_parents,childrens_parents_depth",
param_specs,
ids=id_macro,
)
Expand All @@ -192,6 +196,7 @@ def test_parse_specs(
filter_type,
filter_value,
childrens_parents,
childrens_parents_depth
):
parsed = graph_selector.SelectionCriteria.from_single_spec(spec)
assert parsed.parents == parents
Expand All @@ -201,6 +206,7 @@ def test_parse_specs(
assert parsed.method == filter_type
assert parsed.value == filter_value
assert parsed.childrens_parents == childrens_parents
assert parsed.childrens_parents_depth == childrens_parents_depth


invalid_specs = [
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_graph_selector_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_raw_parse_simple():
assert not result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth is None


def test_raw_parse_simple_infer_path():
Expand All @@ -37,6 +38,7 @@ def test_raw_parse_simple_infer_path():
assert not result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth is None


def test_raw_parse_simple_infer_path_modified():
Expand All @@ -51,6 +53,22 @@ def test_raw_parse_simple_infer_path_modified():
assert not result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth is None


def test_raw_parse_simple_infer_fqn_childrens_parents():
raw = "1@asdf"
result = SelectionCriteria.from_single_spec(raw)
assert result.raw == raw
assert result.method == MethodName.FQN
assert result.method_arguments == []
assert result.value == "asdf"
assert result.childrens_parents
assert not result.children
assert not result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth == 1


def test_raw_parse_simple_infer_fqn_parents():
Expand All @@ -65,6 +83,7 @@ def test_raw_parse_simple_infer_fqn_parents():
assert result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth is None


def test_raw_parse_simple_infer_fqn_children():
Expand All @@ -79,6 +98,7 @@ def test_raw_parse_simple_infer_fqn_children():
assert not result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth is None


def test_raw_parse_complex():
Expand All @@ -93,6 +113,7 @@ def test_raw_parse_complex():
assert result.parents
assert result.parents_depth == 2
assert result.children_depth == 4
assert result.childrens_parents_depth is None


def test_raw_parse_weird():
Expand All @@ -108,6 +129,7 @@ def test_raw_parse_weird():
assert not result.parents
assert result.parents_depth is None
assert result.children_depth is None
assert result.childrens_parents_depth is None


def test_raw_parse_invalid():
Expand Down

0 comments on commit 9e6d5a5

Please sign in to comment.