






"""simple docstring"""






import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


UpperCAmelCase_     :				Union[str, Any]         =				"""http://www.mocksite.com/file1.txt"""
UpperCAmelCase_     :				Dict         =				"""\"text\": [\"foo\", \"foo\"]"""
UpperCAmelCase_     :				Tuple         =				"""6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8"""




class 							lowerCAmelCase__       :






      '''simple docstring'''

      __UpperCamelCase							=						2_0_0
      __UpperCamelCase							=						{"Content-Length": "100"}
      __UpperCamelCase							=						{}
      def _SCREAMING_SNAKE_CASE				(		self  :						Union[str, Any]		,			**lowercase_  :						List[str]):




          '''simple docstring'''


          return [bytes(lowercase_		,			'''utf-8''')]



def       _A    (*__a					,       **__a							)				-> Optional[int]:
    """simple docstring"""






    return MockResponse()



@pytest.mark.parametrize('''urls_type'''					,       [str, list, dict]							)
def       _A    (__a					,       __a					,       __a							)				-> Dict:
    """simple docstring"""






    import requests

    monkeypatch.setattr(__a					,       '''request'''					,       __a							)

    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	URL
    if issubclass(__a					,       __a							):
        SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	url
    elif issubclass(__a					,       __a							):
        SCREAMING_SNAKE_CASE_   :						Tuple							=	[url]
    elif issubclass(__a					,       __a							):
        SCREAMING_SNAKE_CASE_   :						Optional[int]							=	{'''train''': url}
    SCREAMING_SNAKE_CASE_   :						List[Any]							=	'''dummy'''
    SCREAMING_SNAKE_CASE_   :						int							=	'''downloads'''
    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	tmp_path
    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	DownloadConfig(
        cache_dir=os.path.join(__a					,       __a							)					,       use_etag=__a					,       )
    SCREAMING_SNAKE_CASE_   :						List[str]							=	DownloadManager(dataset_name=__a					,       download_config=__a							)
    SCREAMING_SNAKE_CASE_   :						List[Any]							=	dl_manager.download(__a							)
    SCREAMING_SNAKE_CASE_   :						List[Any]							=	urls
    for downloaded_paths in [downloaded_paths]:
        if isinstance(__a					,       __a							):
            SCREAMING_SNAKE_CASE_   :						List[Any]							=	[downloaded_paths]
            SCREAMING_SNAKE_CASE_   :						List[str]							=	[urls]
        elif isinstance(__a					,       __a							):
            assert "train" in downloaded_paths.keys()
            SCREAMING_SNAKE_CASE_   :						int							=	downloaded_paths.values()
            SCREAMING_SNAKE_CASE_   :						str							=	urls.values()
        assert downloaded_paths
        for downloaded_path, input_url in zip(__a					,       __a							):
            assert downloaded_path == dl_manager.downloaded_paths[input_url]
            SCREAMING_SNAKE_CASE_   :						int							=	Path(__a							)
            SCREAMING_SNAKE_CASE_   :						List[Any]							=	downloaded_path.parts
            assert parts[-1] == HASH
            assert parts[-2] == cache_subdir
            assert downloaded_path.exists()
            SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	downloaded_path.read_text()
            assert content == CONTENT
            SCREAMING_SNAKE_CASE_   :						str							=	downloaded_path.with_suffix('''.json'''							)
            assert metadata_downloaded_path.exists()
            SCREAMING_SNAKE_CASE_   :						List[str]							=	json.loads(metadata_downloaded_path.read_text()							)
            assert metadata_content == {"url": URL, "etag": None}



