Пример #1
0
def test_find_last_match(
    input_list: List[Tuple[Optional[str], Optional[str]]],
    reference: str,
    expected_idx: int,
) -> None:
    csp = create_search_path(input_list)
    assert csp.find_last_match(SearchPath(reference[0], reference[1])) == expected_idx
Пример #2
0
def test_initialize_with_config_dir() -> None:
    try:
        assert not GlobalHydra().is_initialized()
        hydra.experimental.initialize(config_dir="../hydra/test_utils/configs",
                                      strict=True)
        assert GlobalHydra().is_initialized()

        config_search_path = (
            GlobalHydra.instance().hydra.config_loader.config_search_path)
        idx = config_search_path.find_first_match(
            SearchPath(provider="main", search_path=None))
        assert idx != -1
    finally:
        GlobalHydra().clear()
Пример #3
0
def create_search_path(
    base_list: List[Tuple[Optional[str], Optional[str]]]
) -> ConfigSearchPath:
    csp = ConfigSearchPath()
    csp.config_search_path = [SearchPath(x[0], x[1]) for x in base_list]
    return csp
Пример #4
0
    assert csp.find_first_match(sp) == expected_idx


@pytest.mark.parametrize(  # type: ignore
    "base_list, provider, path, anchor_provider, result_list",
    [
        # appending to an empty list
        ([], "foo", "/path", None, [("foo", "/path")]),
        # appending to a non empty list
        ([("f1", "/p1")], "f2", "/p2", None, [("f1", "/p1"), ("f2", "/p2")]),
        # appending after an anchor at index 0
        (
            [("f1", "A"), ("f2", "B")],
            "f3",
            "B",
            SearchPath(None, "A"),
            [("f1", "A"), ("f3", "B"), ("f2", "B")],
        ),
        # appending after an anchor at the end of the list
        (
            [("f1", "A"), ("f2", "B")],
            "f3",
            "B",
            SearchPath(None, "B"),
            [("f1", "A"), ("f2", "B"), ("f3", "B")],
        ),
        # appending after a non existent anchor
        (
            [],
            "new_provider",
            "/path",
Пример #5
0
def create_search_path(base_list):
    csp = ConfigSearchPath()
    csp.config_search_path = [SearchPath(x[0], x[1]) for x in base_list]
    return csp
Пример #6
0
def test_find_first_match(input_list, reference, expected_idx):
    csp = create_search_path(input_list)
    sp = SearchPath(reference[0], reference[1])
    assert csp.find_first_match(sp) == expected_idx