Exemplo n.º 1
0
def test_make_tree_with_references_from_directory(
    mock_get_previous_parents: Mock,
    mock_current_directory_path: Path,
    mock_search_string: str,
) -> None:
    directories_expected = 0
    files_expected = 0
    result = Tree._make_tree_with_references(
        path=mock_current_directory_path, search_string=mock_search_string
    )
    for line in result:
        display_name = get_tree_line(tree_line(line))
        args, _ = mock_get_previous_parents.call_args

        assert isinstance(line, Tree)

        if Path(line.path).is_dir():
            assert line in line._found_directories

        if not line._found_directories.get(line.parent_path):
            if line.parent_path is None:
                assert Tree._get_previous_parents(line).call_args is None
            else:
                assert isinstance(args[0], Tree)

        assert line._mount_tree_line() == tree_line(line, line._string_references)
        assert mock_get_previous_parents.called
        assert line.display_name == display_name
        directories_expected += 1
        files_expected += 1
    assert directories_expected > 0
    assert files_expected > 0
Exemplo n.º 2
0
def test_make_tree_with_references_from_file(
    mock_get_previous_parents: Mock, mock_path_with_file: Path
) -> None:
    files_expected = 0
    result = Tree._make_tree_with_references(
        path=mock_path_with_file, search_string="tree",
    )
    for line in result:
        display_name = get_tree_line(tree_line(line))
        args, _ = mock_get_previous_parents.call_args

        assert isinstance(line, Tree)

        if not line._found_directories.get(line.parent_path):
            if line.parent_path is None:
                assert Tree._get_previous_parents(line).call_args is None
            else:
                assert isinstance(args[0], Tree)

        assert mock_get_previous_parents.called
        assert line._mount_tree_line() == tree_line(line, line._string_references)
        assert line.display_name == display_name
        files_expected += 1
    assert files_expected > 0