@pytest.mark.parametrize('''paths_type'''					,       [str, list, dict]							)
def       _A    (__a					,       __a					,       __a							)				-> Optional[int]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						Any							=	str(__a							)
    if issubclass(__a					,       __a							):
        SCREAMING_SNAKE_CASE_   :						int							=	filename
    elif issubclass(__a					,       __a							):
        SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	[filename]
    elif issubclass(__a					,       __a							):
        SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	{'''train''': filename}
    SCREAMING_SNAKE_CASE_   :						Tuple							=	'''dummy'''
    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	xz_file.parent
    SCREAMING_SNAKE_CASE_   :						Tuple							=	'''extracted'''
    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	DownloadConfig(
        cache_dir=__a					,       use_etag=__a					,       )
    SCREAMING_SNAKE_CASE_   :						Any							=	DownloadManager(dataset_name=__a					,       download_config=__a							)
    SCREAMING_SNAKE_CASE_   :						str							=	dl_manager.extract(__a							)
    SCREAMING_SNAKE_CASE_   :						List[str]							=	paths
    for extracted_paths in [extracted_paths]:
        if isinstance(__a					,       __a							):
            SCREAMING_SNAKE_CASE_   :						Dict							=	[extracted_paths]
            SCREAMING_SNAKE_CASE_   :						Optional[int]							=	[paths]
        elif isinstance(__a					,       __a							):
            assert "train" in extracted_paths.keys()
            SCREAMING_SNAKE_CASE_   :						Optional[int]							=	extracted_paths.values()
            SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	paths.values()
        assert extracted_paths
        for extracted_path, input_path in zip(__a					,       __a							):
            assert extracted_path == dl_manager.extracted_paths[input_path]
            SCREAMING_SNAKE_CASE_   :						Optional[int]							=	Path(__a							)
            SCREAMING_SNAKE_CASE_   :						int							=	extracted_path.parts
            assert parts[-1] == hash_url_to_filename(__a					,       etag=__a							)
            assert parts[-2] == extracted_subdir
            assert extracted_path.exists()
            SCREAMING_SNAKE_CASE_   :						int							=	extracted_path.read_text()
            SCREAMING_SNAKE_CASE_   :						Optional[int]							=	text_file.read_text()
            assert extracted_file_content == expected_file_content



def       _A    (__a					,       __a							)				-> List[str]:
    """simple docstring"""






    assert path.endswith('''.jsonl'''							)
    for num_items, line in enumerate(__a					,       start=1							):
        SCREAMING_SNAKE_CASE_   :						Optional[int]							=	json.loads(line.decode('''utf-8'''							)							)
        assert item.keys() == {"col_1", "col_2", "col_3"}
    assert num_items == 4



@pytest.mark.parametrize('''archive_jsonl'''					,       ['''tar_jsonl_path''', '''zip_jsonl_path''']							)
def       _A    (__a					,       __a							)				-> List[Any]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						Any							=	request.getfixturevalue(__a							)
    SCREAMING_SNAKE_CASE_   :						List[str]							=	DownloadManager()
    for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(__a							)					,       start=1							):
        _test_jsonl(__a					,       __a							)
    assert num_jsonl == 2



@pytest.mark.parametrize('''archive_nested_jsonl'''					,       ['''tar_nested_jsonl_path''', '''zip_nested_jsonl_path''']							)
def       _A    (__a					,       __a							)				-> Optional[int]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	request.getfixturevalue(__a							)
    SCREAMING_SNAKE_CASE_   :						Any							=	DownloadManager()
    for num_tar, (path, file) in enumerate(dl_manager.iter_archive(__a							)					,       start=1							):
        for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(__a							)					,       start=1							):
            _test_jsonl(__a					,       __a							)
    assert num_tar == 1
    assert num_jsonl == 2





def       _A    (__a							)				-> Optional[Any]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						List[str]							=	DownloadManager()
    for num_file, file in enumerate(dl_manager.iter_files(__a							)					,       start=1							):
        assert os.path.basename(__a							) == ("test.txt" if num_file == 1 else "train.txt")
    assert num_file == 2










"""simple docstring"""






from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst



def       _A    ()				-> Union[str, Any]:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_		,    SCREAMING_SNAKE_CASE_   :						Tuple							=	9, 14  # noqa: F841
    SCREAMING_SNAKE_CASE_   :						Tuple							=	[
        [0, 1, 4],
        [0, 7, 8],
        [1, 2, 8],
        [7, 8, 7],
        [7, 6, 1],
        [2, 8, 2],
        [8, 6, 6],
        [2, 3, 7],
        [2, 5, 4],
        [6, 5, 2],
        [3, 5, 14],
        [3, 4, 9],
        [5, 4, 10],
        [1, 7, 11],
    ]

    SCREAMING_SNAKE_CASE_   :						Dict							=	defaultdict(__a							)
    for nodea, nodea, cost in edges:
        adjancency[nodea].append([nodea, cost]							)
        adjancency[nodea].append([nodea, cost]							)

    SCREAMING_SNAKE_CASE_   :						Any							=	mst(__a							)

    SCREAMING_SNAKE_CASE_   :						Optional[int]							=	[
        [7, 6, 1],
        [2, 8, 2],
        [6, 5, 2],
        [0, 1, 4],
        [2, 5, 4],
        [2, 3, 7],
        [0, 7, 8],
        [3, 4, 9],
    ]

    for answer in expected:
        SCREAMING_SNAKE_CASE_   :						Dict							=	tuple(answer[:2]							)
        SCREAMING_SNAKE_CASE_   :						Optional[int]							=	tuple(edge[::-1]							)
        assert edge in result or reverse in result


